Пример #1
0
        public override void Execute(Game game)
        {
            LobbyState state = game.State as LobbyState;

            if (state == null)
            {
                throw new CommandException();
            }
            Player sender = game.GetPlayerByUserId(SenderUserId);

            if (sender == null)
            {
                throw new CommandException();
            }
            if (!sender.IsOwner)
            {
                throw new CommandException();
            }
            if (game.Players.Count != Constants.MinPlayerCount)
            {
                throw new CommandException();
            }

            bool canPlayersUseBattleKingCard = game.Players.All(p => p.Deck.BattleKingCard.Card.Effect != GwintEffect.CounterKing);

            foreach (var player in game.Players)
            {
                player.DeckCards.AddRange(player.Deck.Cards.Select(c => c.ToPlayerCard()));
                player.CanUseBattleKingCard = canPlayersUseBattleKingCard;
                player.BattleKingCard       = player.Deck.BattleKingCard.ToPlayerCard();
                player.Faction = player.Deck.Faction;
                player.Lives   = Constants.InitialLifeCount;
            }

            if (game.Players.Any(p => p.Deck.Faction == GwintFaction.Scoiatael))
            {
                NextState = new PickStartingPlayerState();
            }
            else
            {
                var startingPlayer = game.Players.OrderBy(p => new Guid()).First();
                startingPlayer.IsRoundStarter = true;
                Events.Add(new CoinTossEvent(game.GetAllUserIds())
                {
                    StartingPlayerId = startingPlayer.User.Id
                });
                NextState = new RedrawState();
            }
        }
Пример #2
0
 private void DetermineStartingPlayer(Game game, PickStartingPlayerState state)
 {
     if (state.Substates.All(s => !s.CanPickStartingPlayer || s.StartingPlayerUserId == StartingPlayerUserId))
     {
         var startingPlayer = game.GetPlayerByUserId(StartingPlayerUserId);
         startingPlayer.IsRoundStarter = true;
     }
     else
     {
         var startingPlayer = game.Players.OrderBy(p => new Guid()).First();
         startingPlayer.IsRoundStarter = true;
         Events.Add(new CoinTossEvent(game.GetAllUserIds())
         {
             StartingPlayerId = startingPlayer.User.Id
         });
     }
 }
Пример #3
0
        public void InitializePickStartingPlayerWithTwoScoiataelDecks()
        {
            var player1 = new Player
            {
                User = new User
                {
                    Id = 1
                },
                Deck = new Deck
                {
                    Faction = GwintFaction.Scoiatael
                }
            };
            var player2 = new Player
            {
                User = new User
                {
                    Id = 2
                },
                Deck = new Deck
                {
                    Faction = GwintFaction.Scoiatael
                }
            };
            var game = new Game
            {
                Players = new List <Player>
                {
                    player1,
                    player2,
                }
            };
            var state = new PickStartingPlayerState();

            var events = state.Initialize(game).ToList();

            Assert.Empty(events);
            Assert.True(player1.IsTurn);
            Assert.True(player2.IsTurn);
            Assert.Contains(state.Substates, s => s.UserId == 1 && s.StartingPlayerUserId == null && s.CanPickStartingPlayer);
            Assert.Contains(state.Substates, s => s.UserId == 2 && s.StartingPlayerUserId == null && s.CanPickStartingPlayer);
        }
Пример #4
0
        public override void Execute(Game game)
        {
            PickStartingPlayerState state = game.State as PickStartingPlayerState;

            if (state == null)
            {
                throw new CommandException();
            }

            Player sender = game.GetPlayerByUserId(SenderUserId);

            if (sender == null)
            {
                throw new CommandException();
            }

            var substate = state.Substates.First(s => s.UserId == SenderUserId);

            if (substate == null || !substate.CanPickStartingPlayer || substate.StartingPlayerUserId.HasValue)
            {
                throw new CommandException();
            }

            if (!game.GetAllUserIds().Contains(StartingPlayerUserId))
            {
                throw new CommandException();
            }

            substate.StartingPlayerUserId = StartingPlayerUserId;
            sender.IsTurn = false;

            if (state.Substates.Any(s => s.CanPickStartingPlayer && !s.StartingPlayerUserId.HasValue))
            {
                return;
            }

            DetermineStartingPlayer(game, state);
            NextState = new RedrawState();
        }