Exemple #1
0
        static void Main(string[] args)
        {
            Screens.OpenScreen();
            int          difficulty = Screens.SelectDifficulty(25, 10);
            ConsoleBoard board      = new ConsoleBoard(20, 50);
            Game         game       = new Game(board, difficulty);

            game.Run();
            Screens.Finish();
        }
Exemple #2
0
        // Runs the game loop.
        public void Run()
        {
            Console.CursorVisible = false;
            this.Render();
            ConsoleKey key              = 0;
            int        iteration        = 0;
            int        timeSinceLastHit = 0;

            do
            {
                this.HandleKeyPress(key);
                while (!Console.KeyAvailable && this.player.Health != 0)
                {
                    if (iteration % 30 == 0)
                    {
                        this.player.IncreaseScore(1);
                    }
                    if (timeSinceLastHit % 90 == 0)
                    {
                        Console.SetCursorPosition(0, this.board.GetHeight() + 4);
                        Console.Write(new String(' ', 100));
                    }
                    if (moveFlag = !moveFlag)
                    {
                        for (int i = 0; i < this.enemies.Count; i++)
                        {
                            this.enemies[i].Move(this.board, this.player);
                            bool isHit = this.player.CheckHit(this.enemies[i]);
                            if (isHit)
                            {
                                timeSinceLastHit = 0;
                                Console.SetCursorPosition(0, this.board.GetHeight() + 4);
                                Console.Write(new String(' ', 100));
                                Console.SetCursorPosition(0, this.board.GetHeight() + 4);
                                this.attackers[i].Attack(0, this.board.GetHeight() + 4, this.player);
                            }
                        }
                    }

                    iteration++;
                    timeSinceLastHit++;
                    this.Render();
                }
                // Game over message
                if (this.player.Health == 0)
                {
                    Console.SetCursorPosition(0, 0);
                    Console.Write(new String(' ', 100));
                    Console.SetCursorPosition(0, this.board.GetHeight() + 4);
                    Console.Write(new String(' ', 100));
                    Screens.EndScreen(this.board.GetWidth() / 2, this.board.GetHeight() / 2, this.player.Score);
                }
            } while ((key = Console.ReadKey(true).Key) != ConsoleKey.Escape);
        }