コード例 #1
0
ファイル: Program.cs プロジェクト: Captainrax/SKP_Projects
        private static void GuessGame()
        {
            Random random = new Random();
            // numbers to guess between ( both numbers get -1 )
            int num = random.Next(1, 11);
            // number of guesses the player gets at the start
            int GuessCount = 3;
            // current guess
            int guess = 0;

            // game loop
            while (GuessCount >= 0)
            {
                bool nomore = false;
                Console.Clear();

                // Debug
                //Console.WriteLine(num);

                // checks if game is over ie. 0 guesses left
                if (guess == num)
                {
                    // Guessed correct, +3 guesses, new guess number 0 / 10
                    WinStreak++;
                    Console.WriteLine("Guess Correct!");
                    GuessCount = GuessCount + 3;
                    num        = random.Next(1, 11);
                }
                else if (GuessCount < 1)
                {
                    // bool for making sure the player presses Y/n or N/n
                    bool c = true;
                    while (c == true)
                    {
                        Console.WriteLine("you lose! play agian? (Y/N)");
                        Console.Write(": ");

                        string repeat = Console.ReadLine();

                        if (repeat == "Y" || repeat == "y")
                        {
                            // New game
                            GuessCount += 3;
                            num         = random.Next(1, 11);
                            guess       = 0;
                            WinStreak   = 0;
                            c           = false;
                        }
                        else if (repeat == "N" || repeat == "n")
                        {
                            // Saves current game to HighScore.json
                            if (WinStreak >= 1)
                            {
                                Console.WriteLine("input name: ");
                                WinStreakName = Console.ReadLine();
                                if (WinStreakName.Count() >= 1)
                                {
                                    HighScoreObject.Unit tempunit = new HighScoreObject.Unit(WinStreakName, WinStreak);
                                    HandleData.DataBase.Add(tempunit);
                                    HandleData.Commit();
                                }
                            }
                            // resets game
                            guess     = 0;
                            WinStreak = 0;
                            c         = false;
                            nomore    = true;
                        }
                        Console.Clear();
                    }
                    // breaks out of the game if you typed "N / n"
                    if (nomore == true)
                    {
                        break;
                    }
                }
                if (guess != 0)
                {
                    if (guess > num)
                    {
                        Console.WriteLine("The number is smaller.");
                    }
                    else if (guess < num)
                    {
                        Console.WriteLine("the number is bigger.");
                    }
                }

                Console.WriteLine("Current WinStreak: " + WinStreak);
                Console.WriteLine("Guesses Left: " + GuessCount);
                Console.Write("Guess Number: ");

                // takes player guess
                try
                {
                    guess = Convert.ToInt32(Console.ReadLine());
                    if (guess < 0 || guess > 10)
                    {
                    }
                    else
                    {
                        GuessCount--;
                    }
                }
                catch
                {
                    Console.WriteLine("thats not a number!");
                }
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: Captainrax/SKP_Projects
 static void Main(string[] args)
 {
     HandleData.Load();
     MainMenu();
 }