Esempio n. 1
0
 private void panel1_MouseClick(object sender, MouseEventArgs e)
 {
     if (game.playerMove(e.Location))
     {
         game.printBoard(game.board); // DEBUGGING
         Invalidate(true);
         int winner = game.checkWinner();
         if (winner == Game.PLAYER)
         {
             timer1.Stop();
             MessageBox.Show("Player wins!", "Winner!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             Close();
             return;
         }
         else if (winner == Game.COMPUTER)
         {
             timer1.Stop();
             MessageBox.Show("Computer wins!", "Winner!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             Close();
             return;
         }
         else if (winner == Game.DRAW)
         {
             timer1.Stop();
             MessageBox.Show("The board is full!", "Full!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             Close();
             return;
         }
         game.computerMove();
         game.printBoard(game.board); // DEBUGGING
         Invalidate(true);
         winner = game.checkWinner();
         if (winner == Game.PLAYER)
         {
             timer1.Stop();
             MessageBox.Show("Player wins!", "Winner!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             Close();
             return;
         }
         else if (winner == Game.COMPUTER)
         {
             timer1.Stop();
             MessageBox.Show("Computer wins!", "Winner!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             Close();
             return;
         }
         else if (winner == Game.DRAW)
         {
             timer1.Stop();
             MessageBox.Show("The board is full!", "Full!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             Close();
             return;
         }
         time          = 30;
         textBox1.Text = time.ToString();
     }
     else
     {
         MessageBox.Show("Invalid move! Make another choice!", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     }
 }