I’m getting two errors, I see where they are, I just don’t know how to change the code to fit my needs.
Here’s the code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace zaidimas
{
public partial class Form1 : Form
{
public int z1 = 1;
public int z2 = 1;
public int kauliukas;
public string nuoroda;
public Form1()
{
InitializeComponent();
button2.Visible = false;
button1.Visible = true;
webBrowser1.DocumentCompleted += webBrowser1_DocumentCompleted;
webBrowser1.Navigate("siauliaicity.99k.org/zaidimas/");
}
private void button1_Click(object sender, EventArgs e)
{
// Gaunama kauliuko reikšmė
int kauliukas = RandomNumber(1, 6);
pictureBox1.ImageLocation = kauliukas + ".jpg";
label2.Text = "Kauliukas ridenos ridinėjosi ir sustojo ties" + kauliukas + "taškais";
int z1 = z1 + kauliukas; (first error goes here)
string nuoroda = "http://siauliaicity.99k.org/zaidimas/index.php?z=1&z1=" + z1 + "&z2=" + z2 + "&plus=" + kauliukas;
webBrowser1.Navigate(nuoroda);
button1.Visible = false;
button2.Visible = true;
}
private void button2_Click(object sender, EventArgs e)
{
// Gaunama kauliuko reikšmė
int kauliukas = RandomNumber(1, 6);
pictureBox1.ImageLocation = kauliukas + ".jpg";
label2.Text = "Kauliukas ridenos ridinėjosi ir sustojo ties" + kauliukas + "taškais";
int z2 = z2 + kauliukas; (second error goes here)
string nuoroda = "siauliaicity.99k.org/zaidimas/index.php?z=2&z1=" + z1 + "&z2=" + z2 + "&plus=" + kauliukas;
webBrowser1.Navigate(nuoroda);
button1.Text = "Ridenti kauliuką! (Ridena: Pirmasis žaidėjas)";
button2.Visible = false;
button1.Visible = true;
}
// Kauliuko funkcija
private int RandomNumber(int min, int max)
{
Random random = new Random();
return random.Next(min, max);
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
}
}
}
Error message’s:
Error 1 Use of unassigned local variable ‘z1’ C:\Users\Tutis\Documents\Visual Studio 2008\Projects\zaidimas\zaidimas\Form1.cs 38 26 zaidimas
and
Error 2 Use of unassigned local variable ‘z2’ C:\Users\Tutis\Documents\Visual Studio 2008\Projects\zaidimas\zaidimas\Form1.cs 52 22 zaidimas
Any suggestions how to change the code?
You have already declared variable with names
z1andz2you cannot declare them againI think you wanted to use the same variable but you have accidently put
intin startchange
to
and
to