public PlayingCardGame()
        {
            Console.OutputEncoding = Encoding.UTF8;
            List <PlayingCard> deck = PlayingCardDeck.NewDeck();

            PlayingCardDeck.Shuffle(deck);
            PlayingCard PlayerCard   = PlayingCardDeck.TopCard(deck);
            PlayingCard ComputerCard = PlayingCardDeck.TopCard(deck);

            Console.Write("Your card: ");
            DisplayCard(PlayerCard);
            string guess = GuessIfCardIsHigherOrLower();
            bool   win   = CompareCards(PlayerCard, ComputerCard, guess);

            Console.Write("Computer card: ");
            DisplayCard(ComputerCard);
            if (win)
            {
                Console.WriteLine("You Win");
            }
            if (!win)
            {
                Console.WriteLine("You Loose");
            }
        }
Пример #2
0
        private int CompareCards(PlayingCardDeck playingCardDeck, List <PlayingCard> cards, PlayingCard firstCard, string answer, int score)
        {
            PlayingCard secondCard = playingCardDeck.PickFirstCardFromDeck(cards);

            Console.Write($"The second card is {secondCard.Suit} {secondCard.Value}, ");
            cards.Remove(secondCard);

            switch (answer)
            {
            case "l":
                if (firstCard.Value > secondCard.Value)
                {
                    WriteGreen("your answer was correct!\n");
                    score++;
                    Console.ReadKey();
                    Console.Clear();
                }
                else if (firstCard.Value == secondCard.Value)
                {
                    WriteGreen("the cards have the same value!\n");
                    Console.ReadKey();
                    Console.Clear();
                }
                else
                {
                    WriteRed("your answer was wrong!\n");
                    Console.ReadKey();
                    Console.Clear();
                }
                break;

            case "h":
                if (firstCard.Value < secondCard.Value)
                {
                    WriteGreen("your answer was correct!\n");
                    score++;
                    Console.ReadKey();
                    Console.Clear();
                }
                else if (firstCard.Value == secondCard.Value)
                {
                    WriteGreen("the cards have the same value!\n");
                    Console.ReadKey();
                    Console.Clear();
                }
                else
                {
                    WriteRed("your answer was wrong!\n");
                    Console.ReadKey();
                    Console.Clear();
                }
                break;

            default:
                break;
            }

            return(score);
        }
Пример #3
0
        private static void Test3()
        {
            var deck = new PlayingCardDeck();

            deck.AddSomeCards();

            deck.PrintNumberOfCards();
        }
Пример #4
0
 private void ShuffleDeck(PlayingCardDeck deck, int shuffleCount)
 {
     deck.Shuffle(shuffleCount);
     foreach (var card in deck.Cards)
     {
         PlayingCard cardP = (PlayingCard)card;
         PrintMessage("Your card name: " + cardP.Name + " Type: " + cardP.CardType);
     }
 }
Пример #5
0
        private static void Test4()
        {
            var deck = new PlayingCardDeck();

            deck.AddSomeCards();

            int nr = deck.GetNumberOfCards();

            Console.WriteLine($"Antal kort i kortleken är {nr}");
        }
Пример #6
0
        private PlayingCard PlayCard(PlayingCardDeck deck)
        {
            if (deck.Cards.Count == 0)
            {
                return(null);
            }
            var card = deck.Cards[deck.Cards.Count - 1];

            deck.Cards.RemoveAt(deck.Cards.Count - 1);
            return((PlayingCard)card);
        }
Пример #7
0
        static void Main(string[] args)
        {
            PlayingCardDeck deck = new PlayingCardDeck();

            Console.WriteLine(deck);

            //Console.WriteLine("1. Spela ett parti");
            //Console.WriteLine("2. Visa spelregler");
            //Console.WriteLine("3. Visa highscores");
            //Console.WriteLine("4. Avsluta spelet");
        }
Пример #8
0
        public override void PlayGame()
        {
            int             numberOfCards = _cardDeck.Cards.Count;
            PlayingCardDeck cardDeck      = (PlayingCardDeck)_cardDeck;

            ShuffleDeck(cardDeck, _shuffleCount);
            while (cardDeck.Cards.Count > 0)
            {
                PrintMessage("Enter your choice");
                PrintMessage("p: play the game");
                PrintMessage("r: restart the game");
                PrintMessage("s: shuffle the deck");

                var ch = ReadInput();
                switch (ch)
                {
                case "p":
                    var card = PlayCard(cardDeck);
                    if (card == null)
                    {
                        PrintMessage("Deck is empty");
                    }
                    PrintMessage("Your card name: " + card.Name + " Type: " + card.CardType);
                    break;

                case "s":
                    ShuffleDeck(cardDeck, _shuffleCount);
                    break;

                case "r":
                    RestartGame(cardDeck, numberOfCards);
                    break;
                }
            }
            PrintMessage("Deck is Empty. Thank you for playing!!");
        }
Пример #9
0
 public ShuffleGame(int shuffleCount, PlayingCardDeck deck) : base(deck)
 {
     _shuffleCount = shuffleCount;
 }
Пример #10
0
 private void RestartGame(PlayingCardDeck deck, int numberOfCards)
 {
     deck.IntializeDeck(numberOfCards);
 }
Пример #11
0
        public void PlayGame()
        {
            Console.Clear();

            string userName = AskUserForName();

            WelcomeUser(userName);
            int score        = 0;
            int roundCounter = 0;


            //Skapar en ny kortlek
            PlayingCardDeck    playingCardDeck = new PlayingCardDeck();
            List <PlayingCard> cards           = playingCardDeck.CreateDeck();

            playingCardDeck.Shuffle(cards); //Har nu skapat en kortlek med randomiserad ordning i

            Console.Clear();
            while (cards.Count >= 2)
            {
                PrintInstructions("\nWrite 'h' for higher and 'l' for lower. Write 'exit' to go back to main menu ");

                PlayingCard firstCard = playingCardDeck.PickFirstCardFromDeck(cards);

                Console.WriteLine($"\nThe card is {firstCard.Suit} {firstCard.Value}");
                cards.Remove(firstCard);

                string input = "";

                Console.Write("Do you think the next card will be higher or lower? ");

                while (true)
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                    input = Console.ReadLine();
                    Console.ResetColor();

                    if (input.ToLower() == "l" || input.ToLower() == "h")
                    {
                        score = CompareCards(playingCardDeck, cards, firstCard, input, score);
                        roundCounter++;
                        break;
                    }
                    else if (input.ToLower() == "exit")
                    {
                        break;
                    }
                    else
                    {
                        Console.Write("I didn't quite get that. Please write 'h' or 'l': ");
                        continue;
                    }
                }

                if (input.ToLower() == "exit")
                {
                    break;
                }

                if (roundCounter == 10)
                {
                    WriteGreen("\nThe round is over!\n");
                    break;
                }
            }

            double percent = CalculatePercent(score, roundCounter);

            EndGame(userName, percent);
        }
Пример #12
0
 private void SetUpNewDeck()
 {
     Deck = new PlayingCardDeck(true);
     Deck.ShuffleDeck();
 }