private bool tryUncoverPairFromMemory() { bool uncoveredPartnerFromMemory = false; for (int i = 0; i < MemoryBoard.GetLength(0) && !uncoveredPartnerFromMemory; i++) { for (int j = 0; j < MemoryBoard.GetLength(1) && !uncoveredPartnerFromMemory; j++) { if (OriginalBoard[i, j].Covered) { uncoveredPartnerFromMemory = tryUncoverPartnerFromMemory(MemoryBoard[i, j]); if (uncoveredPartnerFromMemory) { OriginalBoard[i, j].WaitingForPartner = true; OriginalBoard[i, j].Covered = false; onMoveDone(); OriginalBoard[i, j].UpdateFoundPartner(); } } } } return(uncoveredPartnerFromMemory); }
private void enableDisableButtonsComputerTurn(bool i_EnableDisable) { MemoryGameButton button; foreach (Control c in Controls) { button = c as MemoryGameButton; if (button != null) { if (i_EnableDisable == true) { if (MemoryBoard.IsOpen(button.Row, button.Col) == false) { button.Click += MemoryGameButton_Click; } } else { if (MemoryBoard.IsOpen(button.Row, button.Col) == false) { button.Click -= MemoryGameButton_Click; } } } } }
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 computerChooseSameTiles() { MemoryBoard.MakeOpen(FirstChoiceButton.Row, FirstChoiceButton.Col, SecondChoiceButton.Row, SecondChoiceButton.Col); incScore(); updateLabel(); IsGameWon(); }
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 playerChooseSameTiles(MemoryGameButton i_BoardTileButton) { MemoryBoard.MakeOpen(i_BoardTileButton.Row, i_BoardTileButton.Col, FirstChoiceButton.Row, FirstChoiceButton.Col); incScore(); updateLabel(); FirstChoiceButton.Click -= MemoryGameButton_Click; SecondChoiceButton.Click -= MemoryGameButton_Click; IsGameWon(); }
public void InitialMemory() { for (int i = 0; i < MemoryBoard.GetLength(0); i++) { for (int j = 0; j < MemoryBoard.GetLength(1); j++) { MemoryBoard[i, j] = new Cell(); } } }
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 playerChooseDifferentTiles(MemoryGameButton i_BoardTileButton) { bool disableButtons = false; enableDisableButtonsPvPTurn(disableButtons); PicTimer.Start(); MemoryBoard.MakeTurnOpen(i_BoardTileButton.Row, i_BoardTileButton.Col); MemoryBoard.MakeRevealed(i_BoardTileButton.Row, i_BoardTileButton.Col, FirstChoiceButton.Row, FirstChoiceButton.Col); Turn = !Turn; SetCurrentPlayerName(); }
private void copyUncoveredCells() { for (int i = 0; i < MemoryBoard.GetLength(0); i++) { for (int j = 0; j < MemoryBoard.GetLength(1); j++) { if (!OriginalBoard[i, j].Covered) { MemoryBoard[i, j].Content = OriginalBoard[i, j].Content; } } } }
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; }
private void computerChooseDifferentTiles() { const bool k_EnableButtons = true; ComputerTimer.Stop(); MemoryBoard.MakeRevealed(FirstChoiceButton.Row, FirstChoiceButton.Col, SecondChoiceButton.Row, SecondChoiceButton.Col); TileButtonMatrix[FirstChoiceButton.Row, FirstChoiceButton.Col].Image = null; TileButtonMatrix[SecondChoiceButton.Row, SecondChoiceButton.Col].Image = null; TileButtonMatrix[FirstChoiceButton.Row, FirstChoiceButton.Col].BackColor = BackColor; TileButtonMatrix[SecondChoiceButton.Row, SecondChoiceButton.Col].BackColor = BackColor; Turn = !Turn; SetCurrentPlayerName(); enableDisableButtonsComputerTurn(k_EnableButtons); }
private void enableDisableButtonsPvPTurn(bool i_EnableDisable) { MemoryGameButton button; foreach (Control c in Controls) { button = c as MemoryGameButton; if (button != null) { if (c != FirstChoiceButton && c != SecondChoiceButton && MemoryBoard.IsOpen(button.Row, button.Col) == false) { c.Enabled = i_EnableDisable; } } } }
private void IsGameWon() { MessageBoxButtons button = MessageBoxButtons.YesNo; string winnerName = string.Empty; string loserName = string.Empty; string endGameMsg = string.Empty; if (MemoryBoard.IsGameWon()) { ComputerTimer.Stop(); if (ScorePlayer1 > ScorePlayer2) { winnerName = Player1Name.Text.Substring(0, Player1NameLength); loserName = Player2Name.Text.Substring(0, Player2NameLength); endGameMsg = string.Format("congratulations {0} you won the game with {1} pairs! {2}{3} with {4} pairs, Don't worry, maybe next time", winnerName, ScorePlayer1, Environment.NewLine, loserName, ScorePlayer2); } else if (ScorePlayer2 > ScorePlayer1) { winnerName = Player2Name.Text.Substring(0, Player2NameLength); loserName = Player1Name.Text.Substring(0, Player1NameLength); endGameMsg = string.Format("Congratulations!! {0} you won the game with {1} pairs! {2}{3} with {4} pairs, Don't worry, maybe next time", winnerName, ScorePlayer2, Environment.NewLine, loserName, ScorePlayer1); } else { endGameMsg = string.Format("Its a tie!! {0}both of you got {1} pairs!", Environment.NewLine, ScorePlayer1); } endGameMsg = string.Format("{0}{1}Do you want to start another game?", endGameMsg, Environment.NewLine); DialogResult result = MessageBox.Show(endGameMsg, "Memory Game", button); if (result == DialogResult.Yes) { DialogResult = DialogResult.OK; } else { DialogResult = DialogResult.No; } Close(); } }
private bool tryUncoverPartnerFromMemory(Cell i_Cell) { bool foundCellInMemory = false; for (int i = 0; i < MemoryBoard.GetLength(0) && !foundCellInMemory; i++) { for (int j = 0; j < MemoryBoard.GetLength(1) && !foundCellInMemory; j++) { if (MemoryBoard[i, j].Content != " " && MemoryBoard[i, j].Content == i_Cell.Content && MemoryBoard[i, j] != i_Cell && OriginalBoard[i, j] != i_Cell && !OriginalBoard[i, j].FoundPartner) { foundCellInMemory = true; OriginalBoard[i, j].WaitingForPartner = true; OriginalBoard[i, j].Covered = false; onMoveDone(); OriginalBoard[i, j].UpdateFoundPartner(); } } } return(foundCellInMemory); }
public void Awake() { if (string.IsNullOrEmpty(this.AppId)) { Debug.LogError("You must enter your AppId from the Dashboard in the component: Scripts, MemoryGui, AppId before you can use this demo."); Debug.Break(); } Application.runInBackground = true; CustomTypes.Register(); this.GameClientInstance = new MemoryGameClient(); this.GameClientInstance.memoryGui = this; this.GameClientInstance.AppId = this.AppId; // set in Inspector this.GameClientInstance.AppVersion = "1.0"; board = this.GetComponentInChildren <MemoryBoard>(); board.GameClientInstance = this.GameClientInstance; GameClientInstance.board = board; board.MemoryGui = this; this.DisableButtons(); }
public void Awake() { if (string.IsNullOrEmpty(this.AppId)) { Debug.LogError("You must enter your AppId from the Dashboard in the component: Scripts, MemoryGui, AppId before you can use this demo."); Debug.Break(); } Application.runInBackground = true; CustomTypes.Register(); this.GameClientInstance = new MemoryGameClient(); this.GameClientInstance.memoryGui = this; this.GameClientInstance.AppId = this.AppId; // set in Inspector this.GameClientInstance.AppVersion = "1.0"; board = this.GetComponentInChildren<MemoryBoard>(); board.GameClientInstance = this.GameClientInstance; GameClientInstance.board = board; board.MemoryGui = this; this.DisableButtons(); }