コード例 #1
0
        public void PerformTaskThree()
        {
            string[] inputFile = File.ReadAllLines(Program.filePath);

            int inputFileLength = inputFile.Count();

            if (inputFileLength < 2)
            {
                Console.WriteLine("Task 3: Please choose at least 2 decks.\n");
            }

            else
            {
                var deckNew = new SetDeck();
                IEnumerable <int> RowsThreeSet = Enumerable.Range(0, inputFileLength);
                List <int>        Decks        = new List <int>();

                foreach (int row in RowsThreeSet)
                {
                    Decks.Add(row);
                }

                List <string> DeckCombined = deckNew.GetDeck(Decks);

                if (DeckCombined.Count < 10)
                {
                    Console.WriteLine("Task 3: The deck should consists of minimum 10 cards. \n Please choose the right deck.");
                }

                else
                {
                    Random random     = new Random();
                    var    output     = new List <string>();
                    var    RandomList = new List <int>();


                    for (int cardNum = 0; cardNum < 10; cardNum++)
                    {
                        var currentRandom = random.Next(0, DeckCombined.Count);

                        if (RandomList.Contains(currentRandom))
                        {
                            cardNum--;
                        }
                        else
                        {
                            RandomList.Add(currentRandom);
                        }
                    }

                    foreach (int num in RandomList)
                    {
                        output.Add(DeckCombined[num]);
                    }
                    string outputJoined = string.Join(", ", output);
                    File.WriteAllText(Path.Combine("Files", "3-output.txt"), outputJoined);
                    Console.WriteLine("Task 3: Output was saved to: {0} \n", Path.Combine("Files", "3-output.txt"));
                }
            }
        }
コード例 #2
0
        public void PerformTaskTwo()
        // Reads a file and generates a deck of cards.
        {   // task 2
            var        deckTaskTwo = new SetDeck();
            List <int> rowsTwo     = new List <int> {
                0
            };

            List <string> output       = deckTaskTwo.GetDeck(rowsTwo);
            string        outputJoined = string.Join(", ", output);

            File.WriteAllText(Path.Combine("Files", "2-output.txt"), outputJoined);
            Console.WriteLine("Task 2: Output was saved to: {0} \n", Path.Combine("Files", "2-output.txt"));
        }
コード例 #3
0
ファイル: Taskfour.cs プロジェクト: matemwa/CardGame
        public void PerformTaskFour()
        {
            var        deckNew  = new SetDeck();
            List <int> rowsFour = new List <int> {
                0
            };
            List <string> deck = deckNew.GetDeck(rowsFour);
            string        deckTaskFourJoined = string.Join(", ", deck);

            Random        random      = new Random();
            List <string> GameResults = new List <string>();

            // Pick 2 random unique cards

            for (int gameNumber = 0; gameNumber < 10; gameNumber++)
            {
                int firstCardNum  = random.Next(deck.Count);
                int secondCardNum = random.Next(deck.Count);

                while (secondCardNum == firstCardNum)
                {
                    secondCardNum = random.Next(deck.Count);
                }

                string firstCard  = deck[firstCardNum];
                string secondCard = deck[secondCardNum];
                string handValue  = firstCard + ", " + secondCard + ", ";

                if (firstCard.StartsWith("H"))
                {
                    if (secondCard.StartsWith("H") || secondCard.StartsWith("D") || secondCard.StartsWith("S"))
                    {
                        handValue = handValue + "Win";
                    }

                    else
                    {
                        handValue = handValue + "Loss";
                    }
                    GameResults.Add(handValue);
                }

                else if (firstCard.StartsWith("C"))
                {
                    if (secondCard.StartsWith("H"))
                    {
                        handValue = handValue + "Tie";
                    }

                    else
                    {
                        handValue = handValue + "Loss";
                    }
                    GameResults.Add(handValue);
                }

                else if (firstCard.StartsWith("D") || firstCard.StartsWith("S"))
                {
                    if (secondCard.StartsWith("D") || secondCard.StartsWith("S"))
                    {
                        handValue = handValue + "Tie";
                    }

                    else
                    {
                        if (secondCard.StartsWith("H"))
                        {
                            handValue = handValue + "Win";
                        }
                        else
                        {
                            handValue = handValue + "Loss";
                        }
                    }
                    GameResults.Add(handValue);
                }
            }

            File.WriteAllLines(Path.Combine("Files", "4-output.txt"), GameResults);
            Console.WriteLine("Task 4: Output was saved to: {0} \n", Path.Combine("Files", "4-output.txt"));
        }