-
November 21st, 2017, 06:53 PM
#1
Variables keep overwriting each other
I am currently trying to develop a 3D tic toe model. However, my counter keeps overwriting every time I click a button.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Windows.Forms;
public partial class TTT_Game : System.Web.UI.Page
{
public Player CurrentPlayer = Player.X;
protected void btn0_Click(object sender, EventArgs e)
{
if (CurrentPlayer == Player.X)
{
btn0.Text = "X";
CurrentPlayer = Player.O; scoreOne--;
}
else if (CurrentPlayer == Player.O)
{
btn0.Text = "O";
CurrentPlayer = Player.X; scoreTwo--;
}
btn0.Enabled = true;
Check();
}
protected void btn1_Click(object sender, EventArgs e)
{
if (CurrentPlayer == Player.X)
{
btn1.Text = "X";
CurrentPlayer = Player.O; scoreOne--;
}
else if (CurrentPlayer == Player.O)
{
btn1.Text = "O";
CurrentPlayer = Player.X; scoreTwo--;
}
btn1.Enabled = false;
Check();
}
}
So let's say I would click btn0 should then set the next turn to Player.O, but it keeps being a constant Player.X no matter what I do. Appreciate the help (fyi scoreTwo and scoreOne is in there along with check, but did not want to post 2000+ lines.
Last edited by 2kaud; November 22nd, 2017 at 04:04 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|