How can I store the values in my class?
Every time I click the buttons my class seems to be instantiated again.
My class:
public class Partida
{
public string[] linha1 = new string[3];
public string[] linha2 = new string[3];
public string[] linha3 = new string[3];
public string[] diagonal1 = new string[3];
public string[] diagonal2 = new string[3];
public string[] coluna1 = new string[3];
public string[] coluna2 = new string[3];
public string[] coluna3 = new string[3];
public Partida()
{
for (int i = 0; i < 3; i++)
{
linha1[i] = "";
linha2[i] = "";
linha3[i] = "";
coluna1[i] = "";
coluna2[i] = "";
coluna3[i] = "";
diagonal1[i] = "";
diagonal2[i] = "";
}
}
}
My Web Page
namespace prova.jogo_da_velha
{
public partial class jogodavelha : System.Web.UI.Page
{
Partida partida = new Partida();
//True = X False = O
bool turno = true;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button11_Click(object sender, EventArgs e)
{
if (turno)
{
partida.linha1[0] = "x";
partida.coluna1[0] = "x";
partida.diagonal1[0] = "x";
Button11.Text = "X";
turno = false;
}
else
{
partida.linha1[0] = "o";
partida.coluna1[0] = "o";
partida.diagonal1[0] = "o";
Button11.Text = "O";
turno = true;
}
}
protected void Button12_Click(object sender, EventArgs e)
{
if (turno)
{
partida.linha1[1] = "x";
partida.coluna2[0] = "x";
Button12.Text = "X";
turno = false;
}
else
{
partida.linha1[1] = "o";
partida.coluna2[0] = "o";
Button12.Text = "O";
turno = true;
}
}
}