Example #1
0
        public void StartGame(GuiController guiController)
        {
            // init game
            GameScreen myGame = new GameScreen(30, 20);

            // fill game with game data.
            myGame.SetHero(new Hero(5, 5, "HERO"));

            Random rnd        = new Random();
            int    enemyCount = 0;

            for (int i = 0; i < 10; i++)
            {
                myGame.AddEnemy(new Enemy(enemyCount, rnd.Next(0, 10), rnd.Next(0, 10), "enemy" + enemyCount));
                enemyCount++;
            }

            // render loop
            bool needToRender = true;

            do
            {
                // isvalom ekrana
                Console.Clear();
                myGame.Render();

                while (Console.KeyAvailable)
                {
                    ConsoleKeyInfo pressedChar = Console.ReadKey(true);
                    int            hashCode    = pressedChar.Key.GetHashCode();

                    switch (hashCode)
                    {
                    case 27:     //ConsoleKey.Escape:
                        needToRender = false;
                        Console.Clear();
                        guiController.ShowMenu();
                        break;

                    case 39:     // ConsoleKey.RightArrow:
                        myGame.GetHero().MoveRight();
                        Console.Clear();
                        myGame.Render();
                        break;

                    case 37:     // ConsoleKey.LeftArrow:
                        myGame.GetHero().MoveLeft();
                        Console.Clear();
                        myGame.Render();
                        break;
                    }
                }


                System.Threading.Thread.Sleep(250);
            } while (needToRender);
        }
        public void EndGame(int score, GuiController guiController)
        {
            GameOverWindow gameOverWindow = new GameOverWindow(score);

            gameOverWindow.Render();
            bool needToRender = true;

            do
            {
                while (Console.KeyAvailable)
                {
                    ConsoleKeyInfo pressedChar = Console.ReadKey(true);
                    int            hashCode    = pressedChar.Key.GetHashCode();

                    switch (hashCode)
                    {
                    case 39:     // ConsoleKey.RightArrow:
                        gameOverWindow.SwitchActiveButtonsToRight();
                        gameOverWindow.Render();
                        break;

                    case 37:     // ConsoleKey.LeftArrow:
                        gameOverWindow.SwitchActiveButtonsToLeft();
                        gameOverWindow.Render();
                        break;

                    case 13:
                        switch (gameOverWindow.ActiveButtonIndex())
                        {
                        case 0:
                            StartGame(guiController, new GameScreen(50, 30));
                            break;

                        case 1:
                            guiController.ShowMenu();
                            needToRender = false;
                            break;

                        default:
                            break;
                        }
                        break;
                    }
                }

                System.Threading.Thread.Sleep(250);
            } while (needToRender);
        }
        public void PauseGame(GuiController guiController, GameScreen myGame)
        {
            PauseWindow pauseWindow = new PauseWindow(myGame.GetScore());

            pauseWindow.Render();
            bool needToRender = true;

            do
            {
                while (Console.KeyAvailable)
                {
                    ConsoleKeyInfo pressedChar = Console.ReadKey(true);
                    int            hashCode    = pressedChar.Key.GetHashCode();

                    switch (hashCode)
                    {
                    case 39:     // ConsoleKey.RightArrow:
                        pauseWindow.SwitchActiveButtonsToRight();
                        pauseWindow.Render();
                        break;

                    case 37:     // ConsoleKey.LeftArrow:
                        pauseWindow.SwitchActiveButtonsToLeft();
                        pauseWindow.Render();
                        break;

                    case 13:
                        switch (pauseWindow.ActiveButtonIndex())
                        {
                        case 0:
                            StartGame(guiController, myGame);
                            break;

                        case 1:
                            guiController.ShowMenu();
                            needToRender = false;
                            break;

                        default:
                            break;
                        }
                        break;
                    }
                }

                System.Threading.Thread.Sleep(250);
            } while (needToRender);
        }
        public void StartGame(GuiController guiController, GameScreen myGame)
        {
            Console.Clear();
            ConsoleKeyInfo keyInfo;

            myGame.RenderFrames();
            while (!myGame.IsGameOver())
            {
                Thread.Sleep(Convert.ToInt16(100 / myGame.Speed));
                if (Console.KeyAvailable == true)
                {
                    keyInfo = Console.ReadKey(true);
                    switch (keyInfo.Key)
                    {
                    case ConsoleKey.UpArrow:
                        myGame.SetDir(0, -1);
                        break;

                    case ConsoleKey.DownArrow:
                        myGame.SetDir(0, 1);
                        break;

                    case ConsoleKey.RightArrow:
                        myGame.SetDir(1, 0);
                        break;

                    case ConsoleKey.LeftArrow:
                        myGame.SetDir(-1, 0);
                        break;

                    case ConsoleKey.Escape:
                        PauseGame(guiController, myGame);
                        break;
                    }
                }
                myGame.Eat();
                myGame.Render();
            }
            EndGame(myGame.GetScore(), guiController);
        }
Example #5
0
 public void ExitToMenu()
 {
     GuiController exitToMenu = new GuiController();
 }