Esempio n. 1
0
        public void Update(Player player, Inventory inventory)
        {
            if (bought)
            {
                return;
            }

            if (inventory.IsInventorySlotAvailable())
            {
                if (player.CheckGoldAmount() >= itemPrice)
                {
                    bool canBuyItem = true;
                    while (canBuyItem)
                    {
                        Console.Clear();
                        Console.CursorLeft = 0;
                        Console.CursorTop  = 0;
                        Console.WriteLine("This " + itemName + " costs " + itemPrice + ". You have " + player.CheckGoldAmount() + ". Do you want to buy it?");
                        Console.WriteLine("Y) Yes      N) No");
                        ConsoleKeyInfo keyPressed = Console.ReadKey(true);
                        if (keyPressed.Key == ConsoleKey.Y)
                        {
                            GiveItem();
                            player.LoseGold(itemPrice);
                            canBuyItem = false;
                            bought     = true;
                            pickedUp   = true;
                            Console.Clear();
                            break;
                        }
                        else if (keyPressed.Key == ConsoleKey.N)
                        {
                            canBuyItem = false;
                            Console.Clear();
                            break;
                        }
                    }
                }
                else
                {
                    Console.Clear();
                    Console.CursorLeft = 0;
                    Console.CursorTop  = 0;
                    Console.WriteLine("This " + itemName + " costs " + itemPrice + ". You have " + player.CheckGoldAmount() + ". You cannot afford it.");
                    Console.ReadKey(true);
                    Console.Clear();
                }
            }
        }
Esempio 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;
            }
        }