Ejemplo 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();
            }
        }
Ejemplo n.º 2
0
        public void Update(Map map, EnemyManager enemyManager, ItemManager itemManager, GameOver gameOver, Inventory inventory, ShopManager shopManager)
        {
            Console.CursorVisible = false;
            ConsoleKey keyPressed = Console.ReadKey(true).Key;

            if (vitalStatus == VitalStatus.Alive)
            {
                if (keyPressed == ConsoleKey.W)
                {
                    //collision
                    if (wallExist = map.IsWallAt(xLoc, yLoc - 1))
                    {
                        //do nothing
                    }
                    else if (enemyExist = enemyManager.IsEnemyAt(xLoc, yLoc - 1))
                    {
                        enemyManager.CheckEnemies(xLoc, yLoc - 1, attackDamage);
                    }
                    else if (itemExist = itemManager.IsItemAt(xLoc, yLoc - 1) && inventory.settingUpInventory == false)
                    {
                        if (inventory.IsInventorySlotAvailable() == true)
                        {
                            itemManager.CheckAndPickupItems(xLoc, yLoc - 1);
                        }
                        else
                        {
                            inventory.inventoryIsFull = true;
                        }
                    }
                    else
                    {
                        previousXLoc = xLoc;
                        previousYLoc = yLoc;
                        yLoc         = yLoc - 1;
                    }
                }
                if (keyPressed == ConsoleKey.A)
                {
                    if (wallExist = map.IsWallAt(xLoc - 1, yLoc))
                    {
                        //do nothing
                    }
                    else if (enemyExist = enemyManager.IsEnemyAt(xLoc - 1, yLoc))
                    {
                        enemyManager.CheckEnemies(xLoc - 1, yLoc, attackDamage);
                    }
                    else if (itemExist = itemManager.IsItemAt(xLoc - 1, yLoc))
                    {
                        if (inventory.IsInventorySlotAvailable() == true)
                        {
                            itemManager.CheckAndPickupItems(xLoc - 1, yLoc);
                        }
                        else
                        {
                            inventory.inventoryIsFull = true;
                        }
                    }
                    else
                    {
                        previousXLoc = xLoc;
                        previousYLoc = yLoc;
                        xLoc         = xLoc - 1;
                    }
                }
                if (keyPressed == ConsoleKey.S)
                {
                    if (wallExist = map.IsWallAt(xLoc, yLoc + 1))
                    {
                        //do nothing
                    }
                    else if (enemyExist = enemyManager.IsEnemyAt(xLoc, yLoc + 1))
                    {
                        enemyManager.CheckEnemies(xLoc, yLoc + 1, attackDamage);
                    }
                    else if (itemExist = itemManager.IsItemAt(xLoc, yLoc + 1))
                    {
                        if (inventory.IsInventorySlotAvailable() == true)
                        {
                            itemManager.CheckAndPickupItems(xLoc, yLoc + 1);
                        }
                        else
                        {
                            inventory.inventoryIsFull = true;
                        }
                    }
                    else
                    {
                        previousXLoc = xLoc;
                        previousYLoc = yLoc;
                        yLoc         = yLoc + 1;
                    }
                }
                if (keyPressed == ConsoleKey.D)
                {
                    if (wallExist = map.IsWallAt(xLoc + 1, yLoc))
                    {
                        //do nothing
                    }
                    else if (enemyExist = enemyManager.IsEnemyAt(xLoc + 1, yLoc))
                    {
                        enemyManager.CheckEnemies(xLoc + 1, yLoc, attackDamage);
                    }
                    else if (itemExist = itemManager.IsItemAt(xLoc + 1, yLoc))
                    {
                        if (inventory.IsInventorySlotAvailable() == true)
                        {
                            itemManager.CheckAndPickupItems(xLoc + 1, yLoc);
                        }
                        else
                        {
                            inventory.inventoryIsFull = true;
                        }
                    }
                    else
                    {
                        previousXLoc = xLoc;
                        previousYLoc = yLoc;
                        xLoc         = xLoc + 1;
                    }
                }
                if (keyPressed == ConsoleKey.I)
                {
                    inventory.inventoryIsOpen = true;
                }
                //determines win
                if (collectedValuables >= itemManager.valuableCount)
                {
                    gameOver.gameOverWin = true;
                }
            }
            else
            {
                SwitchVitalStatus(VitalStatus.Dead);
            }
            //determines loss...
            if (vitalStatus == VitalStatus.Dead)
            {
                gameOver.gameOverLoss = true;
            }
        }