예제 #1
0
        public Task <GameState> Handle(BuildNothingCommand request, CancellationToken cancellationToken)
        {
            var board = request.BoardState;

            if (board.GamePhase != BoardState.Phase.Build)
            {
                throw new InvalidOperationException(request.ToString());
            }

            if (board.PlayerTurn == board.Players.Count)
            {
                var gameEnd = board.NewRound();
                if (gameEnd)
                {
                    return(gameEndGetter.Process(board));
                }
                else
                {
                    return(colonistPickGetter.Process(board));
                }
            }
            else
            {
                board.PlayerTurn++;
                board.GamePhase = BoardState.Phase.Draw;
                return(drawGetter.Process(board));
            }
        }
예제 #2
0
        public Task <GameState> Handle(BuildModuleCommand request, CancellationToken cancellationToken)
        {
            var board = request.BoardState;

            if (board.GamePhase != BoardState.Phase.Build)
            {
                throw new InvalidOperationException(request.ToString());
            }

            var player = board.Players[board.PlayerTurn - 1];
            var module = player.Hand.FirstOrDefault(m => m.Name == request.Module);

            if (module is null)
            {
                throw new InvalidOperationException($"The given module is not in the player's hand: {request}");
            }
            if (player.Omnium < module.BuildCost)
            {
                throw new InvalidOperationException($"Not enough omnium to build module: {request}");
            }

            player.Omnium -= module.BuildCost;
            player.Hand.Remove(module);
            player.Colony.Add(module);

            if (board.PlayerTurn == board.Players.Count)
            {
                var gameEnd = board.NewRound();
                if (gameEnd)
                {
                    return(gameEndGetter.Process(board));
                }
                else
                {
                    return(colonistPickGetter.Process(board));
                }
            }
            else
            {
                board.PlayerTurn++;
                board.GamePhase = BoardState.Phase.Draw;
                return(drawGetter.Process(board));
            }
        }
예제 #3
0
        public Task<GameState> Handle(ColonistPickCommand request, CancellationToken cancellationToken)
        {
            var board = request.BoardState;
            var player = board.Players[board.PlayerTurn - 1];
            if (board.GamePhase != BoardState.Phase.ColonistPick) throw new InvalidOperationException(request.ToString());

            // information about previous players' colonists
            for (int i = 1; i < player.ID; i++)
            {
                player.ColonistInformation[i] = board.PlayableColonists.Where(c => !board.AvailableColonists.Any(x => x.Name == c.Name)).ToList();
            }

            // pick colonist and remove him from available
            player.Colonist = board.AvailableColonists.Single(c => c.Name == request.Colonist);
            board.AvailableColonists.Remove(player.Colonist);

            // player knows his own colonist
            player.ColonistInformation[player.ID] = new List<Colonist> { player.Colonist };
            // information about following players' colonists
            for (int i = player.ID + 1; i <= GameConstants.PlayerCount; i++)
            {
                player.ColonistInformation[i] = new List<Colonist>(board.AvailableColonists);
            }

            if (board.PlayerTurn == board.Players.Count) // Move to next phase
            {
                board.PlayerTurn = 1;
                board.GamePhase++;
                return drawGetter.Process(board);
            }
            else
            {
                board.PlayerTurn++;
                return colonistPickGetter.Process(board);
            }
        }