예제 #1
0
        void IObserver.Update(object Model)
        {
            Model model  = (Model)Model;
            int   winner = model.getWinner();

            int[] temp = model.getboard();

            if (winner != 0)
            {
                if (winner == 1)
                {
                    System.Windows.Forms.MessageBox.Show(Playername1 + " won!");
                }
                else if (winner == -1)
                {
                    System.Windows.Forms.MessageBox.Show(Playername2 + " won!");
                }
                else if (winner == 2)
                {
                    System.Windows.Forms.MessageBox.Show("It´s a tie!");
                }
            }

            for (int i = 0; i < 9; i++)
            {
                if (temp[i] == 1)
                {
                    buttonArray[i].Text    = "X";
                    buttonArray[i].Enabled = false;
                }
                else if (temp[i] == -1)
                {
                    buttonArray[i].Text    = "O";
                    buttonArray[i].Enabled = false;
                }
                else if (temp[i] == 0)
                {
                    buttonArray[i].Text    = "";
                    buttonArray[i].Enabled = true;
                }
            }
        }