Пример #1
0
        // ----- private methods
        public void OpenDoor(Player player, HUD hud, Inventory inventory)
        {
            int[] stock = inventory.ItemStock();

            /*for (int i = 0; i < Global.globalAccess.itemIDs.Count; i++)
             * {
             *  if (this._avatar == Global.globalAccess.ItemValues.avatars[i])
             *  {
             *      string ID = i.ToString();
             *      if (stock[i] > 0)
             *      {
             *
             *          inventory.DecreaseStock(i);
             *          hud.Draw(); // updates visible inventory
             *          aliveInWorld = false;
             *          hud.DisplayText($"< {player.Name()} {Global.ITEM_TEXTSUCCESS(ID)} >", false);
             *          _opened = true;
             *      }
             *      else
             *      {
             *          hud.DisplayText($"<  { player.Name()} {Global.ITEM_TEXTFAILURE(ID)} >", false);
             *      }
             *  }
             * }*/
            if (this._avatar == 'd')
            {
                if (stock[(int)ITEM.KEYSMALL] > 0)
                {
                    inventory.DecreaseStock(ITEM.KEYSMALL);
                    hud.Draw(); // updates visible inventory
                    aliveInWorld = false;
                    hud.DisplayText($"< {player.Name()} {Global.MESSAGE_DOORSMALLOPEN} >", false);
                    _opened = true;
                }
                else
                {
                    hud.DisplayText($"<  { player.Name()} {Global.MESSAGE_DOORSMALLLOCKED} >", false);
                }
            }
            if (this._avatar == 'D')
            {
                if (stock[(int)ITEM.KEYBIG] > 0)
                {
                    inventory.DecreaseStock(ITEM.KEYBIG);
                    hud.Draw(); // updates visible inventory
                    aliveInWorld = false;
                    hud.DisplayText($"< {player.Name()} {Global.MESSAGE_DOORBIGOPEN} >", false);
                    _opened = true;
                }
                else
                {
                    hud.DisplayText($"< {player.Name()} {Global.MESSAGE_DOORBIGLOCKED} >");
                }
            }
        }
Пример #2
0
        public int DealDamage(int[] health, HUD ui, bool isEnemy, int[] shield = null) // calculates damage and deals it out
        {
            int damageToHealth = -1;

            //calculate damage
            damageToHealth = Toolkit.RandomNumBetween(_damage[0], _damage[1]); //random runber between a high and low value
            int damageToShield = damageToHealth;                               //names for convenience and to display to HUD textbox
            int passDamage     = 0;                                            // null if not passing

            if (shield != null)                                                /// this if statement could alternatively be in enemy.dealdamage() but it was moved here and now makes more sense
            {
                // calculate spill damage
                int calcDamageSpill = damageToShield - shield[(int)STATUS.CURRENT];

                // deal damage to player shield
                shield[(int)STATUS.CURRENT] -= damageToShield;

                // passes spill damage and sets stat to limit
                if (shield[(int)STATUS.CURRENT] < 0)
                {
                    passDamage = calcDamageSpill;
                }
                shield[(int)STATUS.CURRENT] = SetStatToLimits(shield[(int)STATUS.CURRENT], shield[(int)STATUS.MAX]);
            }

            if (shield == null || shield[(int)STATUS.CURRENT] == 0)
            {
                // calculate damage
                if (passDamage != 0)
                {
                    damageToHealth = passDamage;
                }                                                     // sets the damage to the leftover shield break damage

                //deal damage to character health and checks the limits
                health[(int)STATUS.CURRENT] -= damageToHealth;
                health[(int)STATUS.CURRENT]  = SetStatToLimits(health[(int)STATUS.CURRENT], health[(int)STATUS.MAX]); // does nothing if limit doesnt break
            }

            if (!isEnemy)
            {
                //update player HUD bar
                ui.setHudHealthAndShield(health, shield);
                ui.Draw();
            }

            //sets damage to total amount of damage done if it spills into health
            if (passDamage != 0)
            {
                damageToHealth = damageToShield;
            }
            return(damageToHealth);
        }
Пример #3
0
        public void UseShieldPot(Player player, Item item, HUD hud)
        {
            if (stockItems[(int)ITEM.POTSHELL] > 0)
            {
                DecreaseStock(ITEM.POTSHELL);
                player.HealShell(item.Power(Global.ITEM_AVATAR(ITEM.POTSHELL)), this, hud);

                //update HUD bar and display to HUD text box
                hud.setHudHealthAndShield(player.Health(), player.Shield());
                hud.Draw();// updates visible inventory
                hud.UpdateHotBar(player, this);
            }
            else
            {
                hud.DisplayText($"< {player.Name()} {Global.MESSAGE_POTSHIELDMISSING} >", false);
            }
        }
Пример #4
0
        public void PickupFoundItems(Player player, List <Item> items, HUD hud)
        {
            for (int i = 0; i < items.Count; i++)
            {
                if (items[i].PickedUpByPlayer())
                {
                    //switch statement changed to if else to accept Global parameter

                    /*for (int j = 0; j < Global.globalAccess.itemIDs.Count; j++)
                     *                  {
                     *                          string ID = j.ToString();
                     *                          if (items[i].Avatar() == Global.ITEM_AVATAR(ID))
                     *                          {
                     *                                  IncreaseStock(ID);
                     *                          }
                     *                  }*/

                    if (items[i].Avatar() == Global.ITEM_AVATAR(ITEM.POTHEAL))
                    {
                        IncreaseStock(ITEM.POTHEAL);
                    }
                    else if (items[i].Avatar() == Global.ITEM_AVATAR(ITEM.POTSHELL))
                    {
                        IncreaseStock(ITEM.POTSHELL);
                    }
                    else if (items[i].Avatar() == Global.ITEM_AVATAR(ITEM.KEYBIG))
                    {
                        IncreaseStock(ITEM.KEYBIG);
                    }
                    else if (items[i].Avatar() == Global.ITEM_AVATAR(ITEM.KEYSMALL))
                    {
                        IncreaseStock(ITEM.KEYSMALL);
                    }

                    hud.UpdateHotBar(player, this);
                    hud.Draw();
                    hud.DisplayText($"< {player.Name()} picked up {items[i].Name()} [{items[i].Avatar()}] >", false);
                    items[i].PickedUpByPlayer(false);                     // removes the items ability to be picked up /this completes the process of putting the item in the invetory, otherwise pick up every item set to pickedup every time player picks up new item
                }
            }
        }
Пример #5
0
        // ----- public methods
        public void Draw()         // displays inventory / draws cursor
        {
            hud.Draw();

            // init positioning for display
            int moveUIX = (Console.WindowWidth / 2) - (Camera.displayWidth / 2);

            if (moveUIX < 0)
            {
                moveUIX = 0;
            }
            int moveUIY = (Console.WindowHeight / 3) - (Camera.displayHeight / 2);

            if (moveUIY < 0)
            {
                moveUIY = 0;
            }

            // set position
            if (Console.WindowHeight != Camera.minConsoleSizeHeight || Console.WindowWidth != Camera.minConsoleSizeWidth)
            {
                Console.SetCursorPosition(moveUIX + 1, moveUIY + 2);
            }
            else
            {
                Console.SetCursorPosition(1, 2);
            }

            //change display according to position
            int line = 2;

            for (int y = 0; y < Camera.displayHeight - 1; y++)
            {
                for (int x = 0; x < Camera.displayWidth - 1; x++)
                {
                    //write the display
                    Console.Write(background[y, x]);
                }

                //move down a line
                line++;
                if (Console.WindowHeight != Camera.minConsoleSizeHeight || Console.WindowWidth != Camera.minConsoleSizeWidth)
                {
                    Console.SetCursorPosition(moveUIX + 1, moveUIY + line);
                }
                else
                {
                    Console.SetCursorPosition(1, line);
                }
            }


            // set position of cursor  / -2 is cursor offset from selected item
            int[] menuSelect = { 0, 0 };
            if (cursorPos < 20)             // there's 20 item slots but this doesnt reach 20 however it starts at 0 making 20 slots
            {
                menuSelect[0] = itemPos[cursorPos, 0] - 2;
                menuSelect[1] = itemPos[cursorPos, 1];
            }
            else             // is weapon
            {
                int[] positioning = weaponPos[cursorPos - 20];
                menuSelect[0] = positioning[0] - 2;
                menuSelect[1] = positioning[1];                 // -19 is because there's 20 item slots -1 for '0 start'
            }
            Console.SetCursorPosition(menuSelect[0], menuSelect[1]);
            Console.Write(cursor);

            DrawObjects();
        }
Пример #6
0
        public GAMESTATE Update(List <Enemy> enemies, List <Door> doors, List <Item> item, Map map, Camera camera, HUD hud, Battle battle, Inventory inventory, GAMESTATE gameState, List <Vendor> vendors, TradeMenu tradeMenu)
        {
            if (aliveInWorld)
            {
                CheckForDying(camera, hud);

                // gets Input
                GetInput();

                // "Looks at" selected direction
                DirectionalOutput();

                // used in place of Directional, Opens inventory (and debug battle if not disabled)
                gameState = OpenInventoryOutput(inventory, gameState, battle, enemies[0]); // battle and enemies used for debug

                // used in place of Directional, only Healing items currently
                gameState = UseItemOutput(item[0], hud, inventory, gameState);// item is passed in blank because it's recognized inside the method this is for typing and can probably be done better

                //check everything for collision
                bool collision = false;

                //Enemy Collision / Attacking
                for (int i = 0; i < enemies.Count; i++)
                {
                    if (CheckForCharacterCollision(enemies[i].X(), enemies[i].Y(), enemies[i].AliveInWorld())) // enemy values read as zero on firstcontact, needs enemy locate to read adjesent tile's
                    {
                        //access weapons damage

                        //collide
                        collision = true;

                        //collide to deal damage
                        gameState = StartAttacking(enemies[i].AliveInWorld(), battle, this, enemies[i], gameState, inventory);
                    }
                }
                for (int i = 0; i < vendors.Count; i++)
                {
                    if (CheckForCharacterCollision(vendors[i].X(), vendors[i].Y(), vendors[i].AliveInWorld())) // enemy values read as zero on firstcontact, needs enemy locate to read adjesent tile's
                    {
                        //access weapons damage

                        //collide
                        //collision = true;

                        hud.Draw();
                        hud.DisplayText($"< This is a Vendor, Press 'T' to Trade >", false);

                        //if player hits "T" when colliding with a vendor it will start a trade between the two....
                        if (_playerInput.Key == ConsoleKey.T)
                        {
                            gameState = StartTrading(vendors[i].AliveInWorld(), tradeMenu, this, vendors[i], gameState, inventory);
                        }
                    }
                }

                //Door Collision / Unlocking
                for (int i = 0; i < doors.Count; i++)
                {
                    if (CheckForCharacterCollision(doors[i].X(), doors[i].Y(), doors[i].AliveInWorld()))
                    {
                        // Use Key or not
                        doors[i].OpenDoor(this, hud, inventory);

                        //collide
                        collision = true;
                    }
                }

                //toolkit.DisplayText($"checking at: {map.getTile(_XYHolder[0], _XYHolder[1])}"); //    --------- debugg
                if (!CheckForWallCollision(map.getTile(_XYHolder[0], _XYHolder[1] - 1), map.getWallHold()))
                {
                    if (!collision)
                    {
                        Move();
                    }
                }
            }

            return(gameState);
        }
Пример #7
0
 public void Draw()
 {
     hud.Draw();
     camera.DrawBorder();
 }