Tic Tac Toe - C# - Having trouble completing checks
<p>So here's the deal, I'm trying to compare images in a local resource for <code>X</code> and <code>O</code>, and if they're the same in the <code>winCondition</code> array, to message the user they won. </p>

<p>The problem I'm finding is that <code>b1.Image</code> isn't giving me the proper comparison. It's comparing this:</p>

<pre><code>+  b1.Image  {System.Drawing.Bitmap}  System.Drawing.Image  {System.Drawing.Bitmap}
</code></pre>

<p>when I want it to compare the image names instead.</p>

<p>One of these problems is that when <code>turnNumber = 5</code>, it says I won, when I haven't. I believe this is due to the <code>b1.Image problem</code>. Once I click another square, it checks for the win again.</p>

<p>I want to disable the buttons once a game is completed, however I don't know how to do this.</p>

<p>Would it be as simple as: </p>

<pre><code>   foreach (Button btnEnabled in buttonArray)
   {
       btnEnabled.Enabled = false;
   }
</code></pre>

<p>Here is the code, and again, thank you for any help. I have been struggling with this for a few days.</p>

<pre><code>namespace BGreinAssignment2
{
    public partial class frmTicTacToe : Form
    {
        //Global variables
        private bool player1Turn = false;
        private bool player2Turn = true;

        private int[,] winCondition = 
        {
            {0,1,2}, //Horizontal top
            {3,4,5}, //Horizontal Middle
            {6,7,8}, //Horizontal Bottom
            {0,3,6}, //Vertical Left
            {1,4,7}, //Vertical Middle
            {2,5,8}, //Vertical Right
            {0,4,8}, //Diagonal Top Left to Bottom Right or Vice-Versa
            {2,4,6}  //Diagonal Top Right to Bottom Left or Vice-Versa
        };
        private Button[] buttonArray;
        private int turnNumber = 0;

        public frmTicTacToe()
        {
            InitializeComponent();
        }

        //Creates the button array for checks and sets X to go first.
        private void frmTicTacToe_Load(object sender, EventArgs e)
        {
            //Creates button array for checking if image is there/check for beginning of game
            buttonArray = new Button[9] {btnTopLeft, btnTopMid, btnTopRight, btnMidLeft, btnMid, btnMidRight, btnBotLeft, btnBotMid, btnBotRight};

            //Sets player 1 to go first to satisfy the "X always goes first"
            player1Turn = true;
            player2Turn = false;
        }

        /// &lt;summary&gt;
        /// Checks the buttons if the images don't create a win condition through the winCheck method,
        /// displays message box to user with "Draw!" break is included so it doesn't say "Draw!" for each button it checks.
        /// &lt;/summary&gt;
        private void drawCheck()
        {
            foreach (Button checkDraw in buttonArray)
            {
                if (checkDraw.Image != null)
                {
                    MessageBox.Show("Draw!");
                    break;
                }
            }
        }

        /// &lt;summary&gt;
        /// Checks the win condition to see if the images are the same. If they are, it will show a message box with the winner.
        /// &lt;/summary&gt;
        /// &lt;param name="btnChecks"&gt;Creates an array to check the button images&lt;/param&gt;
        /// &lt;returns&gt;If there is a winner, returns true and shows message box&lt;/returns&gt;
        private bool winCheck(Button[] btnChecks)
        {
            bool win = false;
            for (int i = 0; i &lt; 8; i++)
            {
                int a = winCondition[i, 0], b = winCondition[i, 1], c = winCondition[i, 2];

                Button b1 = btnChecks[a], b2 = btnChecks[b], b3 = btnChecks[c];

                if (b1.Image == null || b2.Image == null || b3.Image == null)
                {
                    continue;
                }

                if (b1.Image == b2.Image &amp;&amp; b2.Image == b3.Image)
                {
                    win = true;
                    MessageBox.Show("Game over. " + b1.Image + " Wins!");
                }
            }
            return win;
        }

        //If player chooses top left square
        private void btnTopLeft_Click(object sender, EventArgs e)
        {
            if (btnTopLeft.Image == null)
            {
                if (player1Turn == true)
                {
                    if (turnNumber == 0)
                    {
                        btnTopLeft.Image = BGreinAssignment2.Properties.Resources.tic_tac_toe_X;
                        player1Turn = false;
                        player2Turn = true;
                        turnNumber++;
                    }
                    else
                    {
                        btnTopLeft.Image = BGreinAssignment2.Properties.Resources.tic_tac_toe_X;
                        player1Turn = false;
                        player2Turn = true;
                        turnNumber++;
                        if (turnNumber &gt;= 5)
                        {
                            winCheck(buttonArray);
                        }
                        if (turnNumber == 9)
                        {
                            drawCheck();
                        }
                    }
                }
                else
                {
                    btnTopLeft.Image = BGreinAssignment2.Properties.Resources.tic_tac_toe_O;
                    player1Turn = true;
                    player2Turn = false;
                    turnNumber++;
                    if (turnNumber &lt;= 5)
                    {
                        winCheck(buttonArray);
                    }
                    if (turnNumber == 9)
                    {
                        drawCheck();
                    }
                }
            }
            else
            {
                MessageBox.Show("This space has already been selected");
            }
        }

        //Excluded rest of code (just button clicks, repeats of same for 9 squares)

        /// &lt;summary&gt;
        /// Resets the game for the player.
        /// &lt;/summary&gt;
        /// &lt;param name="sender"&gt;&lt;/param&gt;
        /// &lt;param name="e"&gt;&lt;/param&gt;
        private void btnPlayAgain_Click(object sender, EventArgs e)
        {
            //For each button, set image to null then reset turn counter and set turn to player 1.
            foreach (Button btnSpaces in buttonArray)
            {
                btnSpaces.Image = null;
            }
            turnNumber = 0;
            player1Turn = true;
            player2Turn = false;
        }
    }
}
</code></pre>
