private void computer_turn() { List <int> coords = new List <int>(); // Identify next move based on difficulty switch (GameLogic.cDifficulty) { // Place DIE Randomly case DIFFICULTY.EASY: coords = GameLogic.easyBOT(GAME_BOARD).ToList(); break; // Block Player - Random case DIFFICULTY.NORMAL: coords = GameLogic.normalBOT(GAME_BOARD).ToList(); // Use EASY BOT if there is nothing to block if (coords[0] == -1 && coords[1] == -1) { coords = GameLogic.easyBOT(GAME_BOARD).ToList(); } break; case DIFFICULTY.HARD: coords = GameLogic.hardBOT(GAME_BOARD).ToList(); // Use EASY BOT if there is nothing to block if (coords[0] == -1 && coords[1] == -1) { coords = GameLogic.easyBOT(GAME_BOARD).ToList(); } break; default: break; } // Update GAME_BOARD GAME_BOARD[coords.ElementAt(0), coords.ElementAt(1)] = COMPUTER_SYMBOL; // Update Btn UI Button btn = (Button)gamePanel.Controls.Find($"{coords.ElementAt(0)}-{coords.ElementAt(1)}_btn", true).First(); btn.BackgroundImage = Image.FromFile(COMPUTER_DIE); btn.BackgroundImageLayout = ImageLayout.Stretch; btn.Enabled = false; // Check Win Condition if (GameLogic.winCondition(GAME_BOARD, COMPUTER_SYMBOL)) { victoryForm victoryForm = new victoryForm(victoryForm.PLAYER.computer, turnNumber, GameLogic.cDifficulty, this, currentUser); victoryForm.ShowDialog(); } }
private void button_click(object sender, EventArgs e) { // Update Turn turnNumber++; turnLbl.Text = turnStr + turnNumber; Button btn = (Button)sender; btnClicked = true; // Get Selected Coords int[] coords = getCoords(btn.Name); int row = coords[0], column = coords[1]; // Update GAME_BOARD based on coords GAME_BOARD[row, column] = PLAYER_SYMBOL; // Update Selected Btn btn.BackgroundImage = Image.FromFile(PLAYER_DIE); btn.BackgroundImageLayout = ImageLayout.Stretch; btn.Enabled = false; // Play Sound soundPlayer.Play(); // Check Victory if (GameLogic.winCondition(GAME_BOARD, PLAYER_SYMBOL)) { victoryForm victoryForm = new victoryForm(victoryForm.PLAYER.player, turnNumber, GameLogic.cDifficulty, this, currentUser); victoryForm.ShowDialog(); } else { computer_turn(); } }