示例#1
0
        // the game loop
        public void Run()
        {
            ConsoleKeyInfo keyInfo;
            bool           quit       = true;
            int            user_Input = 0;

            PrintTitle();
            PrintStory();
            Console.WriteLine("[Enter] to play the game....");

            //keyInfo = Console.ReadKey (true);

            while (quit)
            {
                keyInfo = Console.ReadKey(true);
                if (keyInfo.Key == ConsoleKey.Enter)
                {
                    Console.Clear();
                    PrintNames();
                    PrintHealth();
                    PrintLineBreak();
                    PrintAttacks();
                    // user input and converts it to int and bool value
                    if (Validator(Console.ReadLine(), out user_Input))
                    {
                        boss.health -= player.Attack(user_Input);
                    }

                    player.health -= boss.Attack();

                    // quit prompt ** note: check for either the player is dead or skeletor
                    if (boss.isDead() || player.isDead())
                    {
                        quit = player.Quitter();
                        if (quit)
                        {
                            gameState = 2;
                        }
                    }
                    else
                    {
                        Console.WriteLine("[Enter] to continue....");
                    }
                }
                if (gameState == 2)
                {
                    player    = new HeMan();
                    boss      = new Skeletor();
                    gameState = 1;
                }
            }

            // exiting the program and when debugging it will stop.
            Console.WriteLine("Skeletor and He-man retreat...\n[Enter] to exit...");
            keyInfo = Console.ReadKey(true);
            if (keyInfo.Key == ConsoleKey.Enter)
            {
                Console.Write("Bye... Bye...");
            }
        }
示例#2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CombatSimulator.Game"/> class.
 /// </summary>
 public Game()
 {
     player    = new HeMan();
     boss      = new Skeletor();
     gameState = 1;
     // set window size
     Console.SetWindowSize(WIDTH, HEIGHT);
     Console.CursorVisible = false;
 }