Exemple #1
0
        public static void Game(bool play, Player player, string ChoosenLevel)
        {
            Program.player = player;

            if (play)
            {
                player.score = 0;

                CountDown();
                Console.Clear();

                Console.WriteLine("\nPlayer: {0} \n\n", player.name);

                string randomChar;
                var    gameEndsAt = DateTime.Now.AddSeconds(15);
                var    date       = DateTime.Now;
                while (PlayGame && DateTime.Now < gameEndsAt)
                {
                    if (ChoosenLevel == "m" || ChoosenLevel == "medium")
                    {
                        randomChar = Level.GetShortWord();
                    }
                    else if (ChoosenLevel == "h" || ChoosenLevel == "hard")
                    {
                        randomChar = Level.GetLongWord();
                    }
                    else
                    {
                        randomChar = Level.GetLetter();
                    }

                    Console.SetCursorPosition(5, 4);
                    Console.WriteLine(randomChar);
                    Console.WriteLine("\n__________________\n");
                    var answer = "";

                    ClearCurrentConsoleLine();

                    while (!Console.KeyAvailable)
                    {
                        if (DateTime.Now >= gameEndsAt)
                        {
                            PlayGame = false;
                            break;
                        }
                    }

                    if (PlayGame)
                    {
                        Console.Write("     ");
                        answer = Console.ReadLine();
                    }
                    else
                    {
                        break;
                    }

                    if (randomChar == answer)
                    {
                        player.score++;
                        Console.WriteLine("\n \n Score: {0}", player.score);
                        Console.SetCursorPosition(2, 2);
                    }
                    else
                    {
                        Console.SetCursorPosition(2, 2);
                    }
                }

                Console.Clear();
                GameOver(gameChar, player);
            }
        }