Example #1
0
        public static void PassOutCards <P, D>(this IPlayerCollection <P> playerList, ICustomBasicList <D> thisCol, bool noComputerPass) where P : IPlayerObject <D>, new()
            where D : IDeckObject, new()
        {
            playerList.ForEach(items => items.MainHandList.Clear());
            int z = 0;
            int HowMany;

            HowMany = thisCol.Count;
            do
            {
                foreach (var thisPlayer in playerList)
                {
                    if (thisPlayer.PlayerCategory == EnumPlayerCategory.Computer && noComputerPass == true)
                    {
                    }
                    else
                    {
                        thisPlayer.MainHandList.Add(thisCol[z]); //hopefully no problem still (?)
                        z += 1;
                    }

                    if (z == HowMany)
                    {
                        return;
                    }
                }
            }while (true);
        }
Example #2
0
        public IPlayer GetVictoriousPlayer(IPlayerCollection players)
        {
            Guard.AgainstNull(players, nameof(players));
            Guard.AgainstNullOrEmptyEnumerable(players, nameof(players));

            var orderedPlayers = players.OrderByDescending(player => player.Score).ToList();

            if (orderedPlayers[0].Score >= this.minimumVictoryScoreTotal)
            {
                if (orderedPlayers.Count == 1)
                {
                    return(orderedPlayers[0]);
                }

                var scoreDifferential = (orderedPlayers[0].Score - orderedPlayers[1].Score);
                if (this.scoreLeadMustBeExactValue)
                {
                    if (scoreDifferential == this.requiredScoreLead)
                    {
                        return(orderedPlayers[0]);
                    }
                }
                else if (scoreDifferential > this.requiredScoreLead)
                {
                    return(orderedPlayers[0]);
                }
            }

            return(null);
        }
Example #3
0
        public CardGame(CardGameCommands commands, IPlayerCollection players, IDeck deck, IScorer scorer, IVictoryChecker victoryChecker)
        {
            Guard.AgainstNullDataContainer(commands, nameof(commands));
            Guard.AgainstNull(players, nameof(players));
            Guard.AgainstNull(deck, nameof(deck));
            Guard.AgainstNull(scorer, nameof(scorer));
            Guard.AgainstNull(victoryChecker, nameof(victoryChecker));

            this.drawCardsCommandHandler = commands.DrawCardsCommandHandler;
            this.updateScoresCommand     = commands.UpdateScoresCommandHandler;
            this.handleGameEndCommand    = commands.CheckForGameEndCommandHandler;
            this.players        = players;
            this.deck           = deck;
            this.scorer         = scorer;
            this.victoryChecker = victoryChecker;
        }
Example #4
0
        public GameStateService(
            IUniverseCollection universeCollection,
            IWorldCollection worldCollection,
            IAreaCollection areaCollection,
            ISectionCollection sectionCollection,
            IPlayerCollection playerCollection,
            ICharacterCollection characterCollection,
            IBattleCollection battleCollection,
            ILogService logService,
            IHubService hubService)
        {
            UniverseCollection  = universeCollection;
            WorldCollection     = worldCollection;
            AreaCollection      = areaCollection;
            SectionCollection   = sectionCollection;
            PlayerCollection    = playerCollection;
            CharacterCollection = characterCollection;
            BattleCollection    = battleCollection;

            this.logService = logService;
            this.hubService = hubService;
        }
Example #5
0
        public static void PassOutCards <P, D>(this IPlayerCollection <P> playerList, ICustomBasicList <D> thisCol
                                               , int howMany, int testCount, bool noComputerPass, ref DeckRegularDict <D> leftOverList) where P : IPlayerObject <D>, new()
            where D : IDeckObject, new()
        {
            int players;

            players = playerList.Count();
            if (noComputerPass == true)
            {
                int subs = playerList.Count(Items => Items.PlayerCategory == EnumPlayerCategory.Computer);
                players -= subs;
            }
            int newcount;

            newcount  = players * howMany;
            newcount -= testCount; //because less is being dealt out.
            if (newcount > thisCol.Count)
            {
                throw new BasicBlankException("There needs to be at least " + newcount + " cards.  However, there are only " + thisCol.Count + " cards to pass out");
            }
            int x;

            if (newcount == thisCol.Count)
            {
                leftOverList = new DeckRegularDict <D>();
            }
            else
            {
                var loopTo = thisCol.Count;
                if (leftOverList == null)
                {
                    leftOverList = new DeckRegularDict <D>();
                }
                for (x = newcount + 1; x <= loopTo; x++)
                {
                    leftOverList.Add(thisCol[x - 1]);// because 0 based
                }
            }
            int y;

            y = 0;
            CustomBasicList <CustomBasicList <D> > thisList = new CustomBasicList <CustomBasicList <D> >();

            foreach (var newPlayer in playerList)
            {
                CustomBasicList <D> temps = new CustomBasicList <D>();
                temps.AddRange(newPlayer.StartUpList);
                thisList.Add(temps);
            }

            int z;
            var loopTo1 = howMany;

            for (x = 1; x <= loopTo1; x++)
            {
                z = 0;
                foreach (var newPlayer in playerList)
                {
                    if (newPlayer.PlayerCategory == EnumPlayerCategory.Computer && noComputerPass == true)
                    {
                    }
                    else
                    {
                        if (newPlayer.StartUpList.Count == 0)
                        {
                            var TempList = thisList[z];
                            TempList.Add(thisCol[y]);
                            y += 1;
                        }
                        else
                        {
                            newPlayer.StartUpList.RemoveFirstItem(); //i think because the card is implied being added.
                        }
                    }
                    z += 1;
                }
            }
            z = 0;
            foreach (var newPlayer in playerList)
            {
                if (newPlayer.PlayerCategory == EnumPlayerCategory.Computer && noComputerPass == true)
                {
                }
                else
                {
                    newPlayer.MainHandList.ReplaceRange(thisList[z]); // i think
                }
                z += 1;                                               //this could be it.
            }
        }
Example #6
0
        public void SetPlayers(IPlayerCollection players)
        {
            Guard.AgainstNull(players, nameof(players));

            this.players = players;
        }