/// <summary> /// Shows the hand of <paramref name="player"/> /// </summary> /// <param name="player"></param> public void ShowPlayerHand(BlackPetePlayer <T> player) { foreach (string item in player.ShowPlayerCards()) { GameLogger.LogMessage(item); } }
private bool CheckIfPlayerDone(BlackPetePlayer <T> player) { if (player.CardsInHand.Count == 0) { return(true); } return(false); }
/// <summary> /// Take a specific card from <paramref name="otherPlayer"/> /// </summary> /// <param name="otherPlayer"></param> /// <param name="index"></param> /// <returns>Returns the card stolen</returns> public Card TakeCard(BlackPetePlayer <T> otherPlayer, int index) { Card stolenCard = otherPlayer.CardsInHand[index]; CardsInHand.Add(stolenCard); otherPlayer.CardsInHand.Remove(stolenCard); return(stolenCard); }
/// <summary> /// Steals a random card from <paramref name="otherPlayer"/> /// </summary> /// <param name="otherPlayer"></param> /// <returns>Returns the card stolen</returns> public Card TakeCard(BlackPetePlayer <T> otherPlayer) { Card stolenCard = otherPlayer.CardsInHand[rng.Next(otherPlayer.CardsInHand.Count)]; CardsInHand.Add(stolenCard); otherPlayer.CardsInHand.Remove(stolenCard); return(stolenCard); }
public override void StartGame() { PairCheckAllPlayers(); do { //Loops through each players turn for (int i = 0; i < Players.Count; i++) { BlackPetePlayer <T> otherPlayer = (BlackPetePlayer <T>)Players[i == 0 ? Players.Count - 1 : i - 1]; Card stolenCard = null; if (Players[i].IsAi) { try { stolenCard = ((BlackPetePlayer <T>)Players[i]).TakeCard(otherPlayer); } catch (Exception) { GameLogger.LogMessage("Something went wrong with the Ai"); } } else { //!Way too big a method probably //!Gets a user input between 1 and the next players hand amount string choice = ""; //((ConsoleLogger)GameLogger).GetUInput( //Players[i].Name + ", it is your turn" + "\n" + //"Choose a number between 1-" + otherPlayer.CardsInHand.Count); try { stolenCard = ((BlackPetePlayer <T>)Players[i]).TakeCard(otherPlayer, Convert.ToInt32(choice)); } catch (Exception) { stolenCard = ((BlackPetePlayer <T>)Players[i]).TakeCard(otherPlayer); GameLogger.LogMessage("Your input was invalid and you instead took a random card! \n Try entering a valid number next time"); } } //Steal a card from your opponent, then check whether or not it makes a pair if (((BlackPetePlayer <T>)Players[i]).CheckForNewPair(stolenCard)) { GameLogger.LogMessage(Players[i].Name + " Stole " + ((BlackPetePlayer <T>)Players[i]).TakeCard(otherPlayer).ToString() + " from " + otherPlayer.Name); } else { GameLogger.LogMessage(Players[i].Name + " got a " + stolenCard.Name); } if (CheckIfPlayerDone((BlackPetePlayer <T>)Players[i])) { Players.RemoveAt(i); } else if (CheckIfPlayerDone(otherPlayer)) { Players.Remove(otherPlayer); } } } while (Players.Count != 1); }