Trying to make a hangman game and I am nearly there. When I type in to the txtBokstavGjett the array won't save when I hit the button. Even though I have a session variable for losning[].
I dont really know what to do from here so any help is much appreciated. The variable names are in norwegian but that shouldnt matter.
public partial class _Default : System.Web.UI.Page
{
int antallForsok = 0;
string forsokteBokstaver;
char[] losning = new char[8];
protected void Page_Load(object sender, EventArgs e)
{
if (Session["antallForsok"] != null)
{
antallForsok = (int)Session["antallForsok"];
}
labForsok.Text = Convert.ToString(antallForsok);
if (Session["forsokteBokstaver"] != null)
{
forsokteBokstaver = (string)Session["forsokteBokstaver"];
}
if (Session["losning"] != null)
{
losning = (char[])Session["losning"];
}
if (antallForsok == 0)
{
for (int k = 0; k < losning.Length; k++)
{
losning[k] = '_';
labRes.Text += " " + losning[k] + " ";
labTestBox.Text += "" + losning[k] + " ";
}
}
}
protected void btnKnapp_Click(object sender, EventArgs e)
{
labRes.Text = "";
labTestBox.Text = "";
string losningOrd = "appelsin";
char brukerGjett = Convert.ToChar(txtBokstavGjett.Text);
char[] bokstaver = losningOrd.ToCharArray();
losning = new char[bokstaver.Length];
for (int i = 0; i <bokstaver.Length; i++)
{
if (brukerGjett == bokstaver[i])
{
losning[i] = bokstaver[i];
}
else if (!(brukerGjett == bokstaver[i]))
{
}
forsokteBokstaver = brukerGjett.ToString();
labRes.Text += "" + losning[i];
labTestBox.Text += " " + losning[i];
}
txtBokstavGjett.Text = "";
antallForsok++;
labForsoktBokstav.Text += forsokteBokstaver;
}
protected void Page_Unload (object sender, EventArgs e)
{
Session["antallForsok"] = antallForsok;
Session["forsokteBokstaver"] = forsokteBokstaver;
Session["losning"] = losning;
}
}