public void GameRun() { while (true) { // Wait to be signalled AutoEvent.WaitOne(); Board.CellState cellStateInOut = Board.CellState.CellState_None; // Check to see if game has ended if (CheckGameEnd(ref cellStateInOut) == true) { GameEnd(cellStateInOut); } else { // Let AI Player pick a spot mAIPlayer.PickRandomBoardCell(); // Check to see if game has ended if (CheckGameEnd(ref cellStateInOut) == true) { GameEnd(cellStateInOut); } } // Update board UpdateCallback(mBoard); UpdateLabelsCallback(mGamesWon, mGamesLost, ""); } }
public void GameEnd(Board.CellState cellState) { // Disable the buttons in the forms EnableBoardCb(false); // check if player won if (mUserPlayer.AssignedCellState == cellState) { mGamesWon++; } else if (mAIPlayer.AssignedCellState == cellState) { mGamesLost++; } else { /* Nothing happens */ } }
public BoardCell(int rowNum, int colNum) { indexVal = new Vector2(rowNum, colNum); state = BoardConfig.GetCellState(rowNum, colNum); pos = new Vector2((BoardCell.size / 2 + colNum * BoardCell.size) + 8, (BoardCell.size / 2 + rowNum * BoardCell.size) + 8); }
public BoardCell() { indexVal = new Vector2(); state = Board.CellState.DEFAULT; pos = new Vector2(); }
public bool CheckGameEnd(ref Board.CellState inOutCellState) { bool lGameHasEnded = false; // Check horizontal for (int i = 0; i < Board.NUM_OF_CELLS; i += 3) { if (mBoard.GetCell(i) == mBoard.GetCell(i + 1) && mBoard.GetCell(i) == mBoard.GetCell(i + 2) && mBoard.GetCell(i) != Board.CellState.CellState_None) { lGameHasEnded = true; inOutCellState = mBoard.GetCell(i); } } // Check vertical for (int i = 0; i < 3; i++) { if (mBoard.GetCell(i) == mBoard.GetCell(i + 3) && mBoard.GetCell(i) == mBoard.GetCell(i + 6) && mBoard.GetCell(i) != Board.CellState.CellState_None) { lGameHasEnded = true; inOutCellState = mBoard.GetCell(i); } } // check diagonal // Top left to bottom right if (mBoard.GetCell(0) == mBoard.GetCell(4) && mBoard.GetCell(0) == mBoard.GetCell(8) && mBoard.GetCell(0) != Board.CellState.CellState_None) { lGameHasEnded = true; inOutCellState = mBoard.GetCell(0); } // Top right to bottom left if (mBoard.GetCell(2) == mBoard.GetCell(4) && mBoard.GetCell(2) == mBoard.GetCell(6) && mBoard.GetCell(2) != Board.CellState.CellState_None) { lGameHasEnded = true; inOutCellState = mBoard.GetCell(2); } // Check if everything has been filled bool filled = true; for (int i = 0; i < Board.NUM_OF_CELLS; i++) { if (mBoard.GetCell(i) == Board.CellState.CellState_None) { filled = false; } } if (filled == true) { lGameHasEnded = true; } return(lGameHasEnded); }