diff options
| -rw-r--r-- | Bitspace 2.0/Bitspace 2.0/Bitspace 2.0.csproj | 1 | ||||
| -rw-r--r-- | Bitspace 2.0/Bitspace 2.0/Game creatures/Creatures.cs | 6 | ||||
| -rw-r--r-- | Bitspace 2.0/Bitspace 2.0/Game creatures/Mob.cs | 46 | ||||
| -rw-r--r-- | Bitspace 2.0/Bitspace 2.0/Game creatures/Player.cs | 6 | ||||
| -rw-r--r-- | Bitspace 2.0/Bitspace 2.0/Game items/AmbientItem.cs | 7 | ||||
| -rw-r--r-- | Bitspace 2.0/Bitspace 2.0/Game items/Item.cs | 22 | ||||
| -rw-r--r-- | Bitspace 2.0/Bitspace 2.0/Game items/Items.cs | 29 | ||||
| -rw-r--r-- | Bitspace 2.0/Bitspace 2.0/Game items/Weapon.cs | 7 | ||||
| -rw-r--r-- | Bitspace 2.0/Bitspace 2.0/KeyBindings.cs | 9 | ||||
| -rw-r--r-- | Bitspace 2.0/Bitspace 2.0/Program.cs | 1 |
10 files changed, 106 insertions, 28 deletions
diff --git a/Bitspace 2.0/Bitspace 2.0/Bitspace 2.0.csproj b/Bitspace 2.0/Bitspace 2.0/Bitspace 2.0.csproj index 0d06311..8de2a18 100644 --- a/Bitspace 2.0/Bitspace 2.0/Bitspace 2.0.csproj +++ b/Bitspace 2.0/Bitspace 2.0/Bitspace 2.0.csproj @@ -46,6 +46,7 @@ <Compile Include="Game creatures\Animal.cs" /> <Compile Include="Game creatures\Creatures.cs" /> <Compile Include="Game items\AmbientItem.cs" /> + <Compile Include="Game items\Items.cs" /> <Compile Include="Game items\Weapon.cs" /> <Compile Include="Game map\Biome.cs" /> <Compile Include="Game creatures\Player.cs" /> diff --git a/Bitspace 2.0/Bitspace 2.0/Game creatures/Creatures.cs b/Bitspace 2.0/Bitspace 2.0/Game creatures/Creatures.cs index ed6ebd7..62c04f2 100644 --- a/Bitspace 2.0/Bitspace 2.0/Game creatures/Creatures.cs +++ b/Bitspace 2.0/Bitspace 2.0/Game creatures/Creatures.cs @@ -25,11 +25,7 @@ namespace Bitspace_2._0.Game_creatures { public static List<Mob> AllAliveNPCCreatures { get { - var toReturn = new List<Mob>(); - - toReturn.AddRange(Animals.Values.Where(x => x.IsAlive())); - - return toReturn; + return new List<Mob>(Animals.Values.Where(x => x.IsAlive())); } } } diff --git a/Bitspace 2.0/Bitspace 2.0/Game creatures/Mob.cs b/Bitspace 2.0/Bitspace 2.0/Game creatures/Mob.cs index 094e308..6ab94fa 100644 --- a/Bitspace 2.0/Bitspace 2.0/Game creatures/Mob.cs +++ b/Bitspace 2.0/Bitspace 2.0/Game creatures/Mob.cs @@ -1,4 +1,5 @@ using Bitspace_2._0.Game_map; +using Bitspace_2._0.Game_items; using System; using System.Collections.Generic; using System.Linq; @@ -26,11 +27,24 @@ namespace Bitspace_2._0.Game_creatures { public Player fightingWithPlayer { get; set; } - public Item[] ItemInventory { get; protected set; } + public Dictionary<string, int> ItemInventory { get; protected set; } + protected int inventorySize; protected int selectedItem; public string PrintInventory() { - return Inventory.PrintInventory(ItemInventory, selectedItem); + var temp = new Item[inventorySize]; + foreach(Item toAdd in Items.AllItems.Where(i => this.ItemInventory.Keys.Any(ii => ii == i.Name))) { + temp.Last(x => x == null) = toAdd; + } + return Inventory.PrintInventory(temp, selectedItem); + } + + public void PickUpItem(string name) { + ItemInventory.Add(name, Items.AllItems.First(i => i.Name == name).Quantity); + } + + public void PickUpItem(string name, int quantity) { + ItemInventory.Add(name, quantity); } public void ChooseRndMovement() { @@ -38,7 +52,32 @@ namespace Bitspace_2._0.Game_creatures { Move(randomDirection); } + + public void UseItem(string pressedKeyBinding) { + Item itemToUse = Items.AllItems.First(w => w.Name == this.ItemInventory.ElementAt(selectedItem).Key); + + if (Items.AllWeapons.Contains(itemToUse)) UseWeapon((Weapon)itemToUse, pressedKeyBinding); + } + private void UseWeapon(Weapon weaponToUse, string pressedKeyBinding) { + int wepXPos = this.XPos, wepYPos = this.YPos; + + switch (pressedKeyBinding) { + case "UseForward": if (wepYPos > Map.MinY) wepYPos--; break; + case "UseBackward": if (wepYPos < Map.MaxY) wepYPos++; break; + case "UseLeft": if (wepXPos > Map.MinX) wepXPos--; break; + case "UseRight": if (wepXPos < Map.MaxX) wepXPos++; break; + } + + if (wepXPos != this.XPos || wepYPos != this.YPos) { + Map.ItemLayer[wepYPos][wepXPos] = weaponToUse.Body; + + foreach(var cr in Creatures.AllAliveCreatures.Where(c => c.XPos == wepXPos && c.YPos == wepYPos)) { + weaponToUse.DoDirectDamage(cr); + } + } + } + protected void Move(int direction) { switch (direction) { case 1: //North @@ -137,7 +176,8 @@ namespace Bitspace_2._0.Game_creatures { this.LungCapacity = this.MaxLungCapacity = maxLungCapacity; this.Armour = this.MaxArmour = maxArmour; - this.ItemInventory = new Item[inventorySize]; + this.ItemInventory = new Dictionary<string, int>(inventorySize); + this.inventorySize = inventorySize; this.selectedItem = 0; } diff --git a/Bitspace 2.0/Bitspace 2.0/Game creatures/Player.cs b/Bitspace 2.0/Bitspace 2.0/Game creatures/Player.cs index ca798a3..9f6c010 100644 --- a/Bitspace 2.0/Bitspace 2.0/Game creatures/Player.cs +++ b/Bitspace 2.0/Bitspace 2.0/Game creatures/Player.cs @@ -14,9 +14,9 @@ namespace Bitspace_2._0.Game_creatures { case "Right": Move(4); break; } } - else if (KeyBindings.Items.ContainsValue(pressedKey)) { - switch (KeyBindings.Items.First(kp => kp.Value == pressedKey).Key) { - case "Next": if (this.selectedItem < this.ItemInventory.Length - 1) this.selectedItem++; break; + else if (KeyBindings.Inventory.ContainsValue(pressedKey)) { + switch (KeyBindings.Inventory.First(kp => kp.Value == pressedKey).Key) { + case "Next": if (this.selectedItem < this.inventorySize - 1) this.selectedItem++; break; case "Previous": if (this.selectedItem > 0) this.selectedItem--; break; } } diff --git a/Bitspace 2.0/Bitspace 2.0/Game items/AmbientItem.cs b/Bitspace 2.0/Bitspace 2.0/Game items/AmbientItem.cs index ad43337..71f53fb 100644 --- a/Bitspace 2.0/Bitspace 2.0/Game items/AmbientItem.cs +++ b/Bitspace 2.0/Bitspace 2.0/Game items/AmbientItem.cs @@ -5,6 +5,11 @@ using System.Text; using System.Threading.Tasks; namespace Bitspace_2._0.Game_items { - class AmbientItem { + public class AmbientItem : Item { + public AmbientItem(string name, char body, ConsoleColor color, int health, int maxHealth, int damage) : base(name, body, color, health, maxHealth, damage) { + } + + public AmbientItem(string name, char body, ConsoleColor color, int health, int maxHealth, int damage, bool canPlace, bool canWalkOver) : base(name, body, color, health, maxHealth, damage, canPlace, canWalkOver) { + } } } diff --git a/Bitspace 2.0/Bitspace 2.0/Game items/Item.cs b/Bitspace 2.0/Bitspace 2.0/Game items/Item.cs index 11b9a6d..2c93e75 100644 --- a/Bitspace 2.0/Bitspace 2.0/Game items/Item.cs +++ b/Bitspace 2.0/Bitspace 2.0/Game items/Item.cs @@ -1,20 +1,14 @@ -using System; -using Bitspace_2._0.Game_creatures; -using System.Collections.Generic; +using Bitspace_2._0.Game_creatures; +using System; using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Bitspace_2._0 { public abstract class Item { protected string name; protected char body; - protected int quantity; + protected int initialQuantity; public ConsoleColor Color { get; set; } - public int XPos { get; set; } - public int YPos { get; set; } - public bool CanPlace { get; protected set; } public bool CanWalkOver { get; protected set; } @@ -37,8 +31,6 @@ namespace Bitspace_2._0 { Damage = damage; CanPlace = canPlace; CanWalkOver = canWalkOver; - XPos = xPos; - YPos = yPos; } public void Repair(int repairPoints) { @@ -53,10 +45,12 @@ namespace Bitspace_2._0 { } } - public void DoDamage(Mob targetedMob) { + public void DoDirectDamage(Mob targetedMob) { targetedMob.RecieveDamage(this.Damage); } + + public bool IsNotBroken() { return this.Health > 0; } @@ -82,12 +76,12 @@ namespace Bitspace_2._0 { } public int Quantity { - get { return this.quantity; } + get { return this.initialQuantity; } set { if (value < 1) { throw new ArgumentException("Quantity of items can't be less than 1"); } - this.quantity = value; + this.initialQuantity = value; } } } diff --git a/Bitspace 2.0/Bitspace 2.0/Game items/Items.cs b/Bitspace 2.0/Bitspace 2.0/Game items/Items.cs new file mode 100644 index 0000000..14e2739 --- /dev/null +++ b/Bitspace 2.0/Bitspace 2.0/Game items/Items.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Bitspace_2._0.Game_items { + static class Items { + private static Dictionary<string, Weapon> Weapons = new Dictionary<string, Weapon>() { + { "Stick", new Weapon("Stick", '|', ConsoleColor.Gray, 1, 1, 1) } + }; + + public static List<Weapon> AllWeapons { + get { + return new List<Weapon>(Weapons.Values); + } + } + + public static List<Item> AllItems { + get { + List<Item> toReturn = new List<Item>(); + + toReturn.AddRange(AllWeapons); + + return toReturn; + } + } + } +} diff --git a/Bitspace 2.0/Bitspace 2.0/Game items/Weapon.cs b/Bitspace 2.0/Bitspace 2.0/Game items/Weapon.cs index 2b729e3..4c37acb 100644 --- a/Bitspace 2.0/Bitspace 2.0/Game items/Weapon.cs +++ b/Bitspace 2.0/Bitspace 2.0/Game items/Weapon.cs @@ -5,6 +5,11 @@ using System.Text; using System.Threading.Tasks; namespace Bitspace_2._0.Game_items { - class Weapon { + public class Weapon : Item { + public Weapon(string name, char body, ConsoleColor color, int health, int maxHealth, int damage) : base(name, body, color, health, maxHealth, damage) { + } + + public Weapon(string name, char body, ConsoleColor color, int health, int maxHealth, int damage, bool canPlace, bool canWalkOver) : base(name, body, color, health, maxHealth, damage, canPlace, canWalkOver) { + } } } diff --git a/Bitspace 2.0/Bitspace 2.0/KeyBindings.cs b/Bitspace 2.0/Bitspace 2.0/KeyBindings.cs index 6f325ec..fb5ec69 100644 --- a/Bitspace 2.0/Bitspace 2.0/KeyBindings.cs +++ b/Bitspace 2.0/Bitspace 2.0/KeyBindings.cs @@ -10,9 +10,16 @@ namespace Bitspace_2._0 { { "Right", ConsoleKey.D } }; - public static Dictionary<string, ConsoleKey> Items = new Dictionary<string, ConsoleKey>() { + public static Dictionary<string, ConsoleKey> Inventory = new Dictionary<string, ConsoleKey>() { { "Next", ConsoleKey.E }, { "Previous", ConsoleKey.Q } }; + + public static Dictionary<string, ConsoleKey> Item = new Dictionary<string, ConsoleKey>() { + { "UseForward", ConsoleKey.UpArrow }, + { "UseBackward", ConsoleKey.DownArrow }, + { "UseLeft", ConsoleKey.LeftArrow }, + { "UseRight", ConsoleKey.RightArrow } + }; } } diff --git a/Bitspace 2.0/Bitspace 2.0/Program.cs b/Bitspace 2.0/Bitspace 2.0/Program.cs index e738084..01c15e2 100644 --- a/Bitspace 2.0/Bitspace 2.0/Program.cs +++ b/Bitspace 2.0/Bitspace 2.0/Program.cs @@ -14,6 +14,7 @@ namespace Bitspace_2._0 { Menu.StartMenu(); Console.Clear(); + Creatures.Players["Player1"].ItemInventory.Add("Stick", 1); for (ulong gameTick = 0; ; gameTick++, Thread.Sleep(80)) { if (Console.KeyAvailable) { if (Creatures.Players.Count(p => p.Value.IsAlive()) > 0) { |
