コード例 #1
0
ファイル: Program.cs プロジェクト: kunger47/clue-buddy
        // Making Deductions
        public static void MakeDeductions(Game game)
        {
            DisplayInfo($"Looking for more Deductions...");
            var wasDeductionMade = false;

            foreach (Player player in game.Players.Where(p => p.Cards.Any(c => c.Status == CardStatus.Maybe || c.Status == CardStatus.Unknown)))
            {
                wasDeductionMade = wasDeductionMade || CheckIfPlayerHasAllTheirCards(player);
            }

            foreach (Round round in game.Rounds.Where(r => !r.Solved && r.Shower.Type != PlayerType.Player))
            {
                CheckForSolvedRounds(round);
                wasDeductionMade = wasDeductionMade || CheckRoundForDeduction(game.Players, round);
            }

            foreach (Card card in Lists.Cards())
            {
                wasDeductionMade = wasDeductionMade || CheckIfOnlyOnePlayerCanHaveCard(game.Players, card);
            }

            wasDeductionMade = wasDeductionMade || CheckIfCaseFileHasDeductions(game.Players);

            if (wasDeductionMade)
            {
                MakeDeductions(game);
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: kunger47/clue-buddy
        private static List <Player> GetPlayers(int numberOfPlayers)
        {
            List <Player> addPlayers      = new List <Player>();
            var           totalNumOfCards = 3;

            for (int i = 0; i < numberOfPlayers; i++)
            {
                var playerType = PlayerType.Opponent;
                if (i == 0)
                {
                    OutputToConsoleWithWait($"\nDetective, what is your name?");
                    playerType = PlayerType.Player;
                }
                else if (i == 1)
                {
                    OutputToConsoleWithWait($"\nGoing to your left, enter the name of detective #{ i + 1 }");
                }
                else
                {
                    OutputToConsoleWithWait($"\nGoing to their left, enter the name of detective #{ i + 1 }");
                }

                string playerName = ValidateNewPlayerNameLength(addPlayers);

                if (i == 0)
                {
                    OutputToConsoleWithWait($"How many cards are in your hand (2 to 10)?");
                }
                else
                {
                    OutputToConsoleWithWait($"How many cards are in their hand (2 to 10)?");
                }

                int numberOfCards = GetNumber(2, 9);
                totalNumOfCards += numberOfCards;

                addPlayers.Add(new Player
                {
                    Id    = i + 1,
                    Name  = playerName,
                    Cards = new List <Card>(Lists.Cards().Select(c => new Card {
                        Id = c.Id, Name = c.Name, Type = c.Type
                    }).ToList()),
                    NumberOfCards = numberOfCards,
                    Type          = playerType
                });
            }

            if (totalNumOfCards != 30)
            {
                DisplayError($"Uh oh by my calculations, that was not enough cards, you may want to restart?");
            }

            return(addPlayers);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: kunger47/clue-buddy
        private static string GetCardName(CardType?type = null)
        {
            var cardName = Console.ReadLine();

            while (!Lists.Cards().Any(c => c.Name == cardName && (type != null ? c.Type == type : true)))
            {
                var cardType = type != null?type.ToString() : "card";

                DisplayError($"That is not a valid {cardType} name, try again");
                cardName = Console.ReadLine();
            }
            return(cardName);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: kunger47/clue-buddy
        private static void AddCaseFile(Game game)
        {
            OutputToConsoleWithWait($"Building the Case File...\n", 1000);

            var CaseFile = new Player
            {
                Id    = 0,
                Name  = "Case File",
                Cards = new List <Card>(Lists.Cards().Select(c => new Card {
                    Id = c.Id, Name = c.Name, Type = c.Type
                }).ToList()),
                NumberOfCards = 3,
                Type          = PlayerType.CaseFile
            };

            game.Players.AddRange(new List <Player> {
                CaseFile
            });
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: kunger47/clue-buddy
        // Helpers
        private static void CardDiscovery(List <Player> players, string playerName, string cardName)
        {
            players
            .Where(p => p.Name == playerName)
            .First().Cards
            .Where(c => c.Name == cardName)
            .FirstOrDefault().Status = CardStatus.Yes;

            players
            .Where(p => p.Name != playerName)
            .SelectMany(p => p.Cards)
            .Where(c => c.Name == cardName)
            .All(c => { c.Status = CardStatus.No; return(true); });

            if (playerName == players.Where(p => p.Type == PlayerType.CaseFile).First().Name)
            {
                var type = Lists.Cards().Where(c => c.Name == cardName).First().Type;

                players.Where(p => p.Type == PlayerType.CaseFile).First().Cards
                .Where(c => c.Status != CardStatus.Yes && c.Type == type)
                .All(c => { c.Status = CardStatus.No; return(true); });
            }
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: kunger47/clue-buddy
        // Display Game Data
        private static void DisplayWhatIKnow(Game game)
        {
            Console.ForegroundColor = ConsoleColor.DarkGreen;
            Console.WriteLine($"-------------------------------------------------------------------------------------------------\n");
            Console.WriteLine($"-----------------------          Electronic Detective Notebook          -------------------------\n");
            Console.WriteLine($"-------------------------------------------------------------------------------------------------\n");
            Console.ForegroundColor = ConsoleColor.White;
            Console.Write($"{"",-15}");
            foreach (var player in game.Players)
            {
                Console.Write($"{player.Name,-10}");
            }

            var cardType = CardType.Suspect;

            foreach (var card in Lists.Cards())
            {
                if (cardType != card.Type)
                {
                    Console.WriteLine($"\n-------------------------------------------------------------------------------------------------\n");
                    cardType = card.Type;
                }
                else
                {
                    Console.WriteLine();
                }

                Console.Write($"{card.Name,-15}");
                foreach (var player in game.Players)
                {
                    var cardStatus       = player.Cards.Where(c => c.Name == card.Name).First().Status;
                    var cardStatusSymbol = "";
                    var color            = ConsoleColor.White;
                    switch (cardStatus)
                    {
                    case CardStatus.Unknown:
                        cardStatusSymbol = "[ ]";
                        break;

                    case CardStatus.Maybe:
                        var roundsInQuestion = game.Rounds
                                               .Where(r => !r.Solved)
                                               .Where(r => r.Shower.Name == player.Name)
                                               .Where(r => r.Suspect == card.Name || r.Weapon == card.Name || r.Room == card.Name)
                                               .Select(r => r.Number);
                        var listOfRounds = string.Join($",", roundsInQuestion.Select(n => n.ToString()).ToArray());
                        if (listOfRounds == "")
                        {
                            listOfRounds = " ";
                        }
                        cardStatusSymbol += $"[{listOfRounds}]";
                        color             = ConsoleColor.DarkYellow;
                        break;

                    case CardStatus.No:
                        cardStatusSymbol = "[X]";
                        color            = ConsoleColor.DarkRed;
                        break;

                    case CardStatus.Yes:
                        cardStatusSymbol = "[\u25A0]";
                        color            = ConsoleColor.DarkGreen;
                        break;

                    default:
                        cardStatusSymbol = "Error";
                        color            = ConsoleColor.Red;
                        break;
                    }
                    Console.ForegroundColor = color;
                    Console.Write($"{cardStatusSymbol,-10}");
                    Console.ForegroundColor = ConsoleColor.White;
                }
            }
        }