Example #1
0
 private void StartGameSP()
 {
     LoggingClass.logInfo("SYSTEM", "Game Start (SP)");
     lblInstructions.Text = "Player Starts First! Turn: 0";
     currentPlayer        = Values.X;
     turnNo = 0;
 }
Example #2
0
 public static void determineNextMove(string[,] gameBoard, int lastRow, int lastCol, int turn)
 {
     //Check if first turn and is middle
     if (turn == 1)
     {
         LoggingClass.logInfo("AI", "First Move Execute");
         firstMove(gameBoard, lastRow, lastCol);
     }
     else if (turn > 8)
     {
         return;
     }
     else
     {
         LoggingClass.logInfo("AI", "Check Win");
         //See if AI can win
         if (checkForPossibleAIWinOrBlock(gameBoard, Values.O))
         {
             return;
         }
         LoggingClass.logInfo("AI", "Check Block");
         //Check if I can block
         if (checkForPossibleAIWinOrBlock(gameBoard, Values.X))
         {
             return;
         }
         //Randomize
         LoggingClass.logInfo("AI", "Randomize");
         randomlyChuckValue();
     }
 }
Example #3
0
 private void ResetGame()
 {
     LoggingClass.logInfo("SYSTEM", "Game Reset");
     InitializeGame();
     DisableGame();
     btnStart.Enabled     = true;
     groupSelect.Enabled  = true;
     lblInstructions.Text = "Press Start Game to Start";
 }
Example #4
0
 private void DisableGame()
 {
     LoggingClass.logInfo("SYSTEM", "Game Area Disabled");
     gameStart                        = 0;
     timerDuration                    = 0;
     countUpTimerLabel.Text           = "Time Taken: - seconds";
     grpGamePlay.Enabled              = false;
     btnReset.Enabled                 = false;
     newGameToolStripMenuItem.Enabled = false;
 }
Example #5
0
        public static Boolean hasWon(String value, String[,] gameBoard)
        {
            Boolean winValue = false;

            gameBoardCheck = gameBoard;
            if (wonVert(value) || wonHorizontal(value) || wonDiagonal(value))
            {
                winValue = true;
            }
            LoggingClass.logInfo("WIN-Check", "Has Won Value: " + winValue);
            return(winValue);
        }
Example #6
0
 private void UpdateMove(int row, int col)
 {
     if (checkValid(row, col))
     {
         LoggingClass.logInfo("Player Move", "Turn " + turnNo + ": Placed at " + row + ":" + col);
         gameBoard[row, col] = currentPlayer;
         updateButtons();
         lastCol = col;
         lastRow = row;
         checkWon();
     }
 }
Example #7
0
 private void updateButtons()
 {
     LoggingClass.logInfo("Update Button", "Updating Button");
     r11.Text = gameBoard[0, 0];
     r12.Text = gameBoard[0, 1];
     r13.Text = gameBoard[0, 2];
     r21.Text = gameBoard[1, 0];
     r22.Text = gameBoard[1, 1];
     r23.Text = gameBoard[1, 2];
     r31.Text = gameBoard[2, 0];
     r32.Text = gameBoard[2, 1];
     r33.Text = gameBoard[2, 2];
     LoggingClass.logInfo("Update Button", "Update Complete");
 }
Example #8
0
        private void InitializeGame()
        {
            LoggingClass.logInfo("SYSTEM", "Init Game");
            r11.Text             = r12.Text
                                 = r21.Text = r22.Text
                                                  = r31.Text = r32.Text
                                                                   = r13.Text = r23.Text
                                                                                    = r33.Text = Values.EMPTY;

            gameBoard[0, 0] = gameBoard[0, 1] = gameBoard[0, 2]
                                                    = gameBoard[1, 0] = gameBoard[1, 1] = gameBoard[1, 2]
                                                                                              = gameBoard[2, 0] = gameBoard[2, 1] = gameBoard[2, 2]
                                                                                                                                        = Values.EMPTY;
            LoggingClass.logInfo("SYSTEM", "Init Complete");
        }
Example #9
0
        private void StartGameMultiplayer()
        {
            LoggingClass.logInfo("SYSTEM", "Game Start (MP)");
            Random random         = new Random();
            int    whoStartsFirst = random.Next(2);

            LoggingClass.logInfo("Random", "Rolled " + whoStartsFirst);
            //MessageBox.Show(whoStartsFirst + "");
            if (whoStartsFirst == 1)
            {
                //X
                lblInstructions.Text = "X Starts First! Turn: 0";
                currentPlayer        = Values.X;
            }
            else
            {
                //O
                lblInstructions.Text = "O Starts First! Turn: 0";
                currentPlayer        = Values.O;
            }
            turnNo = 0;
        }
Example #10
0
        private void checkWon()
        {
            if (AlgorithmCheck.hasWon(Values.X, gameBoard))
            {
                LoggingClass.logInfo("GAME-WIN", "X WON");
                gameStart = 3;
                MessageBox.Show("X has won the game!", "X Won!");
                promptReset();
            }
            else if (AlgorithmCheck.hasWon(Values.O, gameBoard))
            {
                LoggingClass.logInfo("GAME-WIN", "O WON");
                gameStart = 3;
                MessageBox.Show("O has won the game!", "O Won!");
                promptReset();
            }

            //If not won, update
            if (gameStart == 1)
            {
                NextTurn();
            }
        }
Example #11
0
 private void promptReset()
 {
     LoggingClass.logInfo("SYSTEM", "Init Reset Prompt");
     gameStart           = 2;
     grpGamePlay.Enabled = false;
 }
Example #12
0
 private void UpdateAIRefreshes()
 {
     LoggingClass.logInfo("Refresh AI", "Refreshing AI");
     updateButtons();
     checkWon();
 }
Example #13
0
 public static void UpdateAIMove(int row, int col)
 {
     LoggingClass.logInfo("AI Move", "Turn " + turnNo + ": Placed at " + row + ":" + col);
     gameBoard[row, col] = Values.O;
 }
Example #14
0
        private void NextTurn()
        {
            if (isSinglePlayer())
            {
                LoggingClass.logInfo("GAME", "Single Player Mode");
                turnNo++;
                LoggingClass.logInfo("GAME", "Incremented Turn No");
                if (currentPlayer == Values.X)
                {
                    //AI's Turn
                    currentPlayer = Values.AI;
                    updateTurnDisplay();
                    grpGamePlay.Enabled = false;
                    ComputerAI.determineNextMove(gameBoard, lastRow, lastCol, turnNo);
                    UpdateAIRefreshes();
                }
                else
                {
                    currentPlayer       = Values.X;
                    grpGamePlay.Enabled = true;
                    updateTurnDisplay();
                }

                //Check drawn
                if (AlgorithmCheck.hasDrawn(turnNo))
                {
                    if (gameStart == 2)
                    {
                        LoggingClass.logInfo("SYSTEM", "Already prompted Draw Message");
                    }
                    else
                    {
                        gameStart = 3;
                        MessageBox.Show("This game is a draw!", "Game Drawn");
                        LoggingClass.logInfo("SYSTEM", "Game Drawn");
                        promptReset();
                    }
                }
            }
            else
            {
                LoggingClass.logInfo("GAME", "Multiplayer Mode");
                turnNo++;
                LoggingClass.logInfo("GAME", "Incremented Turn No");
                if (currentPlayer == Values.X)
                {
                    currentPlayer = Values.O;
                }
                else
                {
                    currentPlayer = Values.X;
                }
                updateTurnDisplay();

                //Check drawn
                if (AlgorithmCheck.hasDrawn(turnNo))
                {
                    gameStart = 3;
                    MessageBox.Show("This game is a draw!", "Game Drawn");
                    LoggingClass.logInfo("SYSTEM", "Game Drawn");
                    promptReset();
                }
            }
        }