示例#1
0
        public Form1()
        {
            InitializeComponent();
            LoggingClass.initLog();

            MaximizeBox = false;

            InitializeGame();
            DisableGame();
        }
示例#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;
 }
示例#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");
        }
示例#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);
        }
示例#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();
     }
 }
示例#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");
 }
示例#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");
        }
示例#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;
        }
示例#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();
            }
        }
示例#10
0
 private void promptReset()
 {
     LoggingClass.logInfo("SYSTEM", "Init Reset Prompt");
     gameStart           = 2;
     grpGamePlay.Enabled = false;
 }
示例#11
0
 public static void throwError(String errorMsg)
 {
     MessageBox.Show(errorMsg, "ERROR");
     LoggingClass.logError("ERROR", errorMsg);
 }
示例#12
0
 private void UpdateAIRefreshes()
 {
     LoggingClass.logInfo("Refresh AI", "Refreshing AI");
     updateButtons();
     checkWon();
 }
示例#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;
 }
示例#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();
                }
            }
        }