private void MemoryGameButton_Click(object i_Sender, EventArgs i_E) { MemoryGameButton button = i_Sender as MemoryGameButton; int key = MemoryBoard.GetKey(button.Row, button.Col); PictureBox picture = GameManager.sr_ValueDictionary[key]; if (!MemoryBoard.IsOpenOrTurnOpen(button.Row, button.Col)) { if (IsFirstTile) { playerChooseFirstTile(button); } else { button.Image = picture.Image; button.BackColor = Turn ? Player2Name.BackColor : Player1Name.BackColor; SecondChoiceButton = button; if (MemoryBoard.SecondChoice(button.Row, button.Col)) { playerChooseSameTiles(button); } else { playerChooseDifferentTiles(button); } IsFirstTile = !IsFirstTile; } } }
private void makeComputerTurn() { const bool k_EnableButtons = false; enableDisableButtonsComputerTurn(k_EnableButtons); if (ComputerTurnState == eComputerTurnState.FirstTileToChoose) { firstTileChoosenByComputer(); } else if (ComputerTurnState == eComputerTurnState.SecondTileToChoose) { secondTileChoosenByComputer(); } else if (ComputerTurnState == eComputerTurnState.EndTurn) { int firstTileValue = MemoryBoard.GetKey(FirstChoiceButton.Row, FirstChoiceButton.Col); int secondTileValue = MemoryBoard.GetKey(SecondChoiceButton.Row, SecondChoiceButton.Col); if (firstTileValue == secondTileValue) { computerChooseSameTiles(); } else { computerChooseDifferentTiles(); } ComputerTurnState = eComputerTurnState.FirstTileToChoose; } }
private void playerChooseFirstTile(MemoryGameButton i_BoardTileButton) { int key = MemoryBoard.GetKey(i_BoardTileButton.Row, i_BoardTileButton.Col); PictureBox picture = GameManager.sr_ValueDictionary[key]; MemoryBoard.FirstChoice(i_BoardTileButton.Row, i_BoardTileButton.Col); i_BoardTileButton.Image = picture.Image; IsFirstTile = !IsFirstTile; FirstChoiceButton = i_BoardTileButton; i_BoardTileButton.BackColor = Turn ? Player2Name.BackColor : Player1Name.BackColor; }
private void secondTileChoosenByComputer() { Point secondOpened = new Point(); int key; ComputerPlayer.ZeroAndUpdateRevealedTiles(MemoryBoard); secondOpened = ComputerPlayer.ChooseSecondTile(MemoryBoard); key = MemoryBoard.GetKey(secondOpened.X, secondOpened.Y); TileButtonMatrix[secondOpened.X, secondOpened.Y].Image = GameManager.sr_ValueDictionary[key].Image; SecondChoiceButton = TileButtonMatrix[secondOpened.X, secondOpened.Y]; SecondChoiceButton.BackColor = Player2Name.BackColor; ComputerTurnState = eComputerTurnState.EndTurn; }
private void firstTileChoosenByComputer() { Point firstOpened = new Point(); int key; ComputerPlayer.ZeroAndUpdateRevealedTiles(MemoryBoard); firstOpened = ComputerPlayer.ChooseFirstTile(MemoryBoard); key = MemoryBoard.GetKey(firstOpened.X, firstOpened.Y); TileButtonMatrix[firstOpened.X, firstOpened.Y].Image = GameManager.sr_ValueDictionary[key].Image; FirstChoiceButton = TileButtonMatrix[firstOpened.X, firstOpened.Y]; FirstChoiceButton.BackColor = Player2Name.BackColor; ComputerTurnState = eComputerTurnState.SecondTileToChoose; }