public static PlayersChoice GetPlayersChoice() { PlayersChoice choice = PlayersChoice.NotSelected; ConsoleKeyInfo pressedKey = Console.ReadKey(true); switch (pressedKey.Key) { case ConsoleKey.A: choice = PlayersChoice.PlayCard; break; case ConsoleKey.S: choice = PlayersChoice.SaveToHand; break; case ConsoleKey.D: choice = PlayersChoice.PlayDifferentCard; break; default: throw new InvalidOperationException("You did not choose an option."); } return(choice); }
// $G$ DSN-999 (-10) no UI and logic speration - this code belongs to the logic // $G$ DSN-003 (-5) This method is too long. Should be split into several methods. private void checkPair(Button i_FirstCard, Button i_SecondCard) { if (!Card.CompareCards((i_FirstCard.Tag as Cell).HoldsCard, (i_SecondCard.Tag as Cell).HoldsCard, FirstPlayer.Turn ? FirstPlayer : SecondPlayer)) { i_FirstCard.Text = string.Empty; i_FirstCard.BackColor = Color.FromArgb(255, 240, 240, 240); i_SecondCard.Text = string.Empty; i_SecondCard.BackColor = Color.FromArgb(255, 240, 240, 240); i_FirstCard.Refresh(); i_SecondCard.Refresh(); FirstPlayer.Turn = !FirstPlayer.Turn; SecondPlayer.Turn = !SecondPlayer.Turn; } else { firstPlayerLabel.Refresh(); secondPlayerLabel.Refresh(); OpenCards.Add(i_FirstCard); OpenCards.Add(i_SecondCard); } PlayersChoice.Clear(); if (SecondPlayer.Turn && SecondPlayer.IsComputer) { foreach (Control button in Controls) { if (button.Name.Contains("Cell")) { button.Enabled = false; } } computersTurn(); } else { foreach (Control button in Controls) { if (button.Name.Contains("Cell")) { if (!(button.Tag as Cell).HoldsCard.Open) { button.Enabled = true; } } } } }
private void UpdateGameFlow(Button i_PictureBox) { PlayersChoice.Add(i_PictureBox); if (PlayersChoice.Count == 2) { foreach (Control card in Controls) { if (card.Name.Contains("Cell")) { card.Enabled = false; } } Button firstCard = PlayersChoice[0]; Button secondCard = PlayersChoice[1]; System.Threading.Thread.Sleep(2000); checkPair(firstCard, secondCard); } }
public static void PlayCard(Game game, Player currentPlayer, Card card, PlayersChoice choice = PlayersChoice.NotSelected) { switch (choice) { case PlayersChoice.PlayCard: card.Action(game); game.IsCardPlayed = true; break; case PlayersChoice.SaveToHand: if (currentPlayer.Hand.Count < 3) { currentPlayer.Hand.Add(card); } else { choice = PlayersChoice.PlayDifferentCard; PlayCard(game, currentPlayer, card, choice); } break; case PlayersChoice.PlayDifferentCard: currentPlayer.Hand.Add(card); if (currentPlayer.Hand.Count > 0) { DisplaySelectFromHand(currentPlayer.Hand, Constants.RightBorderX + 3, 27); card = SelectCardFromHand(currentPlayer.Hand); currentPlayer.Hand.Remove(card); choice = PlayersChoice.PlayCard; PlayCard(game, currentPlayer, card, choice); } break; } }