1
How can I store the values of 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;
}
}
}
You must [Dit] the question and put your code (put relevant parts, no more, no less). It is difficult for people to work with a screenshot. And please learn to make titles described of your problem, it is not to play the tags in it. Also choose the tags with more care. You will find it difficult to be helped if you don’t collaborate. And try to clarify the question, I don’t understand what you want effectively. It seemed to me that you want to know something unrelated to your problem.
– Maniero
That’s better?
– Valderí Leandro
I got a formatting problem. TAKE a look at the edition. http://answall.com/posts/42407/revisions
– Maniero