コード例 #1
0
ファイル: CardGameConsole.cs プロジェクト: Sonkerud/CardGame
        public static void StartGame(PlayingCardGame game)
        {
            while (true)
            {
                Console.Clear();
                Console.WriteLine("---Cardgame 2032----");
                Console.WriteLine("1. Play Game");
                Console.WriteLine("2. Show Highscore");
                Console.WriteLine("3. Show rules");
                Console.WriteLine("4. Play Game\n");

                ConsoleKeyInfo key = new ConsoleKeyInfo();
                key = Console.ReadKey(true);
                switch (key.Key)
                {
                case ConsoleKey.D1:
                    PlayGame(game);
                    break;

                case ConsoleKey.D2:
                    DisplayHighScore(game);
                    Console.ReadKey();
                    break;

                case ConsoleKey.D3:
                    DisplayRules();
                    Console.ReadLine();
                    break;

                default:
                    break;
                }
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: prawniie/CardGame
        static void Main(string[] args)
        {
            PlayingCardGame game = new PlayingCardGame();

            game.Menu();

            Console.ReadLine();
        }
コード例 #3
0
ファイル: CardGameConsole.cs プロジェクト: Sonkerud/CardGame
 public static void AddPlayersToGame(PlayingCardGame game)
 {
     for (int i = 0; i < 2; i++)
     {
         Console.WriteLine($"Input player {i + 1} name:");
         string playerName = Console.ReadLine();
         game.AddPlayers(playerName);
     }
 }
コード例 #4
0
ファイル: CardGameConsole.cs プロジェクト: Sonkerud/CardGame
        public static void DisplayHighScore(PlayingCardGame game)
        {
            Console.Clear();
            var highscoreList = game.service.HighscoreList();

            Console.WriteLine("Highscore:");
            Console.WriteLine();
            for (int i = 0; i < highscoreList.Count(); i++)
            {
                Console.WriteLine($"{i+1}. {highscoreList[i].Name} Wins: {highscoreList[i].NumberOfWins}");
            }
        }
コード例 #5
0
ファイル: CardGameConsole.cs プロジェクト: Sonkerud/CardGame
 public static void PrintWinner(PlayingCardGame game)
 {
     if (game.Player1sTurn)
     {
         Console.WriteLine($"Congratulations {game.Players[0].Name} you won!");
     }
     else
     {
         Console.WriteLine($"Congratulations {game.Players[1].Name} you won!");
     }
     Console.ReadKey();
 }
コード例 #6
0
ファイル: CardGameConsole.cs プロジェクト: Sonkerud/CardGame
        public static void PlayGame(PlayingCardGame game)
        {
            Console.OutputEncoding = Encoding.UTF8;
            AddPlayersToGame(game);
            Console.Clear();
            game.DealCards(5);
            game.Players[0].StrengthOfHandCalculator();
            game.Players[1].StrengthOfHandCalculator();

            ChangeCards(game);
            RunGame(game);
            game.DecideWinner();
            game.UpdateHighScore();
            Console.Clear();
            DisplayHighScore(game);
            Console.ReadKey();
        }
コード例 #7
0
ファイル: CardGameConsole.cs プロジェクト: Sonkerud/CardGame
        public static void PlayCard(PlayingCardGame game, int i)
        {
            if (game.playedCards.Count != 0)
            {
                game.DisplayPlayedCards();
            }
            Console.WriteLine($"It's {game.Players[i].Name}s turn. Pick a card to play:\n");
            Console.WriteLine("Press enter to see hand:\n");
            Console.ReadKey(true);
            game.Players[i].PrintPlayersCards();
            bool validIdofCard = false;

            while (!validIdofCard)
            {
                var idOfcardToPlay = InputControl.ControlIntInput(1, 5);

                if (game.Players[i].DealtHand.Any(x => x.Id == idOfcardToPlay))
                {
                    var cardToPlay = game.Players[i].DealtHand.Single(x => x.Id == idOfcardToPlay);
                    if (game.playedCards.Count == 0)
                    {
                        game.playedCards.Add((game.Players[i].Name, cardToPlay));
                        game.Players[i].PlayCard(idOfcardToPlay);
                        validIdofCard = true;
                    }
                    else if (game.playedCards.Count % 2 == 0 || game.playedCards[game.playedCards.Count - 1].Item2.Suit == cardToPlay.Suit || !game.Players[i].DealtHand.Any(x => x.Suit == game.playedCards[game.playedCards.Count - 1].Item2.Suit))
                    {
                        game.playedCards.Add((game.Players[i].Name, cardToPlay));
                        game.Players[i].PlayCard(idOfcardToPlay);
                        validIdofCard = true;
                    }
                    else
                    {
                        Console.WriteLine("Wrong Suit. Chose a valid card.");
                    }
                }
                else
                {
                    Console.WriteLine("Input valid id from remaining card");
                }
            }
            Console.Clear();
        }
コード例 #8
0
ファイル: CardGameConsole.cs プロジェクト: Sonkerud/CardGame
        public static void ChangeCards(PlayingCardGame game)
        {
            for (int i = 0; i < game.Players.Count; i++)
            {
                Console.WriteLine($"{game.Players[i].Name}, press enter to see your hand: ");
                Console.ReadLine();
                game.Players[i].PrintPlayersCards();
                List <int> idOfCardsToChange = new List <int>();
                Console.WriteLine($"{game.Players[i].Name}: Input nr of cards you like to change:");
                int nrOfCardToChange = InputControl.ControlIntInput(0, 5);

                for (int y = 0; y < nrOfCardToChange; y++)
                {
                    int  idOfCardToChange = 0;
                    bool input            = false;
                    while (!input)
                    {
                        Console.WriteLine("Input id of card you like to change:");

                        try
                        {
                            idOfCardToChange = int.Parse(Console.ReadLine());
                            if (!idOfCardsToChange.Any(x => x == idOfCardToChange))
                            {
                                idOfCardsToChange.Add(idOfCardToChange);
                                input = true;
                            }
                            else
                            {
                                Console.WriteLine("Card doesn't exist!");
                            }
                        }
                        catch (Exception)
                        {
                            Console.WriteLine("Invalid Id");
                        }
                    }
                }

                game.Players[i].ChangeCard(idOfCardsToChange, game);
                Console.Clear();
            }
        }
コード例 #9
0
ファイル: CardGameConsole.cs プロジェクト: Sonkerud/CardGame
        public static void RunGame(PlayingCardGame game)
        {
            Console.Clear();

            for (int i = 0; i < 5; i++)
            {
                if (game.Player1sTurn)
                {
                    PlayCard(game, 0);

                    PlayCard(game, 1);
                }
                else if (!game.Player1sTurn)
                {
                    PlayCard(game, 1);

                    PlayCard(game, 0);
                }
                game.DecideWhosTurn();

                Console.Clear();
            }
            PrintWinner(game);
        }
コード例 #10
0
        static void Main(string[] args)
        {
            PlayingCardGame game = new PlayingCardGame();

            CardGameConsole.StartGame(game);
        }
コード例 #11
0
        public static void Main(string[] args)
        {
            var game = new PlayingCardGame();

            game.Menu();
        }
コード例 #12
0
 private static void NewGame()
 {
     PlayingCardGame game = new PlayingCardGame();
 }
コード例 #13
0
ファイル: CardGameConsole.cs プロジェクト: Sonkerud/CardGame
 public static bool ControlValidCard(int idOfCard, int i, PlayingCardGame game)
 {
     return(game.Players[i].DealtHand.Any(x => x.Id == idOfCard));
 }