Ejemplo n.º 1
0
        private void AddTakenChairsToQueue(Chair chair)
        {
            var playerInChair = _players.SingleOrDefault(p => p.Chair == chair);

            if (playerInChair != null)
            {
                TurnOrder.AddToEnd(playerInChair);
            }
        }
Ejemplo n.º 2
0
        private void ChooseStartPlayer()
        {
            var potentialStartPlayers = _players
                                        .Where(p => p.WantsToBeFirstPlayer)
                                        .ToList();

            var player = potentialStartPlayers.Any() ?
                         potentialStartPlayers.ChooseAtRandom() :
                         _players.ChooseAtRandom();

            TurnOrder.SetCheiftan(player);
        }
Ejemplo n.º 3
0
        private bool InitialBoardSetup()
        {
            Phase     = GamePhase.SetUpBoard;
            Board     = new StandardGameBoard();
            TurnOrder = new TurnOrder();

            AssignPlayerSeats();
            AssignPlayerColors();
            PassOutPlayerBoards();

            PrepareNewRound();
            ChooseStartPlayer();

            // TODO: "how to solve call back and setting up the board"
            IsThinking = false;
            Phase      = GamePhase.PlayersPlacePeople;
            return(true);
        }
Ejemplo n.º 4
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));
        }
Ejemplo n.º 5
0
        private bool InitialBoardSetup()
        {
            Phase = GamePhase.SetUpBoard;
            Board = new GameBoard();
            TurnOrder = new TurnOrder();

            AssignPlayerSeats();
            AssignPlayerColors();
            PassOutPlayerBoards();

            PrepareNewRound();
            ChooseStartPlayer();

            // TODO: "how to solve call back and setting up the board"
            IsThinking = false;
            Phase = GamePhase.PlayersPlacePeople;
            return true;
        }
Ejemplo n.º 6
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());
        }
Ejemplo n.º 7
0
        private bool PrepareNewRound()
        {
            var gameOverSignafied = false;

            var cardsForSlots = new Queue <Card>();

            if (Board.CardSlot1 != null)
            {
                cardsForSlots.Enqueue(Board.CardSlot1);
            }
            if (Board.CardSlot2 != null)
            {
                cardsForSlots.Enqueue(Board.CardSlot2);
            }
            if (Board.CardSlot3 != null)
            {
                cardsForSlots.Enqueue(Board.CardSlot3);
            }
            if (Board.CardSlot4 != null)
            {
                cardsForSlots.Enqueue(Board.CardSlot4);
            }

            for (int i = cardsForSlots.Count(); i < 4; i++)
            {
                if (!Board.CardDeck.Any())
                {
                    gameOverSignafied = true;
                    break;
                }
                cardsForSlots.Enqueue(Board.CardDeck.Pop());
            }

            if (!gameOverSignafied)
            {
                Board.CardSlot1 = cardsForSlots.Dequeue();
                Board.CardSlot2 = cardsForSlots.Dequeue();
                Board.CardSlot3 = cardsForSlots.Dequeue();
                Board.CardSlot4 = cardsForSlots.Dequeue();
            }

            Board.HutStack1.FlipTopTile();
            Board.HutStack2.FlipTopTile();
            Board.HutStack3.FlipTopTile();
            Board.HutStack4.FlipTopTile();

            if (Board.HutStack1.IsEmpty ||
                Board.HutStack2.IsEmpty ||
                Board.HutStack3.IsEmpty ||
                Board.HutStack4.IsEmpty)
            {
                return(true);
            }

            TurnOrder.NextCheiftan();

            // TODO: Check once complete as I think this isn't needed
            foreach (var player in _players)
            {
                player.PlayerBoard.PeopleToPlace = player.PlayerBoard.TotalPeople;
            }

            return(gameOverSignafied);
        }