Exemple #1
0
        public GameResponse <PlayerStats> RequestPlayerStats(Guid playerId, Chair chair)
        {
            if (chair == Chair.Standing)
            {
                return(GameResponse <PlayerStats> .Fail());
            }

            var player = _players.SingleOrDefault(p => p.Id == playerId);

            if (player == null)
            {
                return(GameResponse <PlayerStats> .Fail());
            }

            var playerForStats = _players.SingleOrDefault(p => p.Chair == chair);

            if (playerForStats == null)
            {
                return(GameResponse <PlayerStats> .Fail());
            }

            var playerStats = new PlayerStats(playerForStats);

            return(GameResponse <PlayerStats> .Pass(playerStats));
        }
Exemple #2
0
        public GameResponse <Card> PayForCard(Guid playerId, IDictionary <Resource, int> resources)
        {
            if (Phase != GamePhase.UsePeopleActions)
            {
                return(GameResponse <Card> .Fail());
            }

            var player = _players.SingleOrDefault(p => p.Id == playerId);

            if (player == null)
            {
                return(GameResponse <Card> .Fail());
            }

            if (!player.PayingForSpace.HasValue)
            {
                return(GameResponse <Card> .Fail());
            }

            var cardSlot = player.PayingForSpace.Value;

            Card card = Board.GetCardFromSpace(cardSlot);

            int cost = (int)cardSlot - (int)BoardSpace.CivilizationCardSlot1 + 1;

            foreach (var resource in resources)
            {
                player.PlayerBoard.Resources[resource.Key] -= resource.Value;
            }

            player.PayingForSpace = null;

            return(GameResponse <Card> .Pass(card));
        }
Exemple #3
0
        // should this just be random? Maybe make house rules?
        // which colors? Any order for choice?
        public GameResponse ClaimPlayerColor(Guid playerId, PlayerColor color)
        {
            if (Phase != GamePhase.ChoosePlayers)
            {
                return(GameResponse.Fail());
            }

            var player = _players.SingleOrDefault(p => p.Id == playerId);

            if (player == null)
            {
                return(GameResponse.Fail());
            }
            if (player.Color == color)
            {
                return(GameResponse.Fail());
            }

            if (color != PlayerColor.NotChosenYet && _players.Any(p => p.Color == color))
            {
                return(GameResponse.Fail());
            }

            player.Color = color;

            return(GameResponse.Pass());
        }
Exemple #4
0
        public GameResponse RenamePlayer(Guid playerId, string newName)
        {
            if (Phase != GamePhase.ChoosePlayers)
            {
                return(GameResponse.Fail());
            }

            if (string.IsNullOrWhiteSpace(newName))
            {
                return(GameResponse.Fail());
            }

            if (newName.Contains('\n') || newName.Contains('\r'))
            {
                return(GameResponse.Fail());
            }

            if (newName.Length > Player.MAX_NAME_LENGTH)
            {
                return(GameResponse.Fail());
            }

            var playerToRename = _players.SingleOrDefault(p => p.Id == playerId);

            if (playerToRename == null)
            {
                return(GameResponse.Fail());
            }

            playerToRename.Name = newName;

            return(GameResponse.Pass());
        }
Exemple #5
0
        // moves to next phase once all are ready
        public GameResponse MarkPlayerAsReadyToStart(Guid playerId)
        {
            if (Phase != GamePhase.ChoosePlayers)
            {
                return(GameResponse.Fail());
            }

            var player = _players.SingleOrDefault(p => p.Id == playerId);

            if (player == null)
            {
                return(GameResponse.Fail());
            }
            if (player.ReadyToStart)
            {
                return(GameResponse.Fail());
            }

            player.ReadyToStart = true;

            if (_players.All(p => p.ReadyToStart) && _players.Count() > 1)
            {
                IsThinking = true;
                var task = new Task <bool>(InitialBoardSetup);
                task.Start();
            }

            return(GameResponse.Pass());
        }
Exemple #6
0
        // should this just be random? Maybe make house rules?
        public GameResponse SetPlayerSeat(Guid playerId, Chair chair)
        {
            if (Phase != GamePhase.ChoosePlayers)
            {
                return(GameResponse.Fail());
            }

            var player = _players.SingleOrDefault(p => p.Id == playerId);

            if (player == null)
            {
                return(GameResponse.Fail());
            }
            if (player.Chair == chair)
            {
                return(GameResponse.Fail());
            }

            if (chair != Chair.Standing && _players.Any(p => p.Chair == chair))
            {
                return(GameResponse.Fail());
            }

            player.Chair = chair;

            return(GameResponse.Pass());
        }
Exemple #7
0
        public GameResponse FeedPeople(Guid playerId, IDictionary <Resource, int> otherResourcesToFeedWith)
        {
            if (Phase != GamePhase.FeedPeople)
            {
                return(GameResponse.Fail());
            }

            var player = _players.SingleOrDefault(p => p.Id == playerId);

            if (player == null)
            {
                return(GameResponse.Fail());
            }

            var board        = player.PlayerBoard;
            var peopleToFeed = Math.Max(0, board.TotalPeople - board.FoodTrack);

            player.PlayerBoard.Food = board.Food - peopleToFeed;

            // TODO: support feeding with resources

            player.NeedsToFeed = false;

            if (!_players.Any(p => p.NeedsToFeed))
            {
                Phase = GamePhase.NewRoundPrep;
                PrepareNewRound();
                Phase = GamePhase.PlayersPlacePeople;
            }

            return(GameResponse.Pass());
        }
Exemple #8
0
        public GameResponse <PlayerStats> RequestPlayerStats(Guid playerId)
        {
            var player = _players.SingleOrDefault(p => p.Id == playerId);

            if (player == null)
            {
                return(GameResponse <PlayerStats> .Fail());
            }

            var playerStats = new PlayerStats(player);

            return(GameResponse <PlayerStats> .Pass(playerStats));
        }
Exemple #9
0
        public GameResponse <IEnumerable <PlayerStats> > RequestAllPlayerStats(Guid playerId)
        {
            var player = _players.SingleOrDefault(p => p.Id == playerId);

            if (player == null)
            {
                return(GameResponse <IEnumerable <PlayerStats> > .Fail());
            }

            var playerStats = _players.Select(p => new PlayerStats(p));

            return(GameResponse <IEnumerable <PlayerStats> > .Pass(playerStats));
        }
Exemple #10
0
        public GameResponse RemovePlayer(Guid playerId)
        {
            if (Phase != GamePhase.ChoosePlayers)
            {
                return(GameResponse.Fail());
            }

            var playerToRemove = _players.SingleOrDefault(p => p.Id == playerId);

            if (!_players.Remove(playerToRemove))
            {
                return(GameResponse.Fail());
            }

            return(GameResponse.Pass());
        }
Exemple #11
0
        public GameResponse TapTool(Guid playerId, IList <Tool> tools)
        {
            if (Phase != GamePhase.UsePeopleActions)
            {
                return(GameResponse.Fail());
            }

            var player = _players.SingleOrDefault(p => p.Id == playerId);

            if (player == null)
            {
                return(GameResponse.Fail());
            }

            throw new NotImplementedException();
        }
Exemple #12
0
        public GameResponse <int> PayForHutTile(Guid playerId, IDictionary <Resource, int> resources)
        {
            if (Phase != GamePhase.UsePeopleActions)
            {
                return(GameResponse <int> .Fail());
            }

            var player = _players.SingleOrDefault(p => p.Id == playerId);

            if (player == null)
            {
                return(GameResponse <int> .Fail());
            }

            throw new NotImplementedException();
        }
Exemple #13
0
        public GameResponse ClaimLotteryResult(Guid playerId, int rollValue)
        {
            if (Phase != GamePhase.UsePeopleActions)
            {
                return(GameResponse.Fail());
            }

            var player = _players.SingleOrDefault(p => p.Id == playerId);

            if (player == null)
            {
                return(GameResponse.Fail());
            }

            throw new NotImplementedException();
        }
Exemple #14
0
        public GameResponse UseSpecialAction(Guid playerId, SpecialAction action)
        {
            if (Phase != GamePhase.UsePeopleActions && Phase != GamePhase.FeedPeople)
            {
                return(GameResponse.Fail());
            }

            var player = _players.SingleOrDefault(p => p.Id == playerId);

            if (player == null)
            {
                return(GameResponse.Fail());
            }

            // any time, e.g. 2 resource card
            throw new NotImplementedException();
        }
Exemple #15
0
        public GameResponse CancelLastPlacement(Guid playerId)
        {
            if (Phase != GamePhase.PlayersPlacePeople)
            {
                return(GameResponse.Fail());
            }

            var player = _players.SingleOrDefault(p => p.Id == playerId);

            if (player == null)
            {
                return(GameResponse.Fail());
            }

            // should this be allowed? probably will be a house rule including things like how many times
            throw new NotImplementedException();
        }
Exemple #16
0
        public GameResponse <Guid> AddPlayer()
        {
            if (Phase != GamePhase.ChoosePlayers)
            {
                return(GameResponse <Guid> .Fail());
            }

            if (_players.Count() == MAX_PLAYER_COUNT)
            {
                return(GameResponse <Guid> .Fail());
            }

            var player = new Player();

            _players.Add(player);

            return(GameResponse <Guid> .Pass(player.Id));
        }
Exemple #17
0
        public GameResponse ChangePlayerMode(Guid playerId, PlayerMode mode)
        {
            if (Phase != GamePhase.ChoosePlayers)
            {
                return(GameResponse.Fail());
            }

            var player = _players.SingleOrDefault(p => p.Id == playerId);

            if (player == null)
            {
                return(GameResponse.Fail());
            }

            player.Mode = mode;

            return(GameResponse.Pass());
        }
Exemple #18
0
        public GameResponse <DiceResult> UseActionOfPeople(Guid playerId, BoardSpace boardSpace)
        {
            if (Phase != GamePhase.UsePeopleActions)
            {
                return(GameResponse <DiceResult> .Fail());
            }

            var player = _players.SingleOrDefault(p => p.Id == playerId);

            if (player == null)
            {
                return(GameResponse <DiceResult> .Fail());
            }

            if (player != TurnOrder.Current)
            {
                return(GameResponse <DiceResult> .Fail());
            }

            var space = Board.Spaces.SingleOrDefault(s => s.BoardSpace == boardSpace);

            if (!space.PlayerPreviouslyPlaced(player))
            {
                return(GameResponse <DiceResult> .Fail());
            }

            var diceResult = UseAction(player, space);

            if (player.PlayerBoard.PeopleToPlace == player.PlayerBoard.TotalPeople)
            {
                TurnOrder.Next();
            }

            if (_players.Sum(p => p.PlayerBoard.PeopleToPlace) == _players.Sum(p => p.PlayerBoard.TotalPeople))
            {
                foreach (var playerToChange in _players)
                {
                    playerToChange.NeedsToFeed = true;
                }
                Phase = GamePhase.FeedPeople;
            }

            return(GameResponse <DiceResult> .Pass(diceResult));
        }
Exemple #19
0
        public GameResponse GivePlayerRandomName(Guid playerId)
        {
            if (Phase != GamePhase.ChoosePlayers)
            {
                return(GameResponse.Fail());
            }

            var player = _players.SingleOrDefault(p => p.Id == playerId);

            if (player == null)
            {
                return(GameResponse.Fail());
            }

            var newName = Player.DefaultPlayerNames.ChooseAtRandom();

            player.Name = newName;

            return(GameResponse.Pass());
        }
Exemple #20
0
        // removes player from 1st player drawing
        public GameResponse DeclineStartPlayer(Guid playerId)
        {
            if (Phase != GamePhase.ChoosePlayers)
            {
                return(GameResponse.Fail());
            }

            var player = _players.SingleOrDefault(p => p.Id == playerId);

            if (player == null)
            {
                return(GameResponse.Fail());
            }

            if (!player.WantsToBeFirstPlayer)
            {
                return(GameResponse.Fail());
            }

            player.WantsToBeFirstPlayer = false;

            return(GameResponse.Pass());
        }
Exemple #21
0
        public GameResponse PlacePeople(Guid playerId, int quantity, BoardSpace boardSpace)
        {
            if (Phase != GamePhase.PlayersPlacePeople)
            {
                return(GameResponse.Fail());
            }

            var player = _players.SingleOrDefault(p => p.Id == playerId);

            if (player == null)
            {
                return(GameResponse.Fail());
            }

            if (TurnOrder.Current != player)
            {
                return(GameResponse.Fail());
            }

            var space = Board.Spaces.SingleOrDefault(s => s.BoardSpace == boardSpace);

            if (space.QuantityIsInvalidForSpace(quantity))
            {
                return(GameResponse.Fail());
            }

            if (space.PlayerPreviouslyPlaced(player) && !space.AllowsPartialPlacement)
            {
                return(GameResponse.Fail());
            }

            if (space.NotAvailable(quantity))
            {
                return(GameResponse.Fail());
            }

            if (space.HasTooManyUniquePlayers())
            {
                return(GameResponse.Fail());
            }

            if (!player.PlayerBoard.HasAvailablePeopleToPlace(quantity))
            {
                return(GameResponse.Fail());
            }

            player.PlayerBoard.SetPeopleAsPlaced(quantity);
            space.Place(player, quantity);

            if (_players.Sum(p => p.PlayerBoard.PeopleToPlace) == 0)
            {
                Phase = GamePhase.UsePeopleActions;
                TurnOrder.SetCheiftanToCurrent();
            }
            else
            {
                TurnOrder.NextPlayerToPlace();
            }

            return(GameResponse.Pass());
        }