private bool isPairAvailableInMemory(MemoryGameBoard i_GameBoard, ref ComputerAI i_ComputerMemory, out TwoPairsOfIndexes o_Indexes) { bool isPairFound = false; o_Indexes = new TwoPairsOfIndexes(); for (int i = 0; i < k_NumberOfItemsToFillBoard; i++) { if (i_ComputerMemory.ComputerMemory[i].IsTwoPairsHaveValue()) { o_Indexes.FirstRowIndex = i_ComputerMemory.ComputerMemory[i].FirstRowIndex; o_Indexes.FirstColoumnIndex = i_ComputerMemory.ComputerMemory[i].FirstColoumnIndex; o_Indexes.SecondRowIndex = i_ComputerMemory.ComputerMemory[i].SecondRowIndex; o_Indexes.SecondColoumnIndex = i_ComputerMemory.ComputerMemory[i].SecondColoumnIndex; MemoryGameCard firstCardRevealedFromMemory = i_GameBoard.BoardMatrix[(int)o_Indexes.FirstRowIndex, (int)o_Indexes.FirstColoumnIndex]; firstCardRevealedFromMemory.IsVisable = true; MemoryGameCard secondCardRevealedFromMemory = i_GameBoard.BoardMatrix[(int)o_Indexes.SecondRowIndex, (int)o_Indexes.SecondColoumnIndex]; secondCardRevealedFromMemory.IsVisable = true; i_ComputerMemory.ComputerMemory[i].MarkTwoPairsAsUnAvalabale(); isPairFound = true; break; } } return(isPairFound); }
public MemoryGameBoard(int i_Hight, int i_Width) { if (i_Hight < 1) { throw new ArgumentException("ERROR. Board hight should be positive."); } if (i_Width < 1) { throw new ArgumentException("ERROR. Board width should be positive."); } if ((i_Hight * i_Width) % 2 != 0) { throw new ArgumentException("ERROR. Board hight * width should be even."); } r_BoardHight = i_Hight; r_BoardWidth = i_Width; m_numberOfRevealedCards = 0; m_BoardMatrix = new MemoryGameCard[r_BoardHight, r_BoardWidth]; for (int i = 0; i < r_BoardHight; i++) { for (int j = 0; j < r_BoardWidth; j++) { m_BoardMatrix[i, j] = new MemoryGameCard(); } } }
public void MakeAComputerMove(MemoryGameBoard i_GameBoard, ref ComputerAI i_ComputerMemory, out TwoPairsOfIndexes o_Indexes) { if (!isPairAvailableInMemory(i_GameBoard, ref i_ComputerMemory, out o_Indexes)) { int getRowIndex, getColoumnIndex; MemoryGameCard firstCardRevealed = revealRandomCardByComputer(i_GameBoard, out getRowIndex, out getColoumnIndex, i_ComputerMemory); o_Indexes.FirstRowIndex = getRowIndex; o_Indexes.FirstColoumnIndex = getColoumnIndex; o_Indexes.SecondRowIndex = (int)i_ComputerMemory.ComputerMemory[firstCardRevealed.CardValue].FirstRowIndex; o_Indexes.SecondColoumnIndex = (int)i_ComputerMemory.ComputerMemory[firstCardRevealed.CardValue].FirstColoumnIndex; if (o_Indexes.SecondRowIndex != getRowIndex || o_Indexes.SecondColoumnIndex != getColoumnIndex) { MemoryGameCard pairOfRandomCard = i_GameBoard.BoardMatrix[(int)o_Indexes.SecondRowIndex, (int)o_Indexes.SecondColoumnIndex]; pairOfRandomCard.IsVisable = true; } else { revealRandomCardByComputer(i_GameBoard, out getRowIndex, out getColoumnIndex, i_ComputerMemory); o_Indexes.SecondRowIndex = getRowIndex; o_Indexes.SecondColoumnIndex = getColoumnIndex; } } }
public void PlayASuccessfulTurn(MemoryGameBoard i_GameBoard, Player i_CurrentPlayer, MemoryGameCard i_CardRevealed, ComputerAI i_ComputerMemory) { if (i_ComputerMemory != null) { i_ComputerMemory.ComputerMemory[i_CardRevealed.CardValue].MarkTwoPairsAsUnAvalabale(); } i_CurrentPlayer.IncreaseScore(); i_GameBoard.NumberOfRevealedCards += 2; }
public void PlayAnUnSeccessfulTurn(MemoryGameCard io_FirstCardRevealed, MemoryGameCard io_SecondCardRevealed) { io_FirstCardRevealed.IsVisable = false; io_SecondCardRevealed.IsVisable = false; }