public GameSaver(IMapElementMapConverter mapElementMapConverter, IPlayerFinder playerFinder, IMapper mapper, IUpdateService <Player> updateService)
 {
     _mapElementMapConverter = mapElementMapConverter;
     _playerFinder           = playerFinder;
     _mapper        = mapper;
     _updateService = updateService;
 }
Beispiel #2
0
        public void Setup()
        {
            _mapper           = new Mapper(new MapperConfiguration(cfg => { cfg.CreateMap <Player, PlayerDto>(); }));
            _mockedRepository = new Mock <IRepository <Player> >();
            _mockedUnitOfWork = new Mock <IUnitOfWork>();

            _players = new List <Player>()
            {
                new Player()
                {
                    Id          = Guid.NewGuid(),
                    CreatedDate = DateTime.Now,
                    Name        = "Jani",
                    Password    = "******",
                },
                new Player()
                {
                    Id          = Guid.NewGuid(),
                    CreatedDate = DateTime.Now,
                    Name        = "Hanka",
                    Password    = "******",
                },
            };

            _mockedRepository.Setup(x => x.GetAll()).Returns(_players.AsEnumerable);
            _mockedRepository.Setup(x => x.GetById(It.IsAny <Guid>())).Returns(_players.First);
            _mockedUnitOfWork.Setup(x => x.PlayerRepository).Returns(_mockedRepository.Object);

            _playerFinder = new PlayerFinder(_mockedUnitOfWork.Object, _mapper);
        }
Beispiel #3
0
        public override void PlayTurn(IPlayerFinder playerFinder)
        {
            base.PlayTurn(playerFinder);
            Thread.Sleep(ChoiceDelay);
            var card = Hand.ElementAt(random.Next(1));

            Play(card, playerFinder);
        }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="finder"></param>
 public BucketTeamChooser( IPlayerFinder finder )
 {
     if ( finder != null )
         Finder = finder;
     else
     {
         Finder = new SimplePlayerFinder();
     }
 }
Beispiel #5
0
 public LoginViewModel(IPlayerFinder playerFinder, IPasswordChecker passwordChecker)
 {
     _playerFinder           = playerFinder;
     _passwordChecker        = passwordChecker;
     LoginCommand            = new ParameterizedRelayCommand(Login, IsLoginEnabled);
     OpenSignUpWindowCommand = new RelayCommand(OpenSignUpWindow);
     CloseAppCommand         = new RelayCommand(() => Application.Current.Shutdown());
     InitializePlayers();
     Messenger.Default.Register <NotificationMessage <PlayerDto> >(this, x => Application.Current.Dispatcher.Invoke(() => Players.Add(x.Content)));
 }
Beispiel #6
0
 protected void Play(Card card, IPlayerFinder playerFinder)
 {
     Hand.Remove(card);
     Console.WriteLine($"Player {Number} played {card.Name}");
     card.DoAction(this, playerFinder);
     if (card.Is("princess"))
     {
         OutOfRound();
     }
 }
Beispiel #7
0
 public EnhanceModule(
     IRunEventConverter runEventConverter,
     IPlayerFinder playerFinder,
     INbtLevelConverter nbtLevel,
     INbtPlayerConverter nbtPlayer)
 {
     _runEventConverter = runEventConverter;
     _playerFinder      = playerFinder;
     _nbtLevel          = nbtLevel;
     _nbtPlayer         = nbtPlayer;
 }
Beispiel #8
0
        public override void DoAction(Player currentPlayer, IPlayerFinder playerFinder)
        {
            base.DoAction(currentPlayer, playerFinder);
            var player = ChoosePlayer(currentPlayer, playerFinder);

            if (player == null)
            {
                return;
            }
            currentPlayer.TradeHands(player);
        }
Beispiel #9
0
        public override void DoAction(Player currentPlayer, IPlayerFinder playerFinder)
        {
            base.DoAction(currentPlayer, playerFinder);
            var chosenPlayer = ChoosePlayer(currentPlayer, playerFinder);

            if (chosenPlayer == null)
            {
                return;
            }
            CompareHands(chosenPlayer, currentPlayer);
        }
Beispiel #10
0
        public override void DoAction(Player currentPlayer, IPlayerFinder playerFinder)
        {
            base.DoAction(currentPlayer, playerFinder);
            var player = ChoosePlayer(currentPlayer, playerFinder);

            if (player == null)
            {
                return;
            }
            player.Discard(player.FirstCard());
            listener.DealCard(player);
        }
Beispiel #11
0
        public override void DoAction(Player currentPlayer, IPlayerFinder playerFinder)
        {
            base.DoAction(currentPlayer, playerFinder);
            var player = ChoosePlayer(currentPlayer, playerFinder);

            if (player == null)
            {
                return;
            }
            var card = ChooseCard(currentPlayer);

            DoGuardAction(player, card);
        }
Beispiel #12
0
 protected static Player ChoosePlayer(Player currentPlayer, IPlayerFinder playerFinder)
 {
     if (!playerFinder.ValidPlayersAvailable(currentPlayer))
     {
         return(NoValidPlayers());
     }
     while (true)
     {
         var chosenPlayerNumber = currentPlayer.ChoosePlayer();
         var chosenPlayer       = playerFinder.PlayerAt(chosenPlayerNumber - 1);
         if (!IsValidPlayer(chosenPlayer, currentPlayer))
         {
             continue;
         }
         return(chosenPlayer);
     }
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="divider"></param>
        /// <param name="finder"></param>
        public SimpleTeamChooser( ITeamDivider divider, IPlayerFinder finder )
        {
            if ( divider != null )
                Divider = divider;
            else
            {
                //Create a default team divider
                Divider = new SimpleTeamDivider();
            }

            if ( finder != null )
                Finder = finder;
            else
            {
                //Create a default player finder
                Finder = new SimplePlayerFinder();
            }
        }
Beispiel #14
0
        public override void PlayTurn(IPlayerFinder playerFinder)
        {
            base.PlayTurn(playerFinder);
            Console.WriteLine("Your hand: \n");
            PrintHand();
            Card playCard = null;

            if (HasCard("countess") && (HasCard("king") || HasCard("prince")))
            {
                playCard = GetCardFromHand("countess");
            }
            while (playCard == null)
            {
                var cardChoice = ChooseCard();
                playCard = GetCardFromHand(cardChoice);
            }
            Play(playCard, playerFinder);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="divider"></param>
        /// <param name="finder"></param>
        public SeededTeamChooser( ITeamDivider divider, IPlayerFinder finder )
        {
            MaxElo = 2800;
            MinElo = 0;

            if ( divider != null )
                Divider = divider;
            else
            {
                //Create a default team divider
                Divider = new SimpleTeamDivider();
            }

            if ( finder != null )
                Finder = finder;
            else
            {
                //Create a default player finder
                Finder = new SimplePlayerFinder();
            }
        }
Beispiel #16
0
 public virtual void DoAction(Player currentPlayer, IPlayerFinder playerFinder)
 {
     Print();
 }
Beispiel #17
0
 public PlayerFinderStatsDecorator(IPlayerFinder component)
 => _component = component;
        /// <summary>
        /// Choose teams based upon placement into Elo buckets
        /// </summary>
        /// <param name="players"></param>
        /// <param name="finder"></param>
        /// <param name="seed"></param>
        /// <param name="playersPerTeam"></param>
        /// <param name="eloRange"></param>
        /// <returns></returns>
        private Tuple<Team, Team> chooseTeams( List<Player> players, IPlayerFinder finder, Player seed, int playersPerTeam, int eloRange )
        {
            //Find possible players
            List<Player> possible = finder.FindPlayers( players, seed.GetElo(), eloRange );

            //Add seed to possible players if not already present
            if ( !possible.Contains( seed ) )
                possible.Add( seed );

            //Check if there are enough players
            if ( possible.Count >= 2 * playersPerTeam )
            {
                //Remove seed from list of possible players
                possible.Remove( seed );

                //Bucket players into teams
                return bucketPlayers( possible, playersPerTeam, seed );
            }

            //Return a tuple of EmptyTeams since we don't have enough players for two Teams
            return new Tuple<Team, Team>( new EmptyTeam(), new EmptyTeam() );
        }
 public PlayerFinderEndScreenDecorator(IPlayerFinder component)
 => _component = component;
Beispiel #20
0
 public virtual void PlayTurn(IPlayerFinder playerFinder)
 {
     Vulnerable = true;
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="players"></param>
        /// <param name="divider"></param>
        /// <param name="finder"></param>
        /// <param name="seed"></param>
        /// <param name="playersPerTeam"></param>
        /// <param name="eloRange"></param>
        /// <param name="maxElo"></param>
        /// <param name="minElo"></param>
        /// <returns></returns>
        private Tuple<Team, Team> chooseTeams( List<Player> players, ITeamDivider divider, IPlayerFinder finder, Player seed, int playersPerTeam, int eloRange, int maxElo, int minElo )
        {
            int max = 0;
            int min = 0;

            //Check if the range of Elos to check hits the max
            if ( seed.GetElo() + eloRange / 2 > maxElo )
            {
                //Set max to maxElo
                max = maxElo;
                //Set min
                min = seed.GetElo() - (eloRange / 2) - (maxElo - seed.GetElo());
            }
            else
            {
                //Check if the range of Elos to check hits the min
                if ( seed.GetElo() - eloRange / 2 < minElo )
                {
                    //Set min to minElo
                    min = minElo;
                    //Set max
                    max = seed.GetElo() + (eloRange / 2) + (seed.GetElo() - minElo);
                }
                else
                {
                    //Set max
                    max = seed.GetElo() + eloRange / 2;
                    //Set min
                    min = seed.GetElo() - eloRange / 2;
                }
            }

            //Get possible players
            List<Player> possible = finder.FindPlayers( players, max, max - min );

            //Add seed to list of possible players
            if ( !possible.Contains( seed ) )
            {
                possible.Add( seed );
            }

            //Check if there are enough players to make a match
            if ( possible.Count >= 2 * playersPerTeam )
            {
                //Enough players
                possible.Remove( seed );

                //Divide the players into two teams
                return divider.DividePlayers( possible, playersPerTeam, seed );
            }
            else
            {
                //Not enough players, expand the Elo range
                if ( eloRange < maxElo - minElo )
                    return chooseTeams( players, divider, finder, seed, playersPerTeam, eloRange * 2, maxElo, minElo );
            }

            //Return a tuple of EmptyTeams because we never got enough players together
            return new Tuple<Team, Team>( new EmptyTeam(), new EmptyTeam() );
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="players"></param>
        /// <param name="finder"></param>
        /// <param name="divider"></param>
        /// <param name="seed"></param>
        /// <param name="playersPerTeam"></param>
        /// <param name="eloRange"></param>
        /// <returns></returns>
        private Tuple<Team, Team> chooseTeams( List<Player> players, IPlayerFinder finder, ITeamDivider divider, Player seed, int playersPerTeam, int eloRange )
        {
            List<Player> possible = finder.FindPlayers( players, seed.GetElo(), eloRange );

            if ( !possible.Contains( seed ) )
            {
                possible.Add( seed );
            }

            if ( possible.Count >= 2 * playersPerTeam )
            {
                possible.Remove( seed );

                return divider.DividePlayers( possible, playersPerTeam, seed );
            }

            //Return a tuple of EmptyTeams because we never got enough players together
            return new Tuple<Team, Team>( new EmptyTeam(), new EmptyTeam() );
        }
Beispiel #23
0
 public override void DoAction(Player currentPlayer, IPlayerFinder playerFinder)
 {
     base.DoAction(currentPlayer, playerFinder);
     currentPlayer.Vulnerable = false;
 }
 public PlayerFinderAchievementDecorator(IPlayerFinder component)
 => _component = component;