private void OpenCard(CardButton i_Card) { i_Card.Text = values[i_Card.IndexOfValue].ToString(); if (m_CurrentPlayer == m_FirstPlayerName) { i_Card.BackColor = k_FirstPlayerColor; } if (m_CurrentPlayer == m_SecondPlayerName) { i_Card.BackColor = k_SecondPlayerColor; } }
private void InitializeCards() { for (int i = 0; i < m_Rows; i++) { for (int j = 0; j < m_Columns; j++) { int index = (m_Columns * i) + j; CardButton card = new CardButton(indexesOfValues[index], values[indexesOfValues[index]], index); card.Height = 60; card.Width = 60; card.Location = new Point(10 + ((card.Width + 10) * j), 10 + (card.Height + 10) * i); m_Cards.Add(card); card.BackColor = k_ClosedCardColor; card.Click += m_ButtonCard_Click; this.Controls.Add(card); } } }
private void m_ButtonCard_Click(object sender, EventArgs e) { CardButton card = sender as CardButton; if (m_ButtonEnable == true && card.Text == string.Empty && m_CurrentPlayer != "Computer") { OpenCard(card); gameManager.Move(card.ButtonIndex); this.Refresh(); } if (m_CurrentPlayer == "Computer") { System.Threading.Thread.Sleep(500); OpenCard(card); gameManager.Move(card.ButtonIndex); this.Refresh(); System.Threading.Thread.Sleep(500); } if (gameManager.FirstMove) { m_FirstCard = card; if (m_CurrentPlayer == "Computer") { System.Threading.Thread.Sleep(1000); ComputerTurn(); } } else { m_ButtonEnable = false; m_SecondCard = card; if (gameManager.WonRound) { UpdatePoints(m_CurrentPlayer); if (m_CurrentPlayer == "Computer" && !gameManager.GameFinished) { ComputerTurn(); } } else { System.Threading.Thread.Sleep(2000); SwitchPlayers(); CloseCards(); if (m_CurrentPlayer == "Computer") { ComputerTurn(); } } } if (gameManager.GameFinished) { result = MessageBox.Show(string.Format("{0}\n\n Would you like to play again?", GetResultLine()), "Game Result", MessageBoxButtons.YesNo); if (result == DialogResult.No) { this.Close(); } else if (result == DialogResult.Yes) { this.Visible = false; MainGame newGame = new MainGame(m_Columns, m_Rows, m_FirstPlayerName, m_SecondPlayerName); newGame.ShowDialog(); } } }