示例#1
0
        public static async void userGame(int minRandomNumber, int maxRandomNumber, Task task)
        {
            int num = random.Next(minRandomNumber, maxRandomNumber);

            string userInput = Console.ReadLine();

            while (userInput != num.ToString() && task.IsCompleted == false)
            {
                Console.WriteLine("Dang, you didn't guess correctly, try again!\n");
                userInput = Console.ReadLine();
            }
            if (userInput == num.ToString())
            {
                Console.WriteLine($"You guessed the number: {num} correct! hurraayyyyyyy");
                GuessTheNumber.stopTask();//End task here
                Console.WriteLine("Press any key to restart!");
                Console.ReadKey();
                gameStart();
            }
            else
            {
                Console.Clear();
                GuessTheNumber.stopTask();//End task here
                Console.WriteLine($"Unlucky, you lost! The number you were trying to guess is {num}.");

                Console.WriteLine("\nPress any key to try again!");
                Console.ReadKey();
                gameStart();
            }
        }
    static void Main(string[] args)
    {
        GuessTheNumber numberGame = new GuessTheNumber();

        Console.WriteLine("We're going to play a guessing game!");
        Console.WriteLine("Please enter a number between "
                          + GuessTheNumber.LOW + " and "
                          + GuessTheNumber.HIGH + ":");

        try
        {
            int myGuess = int.Parse(Console.ReadLine());
            if ((myGuess > GuessTheNumber.HIGH) ||
                (myGuess < GuessTheNumber.LOW))
            {
                Console.WriteLine("Value must be between "
                                  + GuessTheNumber.LOW + " and "
                                  + GuessTheNumber.HIGH);
            }
            else
            {
                Console.WriteLine(numberGame.tryGuess(myGuess));
            }
        }
        catch
        {
            Console.WriteLine("You need to enter a number!");
        }
    }
示例#3
0
        public static void gameStart()
        {
            GuessTheNumber.resetTokenValue();
            Console.Clear();
            Console.WriteLine("Press any key once you're ready to guess the number im thinking off.\nBut keep in mind, you only have 10 seconds!\n");
            Console.ReadKey();

            var task = GuessTheNumber.timerForGame(1, 10, () => Console.Write("Remaining seconds until automatic loss: "), () => Console.WriteLine("Time has run out!"));

            userGame(1, 10, task);
        }
示例#4
0
        public static IDisplayPiece GetQuest(string questName, int id, int widthCoo, int debthCoo)
        {
            //// TODO: make the quests drop items
            //// TODO: make items that show on the side of the board (3 items are more than enough)

            Position initPosition = new Position(widthCoo, debthCoo);

            if (questName == "QuizQuest")
            {
                QuizQuest quest = new QuizQuest(initPosition);
                quest.Id = id;
                return(quest);
            }
            else if (questName == "FallingRocks")
            {
                FallingRocks quest = new FallingRocks(initPosition);
                quest.Id = id;
                return(quest);
            }
            else if (questName == "FlappyBird")
            {
                FlappyBirdQuest quest = new FlappyBirdQuest(initPosition);
                quest.Id = id;
                return(quest);
            }
            else if (questName == "GuessTheNumber")
            {
                GuessTheNumber quest = new GuessTheNumber(initPosition);
                quest.Id = id;
                return(quest);
            }
            else if (questName == "Hangman")
            {
                Hangman quest = new Hangman(initPosition);
                quest.Id = id;
                return(quest);
            }

            return(null);
        }
    static void Main(string[] args)
    {
        Console.WriteLine("We're going to play a guessing game!");
        Console.WriteLine("Please enter a number between 1 and 10:");

        try
        {
            int myGuess = int.Parse(Console.ReadLine());
            if ((myGuess > 10) || (myGuess < 1))
            {
                Console.WriteLine("Value must be between 1 and 10");
            }
            else
            {
                GuessTheNumber gtn = new GuessTheNumber();
                Console.WriteLine(gtn.tryGuess(myGuess));
            }
        }
        catch
        {
            Console.WriteLine("You need to enter a number!");
        }
    }