Exemplo n.º 1
0
        public void RunGame()
        {
            Global global = new Global();
            //main title
            MainMenu mainMenu = new MainMenu();

            mainMenu.StartMainMenu();
            Console.Clear();
            mainMenu.ShowInfoScreen();
            Console.Clear();

            //intantiation and declaration of objects.....

            Map          map          = new Map();
            World        world        = new World();
            GameOver     gameOver     = new GameOver();
            Player       player       = new Player();
            EnemyManager enemyManager = new EnemyManager();
            ItemManager  itemManager  = new ItemManager();
            HUD          Hud          = new HUD();
            Camera       camera       = new Camera(map);
            Inventory    inventory    = new Inventory(itemManager);
            ShopManager  shopManager  = new ShopManager();

            world.InitEntities(enemyManager, itemManager, player, camera, inventory, shopManager);
            itemManager.SetShopManager(shopManager);

            //gameloop
            Hud.DisplayHUD(player, enemyManager, camera, inventory, itemManager);
            camera.Draw(player, enemyManager, map, itemManager, shopManager);
            while (true)
            {
                // updates
                itemManager.UpdateItems(map, player, inventory, camera);
                player.Update(map, enemyManager, itemManager, gameOver, inventory, shopManager);
                shopManager.Update();
                inventory.Update(player, itemManager);
                camera.Update(map, player);
                enemyManager.UpdateEnemies(map, player, camera, itemManager, enemyManager);

                //draws + other game elements(for polish)
                itemManager.DrawItems(camera);
                Hud.DisplayHUD(player, enemyManager, camera, inventory, itemManager);
                enemyManager.DrawEnemies(camera);
                shopManager.Draw();
                player.Draw(camera);
                camera.Draw(player, enemyManager, map, itemManager, shopManager);

                //if game is over in anyway break out of game loop.....

                if (gameOver.gameOverWin == true)
                {
                    break;
                }
                if (gameOver.gameOverLoss == true)
                {
                    break;
                }
            }
            if (gameOver.gameOverWin == true)
            {
                Console.Clear(); gameOver.GameOverWinScreen();
            }
            if (gameOver.gameOverLoss == true)
            {
                Console.Clear(); gameOver.GameOverLossScreen();
            }
        }
Exemplo n.º 2
0
        public void GameLoop()
        {
            //ON START
            //Instantiate the viewport including the map
            camera = new Camera("World", ConsoleColor.White);

            //Load up enemy data
            SpawnEnemyAtRuntime(Constant.GAMEPLAY_CANVAS_LIMIT_RIGHT - 10, Constant.GAMEPLAY_CANVAS_LIMIT_UP + 9, EnemyType.Common_Robot, "[    Common Robot    ]");
            SpawnEnemyAtRuntime(Constant.GAMEPLAY_CANVAS_LIMIT_RIGHT - 10, Constant.GAMEPLAY_CANVAS_LIMIT_UP + 9, EnemyType.Common_Robot, "[Another Common Robot]");
            SpawnEnemyAtRuntime(Constant.GAMEPLAY_CANVAS_LIMIT_RIGHT - 10, Constant.GAMEPLAY_CANVAS_LIMIT_UP + 3, EnemyType.Elite_Robot, "[     Elite Robot    ]");
            SpawnEnemyAtRuntime(Constant.GAMEPLAY_CANVAS_LIMIT_RIGHT - 20, Constant.GAMEPLAY_CANVAS_LIMIT_UP + 10, EnemyType.Giant_Robot, "[     Big Fat Bot    ]");
            SpawnEnemyAtRuntime(Constant.GAMEPLAY_CANVAS_LIMIT_RIGHT - 20, Constant.GAMEPLAY_CANVAS_LIMIT_UP + 10, EnemyType.Boss, "[      BIG BOSS      ]");

            //load items, enemies into camera feed
            camera.AddObject(enemyList[0].MapForm, 118, 22);
            camera.AddObject(enemyList[1].MapForm, 42, 10);
            camera.AddObject(enemyList[2].MapForm, 16, 8);
            camera.AddObject(enemyList[3].MapForm, 165, 10);
            camera.AddObject(enemyList[4].MapForm, 145, 61);
            camera.AddObject('⌐', 13, 5);
            camera.AddObject('O', 212, 42);

            //Gameplay canvas
            gameUI.DrawGameplayCanvas();

            //Instantiate Player attributes
            player.CurrentHealth = 30;
            player.CurrentShield = 1;

            //-- Player start location is at the center of the map
            player.X = Constant.GAMEPLAY_CANVAS_LIMIT_LEFT + (int)Math.Round(Constant.VIEWPORT_WIDTH / 2.0, 0) + 1;
            player.Y = Constant.GAMEPLAY_CANVAS_LIMIT_UP + (int)Math.Round(Constant.VIEWPORT_HEIGHT / 2.0, 0) + 1;
            //Display level objective of this level
            gameUI.DrawConfirmationBox(Constant.GAMEPLAY_CANVAS_LIMIT_LEFT + (Constant.GAMEPLAY_CANVAS_LIMIT_RIGHT - Constant.GAMEPLAY_CANVAS_LIMIT_LEFT) / 2 - 26,
                                       Constant.GAMEPLAY_CANVAS_LIMIT_UP + (Constant.GAMEPLAY_CANVAS_LIMIT_DOWN - Constant.GAMEPLAY_CANVAS_LIMIT_UP) / 2 - 2,
                                       28,
                                       4,
                                       "Find and defeat Big Boss", //ok
                                       3);
            camera.Update();
            //camera.TakeSnapshot();

            while (!gameLose || !gameWin)
            {
                //Show player stats
                gameUI.ShowStatsHUD(1, 1, player);

                //Draw Player at default position
                displayManager.DrawObjectAt(player.X, player.Y, player.MapForm.ToString(), player.Color);

                //Collision check
                gameLogic.CollisionCheckInsideCameraViewport(camera, player);
                gameLogic.CollisionCheckBetweenPlayerAndCanvasBoundaries(player);

                //Run player controller
                PlayerController2();

                //Update camera
                //camera.TakeSnapshot();
                camera.Update();

                //Non-enemy collision check on world map
                //------------------------- Flip the switch
                if (gameLogic.ObjectCollisionCheckOnWorldMap(camera, player, '⌐'))
                {
                    gameUI.DrawConfirmationBox(Constant.GAMEPLAY_CANVAS_LIMIT_LEFT + (Constant.GAMEPLAY_CANVAS_LIMIT_RIGHT - Constant.GAMEPLAY_CANVAS_LIMIT_LEFT) / 2 - 26,
                                               Constant.GAMEPLAY_CANVAS_LIMIT_UP + (Constant.GAMEPLAY_CANVAS_LIMIT_DOWN - Constant.GAMEPLAY_CANVAS_LIMIT_UP) / 2 - 2,
                                               30,
                                               4,
                                               "A door is opened somewhere", //ok
                                               5);
                    camera.RemoveObject(13, 5);
                    camera.RemoveObject(147, 21);
                    camera.RemoveObject(148, 21);
                    camera.RemoveObject(147, 22);
                    camera.RemoveObject(148, 22);
                }
                //------------------------- Mega buff
                if (gameLogic.ObjectCollisionCheckOnWorldMap(camera, player, 'O'))
                {
                    gameUI.DrawConfirmationBox(Constant.GAMEPLAY_CANVAS_LIMIT_LEFT + (Constant.GAMEPLAY_CANVAS_LIMIT_RIGHT - Constant.GAMEPLAY_CANVAS_LIMIT_LEFT) / 2 - 26,
                                               Constant.GAMEPLAY_CANVAS_LIMIT_UP + (Constant.GAMEPLAY_CANVAS_LIMIT_DOWN - Constant.GAMEPLAY_CANVAS_LIMIT_UP) / 2 - 2,
                                               36,
                                               4,
                                               "You received an powerful upgrade", //ok
                                               7);
                    camera.RemoveObject(212, 42);
                    player.Health        = 100;
                    player.CurrentHealth = 100;
                    player.CurrentShield = 100;
                    player.Damage       += 10;
                }

                //Battle check
                if (enemyList.Count != 0 && gameLogic.BattleCheckOnWorldMap(camera, player, enemyList[0]))
                {
                    //Display level objective of this level
                    gameUI.DrawConfirmationBox(Constant.GAMEPLAY_CANVAS_LIMIT_LEFT + (Constant.GAMEPLAY_CANVAS_LIMIT_RIGHT - Constant.GAMEPLAY_CANVAS_LIMIT_LEFT) / 2 - 26,
                                               Constant.GAMEPLAY_CANVAS_LIMIT_UP + (Constant.GAMEPLAY_CANVAS_LIMIT_DOWN - Constant.GAMEPLAY_CANVAS_LIMIT_UP) / 2 - 2,
                                               28,
                                               4,
                                               "You encountered an enemy", //ok
                                               3);
                    gameUI.DrawTransitionEffect_Dissolve('█', ' ');

                    switch (battleCount)
                    {
                    case 0:
                        StartBattle(scenario_00);
                        break;

                    case 1:
                        StartBattle(scenario_01);
                        camera.RemoveObject(41, 16);
                        camera.RemoveObject(42, 16);
                        camera.RemoveObject(43, 16);
                        break;

                    case 2:
                        StartBattle(scenario_02);
                        camera.RemoveObject(15, 6);
                        camera.RemoveObject(16, 6);
                        camera.RemoveObject(17, 6);
                        break;

                    case 3:
                        StartBattle(scenario_03);
                        camera.RemoveObject(187, 21);
                        camera.RemoveObject(188, 21);
                        camera.RemoveObject(187, 22);
                        camera.RemoveObject(188, 22);
                        break;

                    case 4:
                        StartBattle(scenario_04);
                        gameWin = true;
                        break;
                    }

                    //Remove defeated enemy data
                    camera.RemoveObject(enemyList[0].MapNegativeForm);
                    RemoveEnemyInstance(enemyList[0]);
                    battleFinish = false;


                    //Reset player map posistion
                    player.X = Constant.GAMEPLAY_CANVAS_LIMIT_LEFT + (int)Math.Round(Constant.VIEWPORT_WIDTH / 2.0, 0) + 1;
                    player.Y = Constant.GAMEPLAY_CANVAS_LIMIT_UP + (int)Math.Round(Constant.VIEWPORT_HEIGHT / 2.0, 0) + 1;

                    //Redrawn gameplay canvas
                    gameUI.DrawGameplayCanvas();
                }
                if (gameLose)
                {
                    gameState = GameState.Defeat;
                    ResetGameData();
                    break;
                }

                if (gameWin)
                {
                    gameState = GameState.Victory;
                    ResetGameData();
                    break;
                }
            }
            Console.Clear();
        }