diff options
| author | Syndamia <kami02882@gmail.com> | 2019-09-14 09:31:07 +0300 |
|---|---|---|
| committer | Syndamia <kami02882@gmail.com> | 2019-09-14 09:31:07 +0300 |
| commit | 3967e21a428281bc6a8df364f70c451b93ef9e7a (patch) | |
| tree | 6d8f069141d343732bd1e92077a2a845d8e06e37 | |
| parent | b58c57715f5bf24b08d5e7488bd209fb9b539628 (diff) | |
| download | Shower-3967e21a428281bc6a8df364f70c451b93ef9e7a.tar Shower-3967e21a428281bc6a8df364f70c451b93ef9e7a.tar.gz Shower-3967e21a428281bc6a8df364f70c451b93ef9e7a.zip | |
Did issue #54, Inventory is fully implimented
| -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/Animal.cs | 10 | ||||
| -rw-r--r-- | Bitspace 2.0/Bitspace 2.0/Game creatures/Mob.cs | 22 | ||||
| -rw-r--r-- | Bitspace 2.0/Bitspace 2.0/Game creatures/Player.cs | 16 | ||||
| -rw-r--r-- | Bitspace 2.0/Bitspace 2.0/Game items/Item.cs | 16 | ||||
| -rw-r--r-- | Bitspace 2.0/Bitspace 2.0/Graphics.cs | 1 | ||||
| -rw-r--r-- | Bitspace 2.0/Bitspace 2.0/Inventory.cs | 71 | ||||
| -rw-r--r-- | Bitspace 2.0/Bitspace 2.0/KeyBindings.cs | 5 |
8 files changed, 122 insertions, 20 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 7883116..f388bf7 100644 --- a/Bitspace 2.0/Bitspace 2.0/Bitspace 2.0.csproj +++ b/Bitspace 2.0/Bitspace 2.0/Bitspace 2.0.csproj @@ -51,6 +51,7 @@ <Compile Include="Game creatures\Player.cs" /> <Compile Include="Graphics.cs" /> <Compile Include="Game items\Item.cs" /> + <Compile Include="Inventory.cs" /> <Compile Include="KeyBindings.cs" /> <Compile Include="Game map\Map.cs" /> <Compile Include="Game creatures\Mob.cs" /> diff --git a/Bitspace 2.0/Bitspace 2.0/Game creatures/Animal.cs b/Bitspace 2.0/Bitspace 2.0/Game creatures/Animal.cs index bdfe09b..b337a50 100644 --- a/Bitspace 2.0/Bitspace 2.0/Game creatures/Animal.cs +++ b/Bitspace 2.0/Bitspace 2.0/Game creatures/Animal.cs @@ -7,15 +7,15 @@ using System.Threading.Tasks; namespace Bitspace_2._0.Game_creatures { public class Animal : Mob { public Animal(string name, char body, ConsoleColor color, int maxHealth) - : base(name, body, color, 20, maxHealth, 10, 0) { } + : base(name, body, color, 20, maxHealth, 10, 0, 1) { } public Animal(string name, char body, ConsoleColor color, int maxHealth, int maxLungCapacity) - : base(name, body, color, 20, maxHealth, maxLungCapacity, 0) { } + : base(name, body, color, 20, maxHealth, maxLungCapacity, 0, 1) { } public Animal(string name, char body, ConsoleColor color, int defaultMovementFactor, int maxHealth, int maxLungCapacity) - : base(name, body, color, defaultMovementFactor, maxHealth, maxLungCapacity, 0) { } + : base(name, body, color, defaultMovementFactor, maxHealth, maxLungCapacity, 0, 1) { } - public Animal(string name, char body, ConsoleColor color, int defaultMovementFactor, int maxHealth, int maxLungCapacity, int maxArmour) - : base(name, body, color, defaultMovementFactor, maxHealth, maxLungCapacity, maxArmour) { } + public Animal(string name, char body, ConsoleColor color, int defaultMovementFactor, int maxHealth, int maxLungCapacity, int maxArmour, int inventorySize) + : base(name, body, color, defaultMovementFactor, maxHealth, maxLungCapacity, maxArmour, inventorySize) { } } } 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 97f7d50..497c418 100644 --- a/Bitspace 2.0/Bitspace 2.0/Game creatures/Mob.cs +++ b/Bitspace 2.0/Bitspace 2.0/Game creatures/Mob.cs @@ -8,8 +8,8 @@ namespace Bitspace_2._0.Game_creatures { abstract public class Mob { //short for mobile object protected static Random rndNum = new Random(); //the random class uses certain patters to it's randomness, this way it adds "another layer to the randomness" - public string name; - public char body; + protected string name; + protected char body; public ConsoleColor Color { get; set; } public int XPos { get; set; } @@ -26,7 +26,12 @@ namespace Bitspace_2._0.Game_creatures { public Player fightingWithPlayer { get; set; } - public List<Item> Inventory { get; protected set; } + public Item[] ItemInventory { get; protected set; } + protected int selectedItem; + + public string PrintInventory() { + return Inventory.PrintInventory(ItemInventory, selectedItem); + } public void ChooseRndMovement() { var randomDirection = rndNum.Next(MovementFactor); //the bigger it is, the less chance for a mob to move from it's current position @@ -108,15 +113,15 @@ namespace Bitspace_2._0.Game_creatures { } public Mob (string name, char body, ConsoleColor color, int maxHealth) - : this(name, body, color, 20, maxHealth, 10, 0) { } + : this(name, body, color, 20, maxHealth, 10, 0, 3) { } public Mob (string name, char body, ConsoleColor color, int maxHealth, int maxLungCapacity) - : this(name, body, color, 20, maxHealth, maxLungCapacity, 0) { } + : this(name, body, color, 20, maxHealth, maxLungCapacity, 0, 3) { } public Mob(string name, char body, ConsoleColor color, int defaultMovementFactor, int maxHealth, int maxLungCapacity) - : this(name, body, color, defaultMovementFactor, maxHealth, maxLungCapacity, 0) { } + : this(name, body, color, defaultMovementFactor, maxHealth, maxLungCapacity, 0, 3) { } - public Mob (string name, char body, ConsoleColor color, int defaultMovementFactor, int maxHealth, int maxLungCapacity, int maxArmour) { + public Mob (string name, char body, ConsoleColor color, int defaultMovementFactor, int maxHealth, int maxLungCapacity, int maxArmour, int inventorySize) { this.Name = name; this.Body = body; this.Color = color; @@ -128,7 +133,8 @@ namespace Bitspace_2._0.Game_creatures { this.LungCapacity = this.MaxLungCapacity = maxLungCapacity; this.Armour = this.MaxArmour = maxArmour; - this.Inventory = new List<Item>(); + this.ItemInventory = new Item[inventorySize]; + this.selectedItem = 0; } public override string ToString() { 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 77acb57..ca798a3 100644 --- a/Bitspace 2.0/Bitspace 2.0/Game creatures/Player.cs +++ b/Bitspace 2.0/Bitspace 2.0/Game creatures/Player.cs @@ -14,19 +14,27 @@ 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; + case "Previous": if (this.selectedItem > 0) this.selectedItem--; break; + } + } } public Player(string name, char body, ConsoleColor color, int maxHealth) - : base(name, body, color, 20, maxHealth, 10, 0) { } + : base(name, body, color, 20, maxHealth, 10, 0, 10) { } public Player(string name, char body, ConsoleColor color, int maxHealth, int maxLungCapacity) - : base(name, body, color, 20, maxHealth, maxLungCapacity, 0) { } + : base(name, body, color, 20, maxHealth, maxLungCapacity, 0, 10) { } public Player(string name, char body, ConsoleColor color, int defaultMovementFactor, int maxHealth, int maxLungCapacity) - : base(name, body, color, defaultMovementFactor, maxHealth, maxLungCapacity, 0) { } + : base(name, body, color, defaultMovementFactor, maxHealth, maxLungCapacity, 0, 10) { } public Player(string name, char body, ConsoleColor color, int defaultMovementFactor, int maxHealth, int maxLungCapacity, int maxArmour) - : base(name, body, color, defaultMovementFactor, maxHealth, maxLungCapacity, maxArmour) { } + : base(name, body, color, defaultMovementFactor, maxHealth, maxLungCapacity, maxArmour, 10) { } + public Player(string name, char body, ConsoleColor color, int defaultMovementFactor, int maxHealth, int maxLungCapacity, int maxArmour, int inventorySize) + : base(name, body, color, defaultMovementFactor, maxHealth, maxLungCapacity, maxArmour, inventorySize) { } } } 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 ff67802..11b9a6d 100644 --- a/Bitspace 2.0/Bitspace 2.0/Game items/Item.cs +++ b/Bitspace 2.0/Bitspace 2.0/Game items/Item.cs @@ -7,9 +7,9 @@ using System.Threading.Tasks; namespace Bitspace_2._0 { public abstract class Item { - public string name; - public char body; - public int quantity; + protected string name; + protected char body; + protected int quantity; public ConsoleColor Color { get; set; } public int XPos { get; set; } @@ -80,5 +80,15 @@ namespace Bitspace_2._0 { this.body = value; } } + + public int Quantity { + get { return this.quantity; } + set { + if (value < 1) { + throw new ArgumentException("Quantity of items can't be less than 1"); + } + this.quantity = value; + } + } } } diff --git a/Bitspace 2.0/Bitspace 2.0/Graphics.cs b/Bitspace 2.0/Bitspace 2.0/Graphics.cs index d9fa4cb..fdf52bd 100644 --- a/Bitspace 2.0/Bitspace 2.0/Graphics.cs +++ b/Bitspace 2.0/Bitspace 2.0/Graphics.cs @@ -43,6 +43,7 @@ namespace Bitspace_2._0 { foreach(var currPlayer in Creatures.Players.Values) { Console.WriteLine(currPlayer); + Console.WriteLine(currPlayer.PrintInventory()); foreach(var fightingWithPlayer in Creatures.AllAliveCreatures.Where(c => c.fightingWithPlayer == currPlayer)) { Console.WriteLine(" " + fightingWithPlayer); diff --git a/Bitspace 2.0/Bitspace 2.0/Inventory.cs b/Bitspace 2.0/Bitspace 2.0/Inventory.cs new file mode 100644 index 0000000..7b644b3 --- /dev/null +++ b/Bitspace 2.0/Bitspace 2.0/Inventory.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Bitspace_2._0 { + public static class Inventory { + public static string PrintInventory(Item[] items, int selectedItem) { + StringBuilder toReturn = new StringBuilder(); + + toReturn.Append(PrintTopOrBot(true, items, selectedItem)); + toReturn.Append(PrintMid(items, selectedItem)); + toReturn.Append(PrintTopOrBot(false, items, selectedItem)); + + return toReturn.ToString(); + } + + private static string PrintMid(Item[] items, int selectedItem) { + StringBuilder toReturn = new StringBuilder(); + + for (int row = 0; row < 2; row++, toReturn.AppendLine()) { + toReturn.Append("│"); + + for (int i = 0; i < items.Length; i++) { + switch(row) { + case 0: + if (items[i] != null) { + toReturn.Append(" " + items[i].Body + " │"); + continue; + } break; + case 1: + if (items[i] != null) { + if (items[i].Quantity > 1) { + switch(items[i].Quantity.ToString().Length) { + case 1: toReturn.Append(" " + items[i].Quantity + " │"); break; + case 2: toReturn.Append(" " + items[i].Quantity + "│"); break; + case 3: toReturn.Append(items[i].Quantity + "│"); break; + } continue; + } + } break; + } + toReturn.Append(" │"); + } + } + return toReturn.ToString(); + } + + private static string PrintTopOrBot(bool printTop, Item[] items, int selectedItem) { + StringBuilder toReturn = new StringBuilder(); + + if (printTop) toReturn.Append("┌"); + else toReturn.Append("└"); + + for (int i = 0; i < items.Length ; i++) { + if (selectedItem == i) { + toReturn.Append("***"); + } else { + toReturn.Append("───"); + } + + if (i + 1 < items.Length) toReturn.Append("─"); + } + + if (printTop) toReturn.AppendLine("┐"); + else toReturn.AppendLine("┘"); + + return toReturn.ToString(); + } + } +} diff --git a/Bitspace 2.0/Bitspace 2.0/KeyBindings.cs b/Bitspace 2.0/Bitspace 2.0/KeyBindings.cs index 61d585c..6f325ec 100644 --- a/Bitspace 2.0/Bitspace 2.0/KeyBindings.cs +++ b/Bitspace 2.0/Bitspace 2.0/KeyBindings.cs @@ -9,5 +9,10 @@ namespace Bitspace_2._0 { { "Left", ConsoleKey.A }, { "Right", ConsoleKey.D } }; + + public static Dictionary<string, ConsoleKey> Items = new Dictionary<string, ConsoleKey>() { + { "Next", ConsoleKey.E }, + { "Previous", ConsoleKey.Q } + }; } } |
