public static void gameTest()
        {
            GameStrategy game = new GameStrategy();

            int[] cellId = { 5, 11, 17, 31, 34, 48, 54, 60, 52 };
            for (int i = 0; i < cellId.Length; i++)
            {
                try
                {
                    MessageBox.Show(game.isValidPostion(5).ToString());
                }
                catch (GameOverException e)
                {
                    MessageBox.Show("Game Over!!");
                }
            }
        }
Beispiel #2
0
        void Cell_Click(object sender, EventArgs e)
        {
            Label cell = (Label)sender;

            if (cell.Image != null)
            {
                cell.Image = null;
                if (numOfQueens-- < 0)
                {
                    numOfQueens = 0;
                }
                game.UnplaceQueen((int)cell.Tag);
                return;
            }

            try
            {
                if (game.isValidPostion((int)cell.Tag))
                {
                    InsertQueen(cell);
                    if (numOfQueens == 8)
                    {
                        MessageBox.Show("Success! You are the winner!");
                    }
                }
                else
                {
                    Color temp = cell.BackColor;
                    for (int i = 0; i < 3; ++i)
                    {
                        cell.BackColor = Color.Red;
                        cell.Refresh();
                        System.Threading.Thread.Sleep(50);
                        cell.BackColor = Color.Yellow;
                        cell.Refresh();
                        System.Threading.Thread.Sleep(50);
                    }
                    cell.BackColor = temp;
                }
            }
            catch (GameOverException)
            {
                MessageBox.Show("WINNER!!!!!!!!!!!!");
            }
        }