Exemple #1
0
 void OnNewGame()
 {
     PictureBox[] board = { p0, p1, p2, p3, p4, p5, p6, p7, p8 };
     foreach (PictureBox p in board)
     {
         p.Image = null;
     }
     turn   = PlayerTurn.Player1;
     winner = Winner.None;
 }
Exemple #2
0
        private void FindWinner(Winner pw)
        {
            if (pw.IsTie)
            {
                label2.Text     = "Tie";
                label2.Visible  = true;
                button2.Visible = true;
                endGame         = true;
            }
            else if (pw.Player != Player.NONE)
            {
                try
                {
                    switch (pw.Player)
                    {
                    case Player.X:
                        if (player == Player.X)
                        {
                            labelWin.Text = (int.Parse(labelWin.Text) + 1).ToString();
                        }
                        else
                        {
                            labelLose.Text = (int.Parse(labelLose.Text) + 1).ToString();
                        }
                        break;

                    case Player.O:
                        if (player == Player.X)
                        {
                            labelLose.Text = (int.Parse(labelLose.Text) + 1).ToString();
                        }
                        else
                        {
                            labelWin.Text = (int.Parse(labelWin.Text) + 1).ToString();
                        }
                        break;
                    }
                }
                catch { }

                pictureBox1.Visible = true;
                label1.Visible      = true;
                label2.Text         = player == pw.Player ? "Win!" : "Lose!";
                label2.Visible      = true;
                button2.Visible     = true;

                foreach (Position p in pw.Positions)
                {
                    PictureBox pic = (PictureBox)tableLayoutPanel1.GetControlFromPosition(p.X, p.Y);
                    pic.BackColor = System.Drawing.Color.LightGreen;
                }
                endGame = true;
            }
        }
Exemple #3
0
 private void TurnsManaging(Winner winner)
 {
     //switching players every turn
     if (winner == Winner.None)
     {
         m_playerTurn = m_playerTurn == PlayerTurn.Player ? PlayerTurn.Computer : PlayerTurn.Player;
     }
     else
     {
         m_playerTurn = PlayerTurn.None;
     }
 }
Exemple #4
0
 private void FindWinner(Winner pw)
 {
     if (pw.Player != Player.NONE)
     {
         foreach (Position p in pw.Positions)
         {
             PictureBox pic = (PictureBox)tableLayoutPanel1.GetControlFromPosition(p.X, p.Y);
             pic.BackColor = System.Drawing.Color.LightGreen;
         }
         endGame = true;
     }
 }
Exemple #5
0
 private void TurnsManaging(Winner winner)
 {
     //switching players every turn
     if (winner == Winner.None)
     {
         playerTurn = playerTurn == PlayerTurn.Player1 ? PlayerTurn.Player2 : PlayerTurn.Player1;
     }
     else
     {
         playerTurn = PlayerTurn.None;
     }
 }
Exemple #6
0
        private void PictureBox0_Click(object sender, EventArgs e)
        {
            PictureBox p = sender as PictureBox;

            if (p.Image != null)
            {
                return;
            }
            if (turn == PlayerTurn.None)
            {
                return;
            }
            if (turn == PlayerTurn.Player1)
            {
                p.Image = player1.Image;
            }

            else
            {
                p.Image = player2.Image;
            }
            //Check for Winner
            winner = GetWinner();
            if (winner == Winner.None)
            {
                //Change Turns
                turn = (PlayerTurn.Player1 == turn) ? PlayerTurn.Player2 : PlayerTurn.Player1;
                if (AI.CPU == false)
                {
                    return;
                }
                else
                {
                    AI.TakeTurn(BoardStatus());
                    int          play         = AI.Play;
                    PictureBox[] pictureBoxes = { p0, p1, p2, p3, p4, p5, p6, p7, p8 };
                    for (int i = 0; i < pictureBoxes.Length; i++)
                    {
                        if (play == i)
                        {
                            pictureBoxes[i].Image = player2.Image;
                        }
                    }
                }
            }
            else
            {
                turn = PlayerTurn.None;
            }
            ShowTurn();
        }
Exemple #7
0
        private bool CheckSomeoneWin()
        {
            var CheckWinner = new Winner(_boardSize, _currentPlayer, _fieldsToWin);

            if (CheckWinner.CheckWinnerHorizontal() ||
                CheckWinner.CheckWinnerVertical() ||
                CheckWinner.CheckWinnerSlanAtFront() ||
                CheckWinner.CheckWinnerSlantAtBack())
            {
                return(true);
            }

            return(false);
        }
Exemple #8
0
        private void OnNewGame()
        {
            //resetting the slots of the game
            foreach (PictureBox slot in gameSlots)
            {
                slot.Image = null;
            }
            lblScorep1.Text += player1Score.ToString();
            lblScorep2.Text += player2Score.ToString();

            playerTurn = winner == Winner.Player1 ? PlayerTurn.Player2 : PlayerTurn.Player1;
            winner     = Winner.None;
            ShowTurn();
        }
Exemple #9
0
        private bool CheckIsItDraw()
        {
            var winner = new Winner(_boardSize, _currentPlayer, _fieldsToWin);

            if (winner.IsDraw())
            {
                var board = new Board();
                board.DisplayBoard(_tab);//display board
                Console.WriteLine($"THERE IS NO WINNER... IT'S DRAW " +
                                  $"\n\n\n\n -----tap any key on keyboard, to get back to main menu------");
                _gameFinished = true;

                return(true);
            }
            return(false);
        }
Exemple #10
0
 private void ShowWinner(Winner winner)
 {
     if (winner == Winner.Player)
     {
         m_playerScore++;
         MessageBox.Show("You Won!", "Game Over", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
     }
     else if (winner == Winner.Computer)
     {
         m_computerScore++;
         MessageBox.Show("Computer won!", "Game Over", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
     }
     else if (winner == Winner.Draw)
     {
         MessageBox.Show("It's a draw!", "Game Over", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
     }
 }
Exemple #11
0
 private void ShowWinner(Winner winner)
 {
     if (winner == Winner.Player1)
     {
         player1Score++;
         MessageBox.Show("Player 1 Won!", "Game Over", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
     }
     else if (winner == Winner.Player2)
     {
         player2Score++;
         MessageBox.Show("Player 2 Won!", "Game Over", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
     }
     else if (winner == Winner.Draw)
     {
         MessageBox.Show("It's a draw!", "Game Over", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
     }
 }
Exemple #12
0
        private void OnNewGame()
        {
            //setting the slots to empty
            foreach (PictureBox picture in gameSlots)
            {
                picture.Image = null;
            }
            //displaying the players score
            lblScorep1.Text += m_playerScore.ToString();
            lblScorep2.Text += m_computerScore.ToString();

            NewGameTurns();
            //Set m_winner to none every new game
            m_winner = Winner.None;
            if (m_playerTurn == PlayerTurn.Computer)
            {
                ComputerPlay();
                TurnsManaging(m_winner);
            }

            ShowTurn();
        }
Exemple #13
0
        private void OnClick(object sender, EventArgs e)
        {
            PictureBox picture = sender as PictureBox;

            //setting player mode to none to prevent the game keep working after the game is over.
            if (m_playerTurn == PlayerTurn.None)
            {
                return;
            }

            // making sure that the image won't change once its clicked
            if (picture.Image != null)
            {
                return;
            }

            if (m_playerTurn == PlayerTurn.Player)
            {
                picture.Image = player1.Image;
            }

            m_winner = CheckWinner();
            ShowWinner(m_winner);
            ShowTurn();
            TurnsManaging(m_winner);

            //once the player finishes his turn, the event call immidiatly to the AI computer method to do its move.
            if (m_playerTurn == PlayerTurn.Computer && m_winner == Winner.None)
            {
                ComputerPlay();
                m_winner = CheckWinner();
                ShowWinner(m_winner);
                TurnsManaging(m_winner);
                ShowTurn();
            }
        }
Exemple #14
0
 /// <summary>
 /// Adds a new Winner object to List
 /// </summary>
 /// <param name="player"></param>
 public void AddStat(Winner player)
 {
     winners.Add(player);
 }