public void InitializeNewGame() { Deck = GenerateDeck(); ChooseFirstRoundPlayer(); ExcludedCards.Clear(); var cardsPerPlayer = 10; var excludedCards = 0; // In evasion mode, cards are distributed "evenly" between players, with some cards remaining out, // when 3 or 5 players are playing. If 2 or 4 players are playing, 10 cards each are given, like // in plain mode. // I some cards remain out, they will be given to the player who got the last point. if (GameSetup.GameMode == GameMode.Evasion) { if (Players.Count != 2 && Players.Count != 4) { cardsPerPlayer = Deck.Count / Players.Count; excludedCards = Deck.Count % Players.Count; } } foreach (var player in Players) { player.Cards = Deck.GetAndRemove(0, cardsPerPlayer); player.ExtraPoints.Clear(); } ExcludedCards = Deck.GetAndRemove(0, excludedCards); foreach (var team in Teams) { team.Points = 0; } CardsPlayed.Clear(); CardsDrew.Clear(); CardsPlayedPreviousRound.Clear(); RoundEnded = false; IsFirstRound = true; }
public bool MakeMove(string playerConnectionId, Card card) { var player = GetPlayerFromConnectionId(playerConnectionId); if (player.Cards.FirstOrDefault(x => x.Color == card.Color && x.Number == card.Number) == null) { return(false); } if (playerConnectionId != UserTurnToPlay.ConnectionId) { return(false); } if (CardsPlayed.Count == Players.Count) { CardsPlayed.Clear(); } if (CardsPlayed.Count == Players.Count - 1) { CardsPlayedPreviousRound = CardsPlayed.ToList(); } if (CardsDrew.Count == Players.Count) { CardsDrew.Clear(); } if (CardsPlayed.Count != 0 && card.Color != _firstCardPlayedInRound.Card.Color && player.Cards.Any(x => x.Color == _firstCardPlayedInRound.Card.Color)) { return(false); } CardsPlayed.Add(new CardAndUser(card, player.User)); if (CardsPlayed.Count == Players.Count) { CardsPlayedPreviousRound = CardsPlayed.ToList(); } _firstCardPlayedInRound = CardsPlayed.FirstOrDefault(); _strongestCardInRound = CardsPlayed.Where(x => x.Card.Color == _firstCardPlayedInRound.Card.Color).OrderByDescending(item => item.Card.Strength).First(); RemoveCardFromHand(player, card); ChangePlayersTurn(); if (CardsPlayed.Count == Players.Count) { var isLastPoint = Players.Where(x => x.Cards.Any()).Count() == 0; UserTurnToPlay = Players.FirstOrDefault(x => x.User.Name == _strongestCardInRound.User.Name).User; var teamRoundWinner = Teams.FirstOrDefault(x => x.Users.FirstOrDefault(y => y.ConnectionId == UserTurnToPlay.ConnectionId) != null); foreach (var cardPlayed in CardsPlayed) { teamRoundWinner.Points += cardPlayed.Card.Value(GameSetup.GameMode); } if (isLastPoint) { teamRoundWinner.Points += 3; if (GameSetup.GameMode == GameMode.Evasion) { // In evasion mode, the spurious points of all players and the excluded cards go to the // player who got the last point. // However, if doing so, the player who got the last point gets maximum points (Cappotto), // he/she transfers the total to each player, and he/she stays at 0 points. foreach (var team in Teams) { if (team.Name != teamRoundWinner.Name) { var spurious = team.Points % 3; teamRoundWinner.Points += spurious; team.Points -= spurious; } } // Add points from excluded cards // TODO: There should be an animation showing this happening teamRoundWinner.Points += ExcludedCards.Sum(x => x.Value(GameSetup.GameMode)); // Cappotto if (Teams.All(x => x.Name == teamRoundWinner.Name || x.Points == 0)) { var total = teamRoundWinner.Points; foreach (var team in Teams) { team.Points = total; } teamRoundWinner.Points = 0; } } } DrawCards(); } if (CardsPlayed.Count == Players.Count && IsFirstRound) { IsFirstRound = false; } return(true); }