Esempio n. 1
0
        public Form1()
        {
            InitializeComponent();
            LoggingClass.initLog();

            MaximizeBox = false;

            InitializeGame();
            DisableGame();
        }
Esempio n. 2
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;
 }
Esempio n. 3
0
        private void viewGameLogToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ArrayList logList = LoggingClass.getLogList();
            String    msg     = "";

            foreach (string log in logList)
            {
                msg += log + "\n";
            }
            FlexibleMessageBox.Show(msg, "Log");
        }
Esempio n. 4
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);
        }
Esempio n. 5
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();
     }
 }
Esempio n. 6
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");
 }
Esempio n. 7
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");
        }
Esempio n. 8
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;
        }
Esempio n. 9
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();
            }
        }
Esempio n. 10
0
 private void promptReset()
 {
     LoggingClass.logInfo("SYSTEM", "Init Reset Prompt");
     gameStart           = 2;
     grpGamePlay.Enabled = false;
 }
Esempio n. 11
0
 public static void throwError(String errorMsg)
 {
     MessageBox.Show(errorMsg, "ERROR");
     LoggingClass.logError("ERROR", errorMsg);
 }
Esempio n. 12
0
 private void UpdateAIRefreshes()
 {
     LoggingClass.logInfo("Refresh AI", "Refreshing AI");
     updateButtons();
     checkWon();
 }
Esempio n. 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;
 }
Esempio n. 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();
                }
            }
        }