From 6f243ec658ec3761a03df15d4a01cf248c7cb0b6 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 12 Sep 2019 20:42:03 +0300 Subject: Did work on issues #48 (finished), #52 (finished) and #56 (whole) --- .../Bitspace 2.0/Game creatures/Creatures.cs | 23 +++++++++++++----- Bitspace 2.0/Bitspace 2.0/Game creatures/Mob.cs | 15 ++++++++---- Bitspace 2.0/Bitspace 2.0/Game map/Map.cs | 3 +-- Bitspace 2.0/Bitspace 2.0/Graphics.cs | 28 ++++++++++++++++++---- Bitspace 2.0/Bitspace 2.0/Program.cs | 21 ++++++++++++++-- 5 files changed, 70 insertions(+), 20 deletions(-) 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 8d81dc6..ed6ebd7 100644 --- a/Bitspace 2.0/Bitspace 2.0/Game creatures/Creatures.cs +++ b/Bitspace 2.0/Bitspace 2.0/Game creatures/Creatures.cs @@ -1,25 +1,36 @@ using Bitspace_2._0.Game_creatures; using System; +using System.Linq; using System.Collections.Generic; namespace Bitspace_2._0.Game_creatures { - public static class Creatures { //when adding new collections, update Graphics.Update() + public static class Creatures { //when adding new collections, update properties at the bottom public static Dictionary Players = new Dictionary() { { "Player1", new Player("The player", '@', ConsoleColor.White, 10) } }; public static Dictionary Animals = new Dictionary() { - { "Smiley", new Animal("Smiley", 'U', ConsoleColor.Magenta, 5) } + { "Smiley", new Animal("Smiley", 'U', ConsoleColor.Magenta, 3) } }; - public static void DoToAll(Action action) { - foreach(var pl in Players.Values) { - action.Invoke(); + public static List AllAliveCreatures { + get { + var toReturn = AllAliveNPCCreatures; + + toReturn.AddRange(Players.Values.Where(x => x.IsAlive())); + + return toReturn; } } - public static void DoToAllNonPlayers(Action action) { + public static List AllAliveNPCCreatures { + get { + var toReturn = new List(); + toReturn.AddRange(Animals.Values.Where(x => x.IsAlive())); + + return toReturn; + } } } } 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 544e8bd..e8ec8c9 100644 --- a/Bitspace 2.0/Bitspace 2.0/Game creatures/Mob.cs +++ b/Bitspace 2.0/Bitspace 2.0/Game creatures/Mob.cs @@ -22,7 +22,7 @@ namespace Bitspace_2._0.Game_creatures { public int Armour { get; protected set; } public int MaxArmour { get; protected set; } - public void MoveRandomly() { + 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 Move(randomDirection); @@ -45,7 +45,7 @@ namespace Bitspace_2._0.Game_creatures { } } - public void AffectedByBiome(Biome currBiome) { + public void GetAffectedByBiome(Biome currBiome) { this.Heal(currBiome.HealPoints); if (this.CanSuffocate()) this.Suffocate(); @@ -61,10 +61,15 @@ namespace Bitspace_2._0.Game_creatures { public void RecieveDamage(int points) { if (IsAlive()) { - if (points > this.Armour / 4) { //all damage under a fourth of the armor doesn't affect mob + if (this.Armour > 0 && points > this.Armour / 4) { //all damage under a fourth of the armor doesn't affect mob this.Armour -= 2 / 3 * points; - //this.Health -= Math.Ceiling(Convert.ToDecimal(1.0 / 3.0 * points)); - } + this.Health -= (int)Math.Ceiling(1M / 3 * points); + + if (this.Armour < 0) { + this.Health += this.Armour; //health will go down because a + -b <=> a - b + this.Armour = 0; + } + } else this.Health -= points; } } diff --git a/Bitspace 2.0/Bitspace 2.0/Game map/Map.cs b/Bitspace 2.0/Bitspace 2.0/Game map/Map.cs index a012185..24902f2 100644 --- a/Bitspace 2.0/Bitspace 2.0/Game map/Map.cs +++ b/Bitspace 2.0/Bitspace 2.0/Game map/Map.cs @@ -15,7 +15,7 @@ namespace Bitspace_2._0.Game_map { public static int MinY = 0; public static int MaxY; - private static Dictionary biomeDB = new Dictionary() { + public static Dictionary biomeDB = new Dictionary() { { "Grass", new Biome("Grass", ',', ConsoleColor.Green, 0, 1) }, { "Water", new Biome("Water", '-', ConsoleColor.Blue, true, 1, 0) }, { "Lava", new Biome("Lava", '#', ConsoleColor.Red, 2, 0) } @@ -103,7 +103,6 @@ namespace Bitspace_2._0.Game_map { foreach (var row in World) { toReturn.AppendLine(row.ToString()); } - return toReturn.ToString(); } } diff --git a/Bitspace 2.0/Bitspace 2.0/Graphics.cs b/Bitspace 2.0/Bitspace 2.0/Graphics.cs index baa9f94..480125e 100644 --- a/Bitspace 2.0/Bitspace 2.0/Graphics.cs +++ b/Bitspace 2.0/Bitspace 2.0/Graphics.cs @@ -8,15 +8,33 @@ using System.Threading.Tasks; namespace Bitspace_2._0 { static class Graphics { + public static bool Mono = false; + public static void ReWriteScreen() { Console.Clear(); - Update(); + UpdateLayers(); - Console.WriteLine(Map.StringWorld); + if (Mono) Console.WriteLine(Map.StringWorld); + else { + foreach(var row in Map.World) { + foreach(var character in row.ToString()) + { + if (Map.biomeDB.Any(b => b.Value.Ground == character)) { + Console.ForegroundColor = Map.biomeDB.Values.First(b => b.Ground == character).Color; + } + else if (Creatures.AllAliveCreatures.Any(c => c.Body == character)) { + Console.ForegroundColor = Creatures.AllAliveCreatures.First(c => c.Body == character).Color; + } + Console.Write(character); + } + Console.WriteLine(); + } + Console.WriteLine(Creatures.Players["Player1"]); + } } - private static void Update() { + private static void UpdateLayers() { UpdateMobLayer(); //UpdateItemLayer(); } @@ -24,8 +42,8 @@ namespace Bitspace_2._0 { private static void UpdateMobLayer() { Map.ClearLayer("MobLayer"); - foreach(var pl in Creatures.Players.Values) { - Map.MobLayer[pl.YPos][pl.XPos] = pl.Body; + foreach(var cr in Creatures.AllAliveCreatures) { + Map.MobLayer[cr.YPos][cr.XPos] = cr.Body; } } } diff --git a/Bitspace 2.0/Bitspace 2.0/Program.cs b/Bitspace 2.0/Bitspace 2.0/Program.cs index 6cbaf76..95fd7b4 100644 --- a/Bitspace 2.0/Bitspace 2.0/Program.cs +++ b/Bitspace 2.0/Bitspace 2.0/Program.cs @@ -15,15 +15,32 @@ namespace Bitspace_2._0 { for (ulong gameTick = 0; ; gameTick++, Thread.Sleep(70)) { if (Console.KeyAvailable) { - Creatures.Players["Player1"].InputAction(); + if (Creatures.Players.Count(p => p.Value.IsAlive()) > 0) { + Creatures.Players["Player1"].InputAction(); + } else { + break; + } } if (gameTick % 2 == 0) { - foreach (var currMob in ) + if (Creatures.AllAliveNPCCreatures.Count() > 0) { + foreach (var currNPC in Creatures.AllAliveNPCCreatures) { + currNPC.ChooseRndMovement(); + } + } + } + + if (gameTick % 3 == 0) { + if (Creatures.AllAliveCreatures.Count() > 0) { + foreach (var currCreature in Creatures.AllAliveCreatures) { + currCreature.GetAffectedByBiome(Map.biomeDB.Values.First(b => b.Ground == Map.MapLayer[currCreature.YPos][currCreature.XPos])); + } + } } Graphics.ReWriteScreen(); } + Console.WriteLine("GAME OVER"); } } } -- cgit v1.2.3 From b58c57715f5bf24b08d5e7488bd209fb9b539628 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Fri, 13 Sep 2019 17:12:17 +0300 Subject: Finished issues #51 and #57, laid foundations for issue #54 (Item.cs) and did overall a lot of tiny code corrections --- Bitspace 2.0/Bitspace 2.0/Bitspace 2.0.csproj | 3 + Bitspace 2.0/Bitspace 2.0/Game creatures/Mob.cs | 66 ++++++++++++----- .../Bitspace 2.0/Game items/AmbientItem.cs | 10 +++ Bitspace 2.0/Bitspace 2.0/Game items/Item.cs | 84 ++++++++++++++++++++++ Bitspace 2.0/Bitspace 2.0/Game items/Weapon.cs | 10 +++ Bitspace 2.0/Bitspace 2.0/Game map/Map.cs | 17 ++--- Bitspace 2.0/Bitspace 2.0/Graphics.cs | 40 +++++++---- Bitspace 2.0/Bitspace 2.0/Program.cs | 6 +- 8 files changed, 194 insertions(+), 42 deletions(-) create mode 100644 Bitspace 2.0/Bitspace 2.0/Game items/AmbientItem.cs create mode 100644 Bitspace 2.0/Bitspace 2.0/Game items/Item.cs create mode 100644 Bitspace 2.0/Bitspace 2.0/Game items/Weapon.cs 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 d66a26e..7883116 100644 --- a/Bitspace 2.0/Bitspace 2.0/Bitspace 2.0.csproj +++ b/Bitspace 2.0/Bitspace 2.0/Bitspace 2.0.csproj @@ -45,9 +45,12 @@ + + + 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 e8ec8c9..97f7d50 100644 --- a/Bitspace 2.0/Bitspace 2.0/Game creatures/Mob.cs +++ b/Bitspace 2.0/Bitspace 2.0/Game creatures/Mob.cs @@ -1,14 +1,16 @@ using Bitspace_2._0.Game_map; using System; +using System.Collections.Generic; using System.Linq; +using System.Text; 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 will always give a "random" number + 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; - public ConsoleColor Color { get; protected set; } + public ConsoleColor Color { get; set; } public int XPos { get; set; } public int YPos { get; set; } @@ -22,6 +24,10 @@ namespace Bitspace_2._0.Game_creatures { public int Armour { get; protected set; } public int MaxArmour { get; protected set; } + public Player fightingWithPlayer { get; set; } + + public List Inventory { get; protected set; } + 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 @@ -48,17 +54,34 @@ namespace Bitspace_2._0.Game_creatures { public void GetAffectedByBiome(Biome currBiome) { this.Heal(currBiome.HealPoints); - if (this.CanSuffocate()) this.Suffocate(); - else this.RecieveDamage(currBiome.DamagePoints); + if (currBiome.Suffocate) this.Suffocate(); + else this.TakeBreather(); + + RecieveDamage(currBiome.DamagePoints); } public void Heal(int points) { - if (this.Health < this.MaxHealth) { + if (this.Health < this.MaxHealth && IsAlive()) { Health += points; if (this.Health > this.MaxHealth) Health = MaxHealth; } } + public void TakeBreather() { + if (IsAlive() && LungCapacity < MaxLungCapacity) { + LungCapacity++; + } + } + + public void Suffocate() { + if (this.LungCapacity > 0) { + this.LungCapacity--; + } + else if (IsAlive()) { + LooseHealth(1); + } + } + public void RecieveDamage(int points) { if (IsAlive()) { if (this.Armour > 0 && points > this.Armour / 4) { //all damage under a fourth of the armor doesn't affect mob @@ -66,27 +89,22 @@ namespace Bitspace_2._0.Game_creatures { this.Health -= (int)Math.Ceiling(1M / 3 * points); if (this.Armour < 0) { - this.Health += this.Armour; //health will go down because a + -b <=> a - b + this.Health += this.Armour; //health will go down because a + -b = a - b this.Armour = 0; } - } else this.Health -= points; + } + else LooseHealth(points); } } - public void Suffocate() { - if (this.LungCapacity > 0) { - this.LungCapacity--; - - if (this.LungCapacity < 0) this.LungCapacity = 0; + public void LooseHealth(int points) { + if (IsAlive()) { + this.Health -= points; } } public bool IsAlive() { - return (this.Health > 0) ? true : false; - } - - public bool CanSuffocate() { - return (this.LungCapacity > 0) ? true : false; + return this.Health > 0; } public Mob (string name, char body, ConsoleColor color, int maxHealth) @@ -109,11 +127,21 @@ namespace Bitspace_2._0.Game_creatures { this.Health = this.MaxHealth = maxHealth; this.LungCapacity = this.MaxLungCapacity = maxLungCapacity; this.Armour = this.MaxArmour = maxArmour; + + this.Inventory = new List(); } public override string ToString() { - return $"{this.Name} | Health: {this.Health} | Armour: {this.Armour} | Air: {new string('O', this.LungCapacity)}\r\n" + - $"X: {this.XPos} | Y: {this.YPos}"; + return $"{this.Name} | Health: {this.Health} | Armour: {this.Armour} | Air: {GenerateBreatheBar()} || X: {this.XPos} | Y: {this.YPos}"; + } + + private string GenerateBreatheBar() { + var toReturn = new StringBuilder(new string('O', this.LungCapacity)); + + for (int i = this.LungCapacity; i < this.MaxLungCapacity; i++) { + toReturn.Append(' '); + } + return toReturn.ToString(); } public string Name { diff --git a/Bitspace 2.0/Bitspace 2.0/Game items/AmbientItem.cs b/Bitspace 2.0/Bitspace 2.0/Game items/AmbientItem.cs new file mode 100644 index 0000000..ad43337 --- /dev/null +++ b/Bitspace 2.0/Bitspace 2.0/Game items/AmbientItem.cs @@ -0,0 +1,10 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Bitspace_2._0.Game_items { + class AmbientItem { + } +} diff --git a/Bitspace 2.0/Bitspace 2.0/Game items/Item.cs b/Bitspace 2.0/Bitspace 2.0/Game items/Item.cs new file mode 100644 index 0000000..ff67802 --- /dev/null +++ b/Bitspace 2.0/Bitspace 2.0/Game items/Item.cs @@ -0,0 +1,84 @@ +using System; +using Bitspace_2._0.Game_creatures; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Bitspace_2._0 { + public abstract class Item { + public string name; + public char body; + public int quantity; + 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; } + + public int Health { get; set; } + public int MaxHealth { get; protected set; } + public int Damage { get; private set; } + + protected Item(string name, char body, ConsoleColor color, int health, int maxHealth, int damage) + :this(name, body, color, health, maxHealth, damage, false, false, 0, 0) { } + + protected Item(string name, char body, ConsoleColor color, int health, int maxHealth, int damage, bool canPlace, bool canWalkOver) + : this(name, body, color, health, maxHealth, damage, canPlace, canWalkOver, 0, 0) { } + + protected Item(string name, char body, ConsoleColor color, int health, int maxHealth, int damage, bool canPlace, bool canWalkOver, int xPos, int yPos) { + Name = name; + Body = body; + Color = color; + Health = health; + MaxHealth = maxHealth; + Damage = damage; + CanPlace = canPlace; + CanWalkOver = canWalkOver; + XPos = xPos; + YPos = yPos; + } + + public void Repair(int repairPoints) { + this.Health += repairPoints; + + if (this.Health > this.MaxHealth) this.Health = this.MaxHealth; + } + + public void RecieveDamage(int amount) { + if (IsNotBroken()) { + this.Health -= amount; + } + } + + public void DoDamage(Mob targetedMob) { + targetedMob.RecieveDamage(this.Damage); + } + + public bool IsNotBroken() { + return this.Health > 0; + } + + public string Name { + get { return this.name; } + protected set { + if (!value.Any(c => (c > 47 && c < 58) || (c > 64 && c < 91) || (c > 96 && c < 123) || c == ' ')) { + throw new ArgumentException("Item name can be composed only of small letters, big letters, numbers and spaces."); + } + this.name = value; + } + } + + public char Body { + get { return this.body; } + protected set { + if (value < 33 || value > 126) { //TODO: limit it even more (in the end) + throw new ArgumentException("Body character can only be from the ASCII printable characters (from 32 to 126), without the space character (32)"); + } + this.body = value; + } + } + } +} diff --git a/Bitspace 2.0/Bitspace 2.0/Game items/Weapon.cs b/Bitspace 2.0/Bitspace 2.0/Game items/Weapon.cs new file mode 100644 index 0000000..2b729e3 --- /dev/null +++ b/Bitspace 2.0/Bitspace 2.0/Game items/Weapon.cs @@ -0,0 +1,10 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Bitspace_2._0.Game_items { + class Weapon { + } +} diff --git a/Bitspace 2.0/Bitspace 2.0/Game map/Map.cs b/Bitspace 2.0/Bitspace 2.0/Game map/Map.cs index 24902f2..bf4a6fd 100644 --- a/Bitspace 2.0/Bitspace 2.0/Game map/Map.cs +++ b/Bitspace 2.0/Bitspace 2.0/Game map/Map.cs @@ -15,10 +15,11 @@ namespace Bitspace_2._0.Game_map { public static int MinY = 0; public static int MaxY; - public static Dictionary biomeDB = new Dictionary() { + public static Dictionary Biomes = new Dictionary() { { "Grass", new Biome("Grass", ',', ConsoleColor.Green, 0, 1) }, - { "Water", new Biome("Water", '-', ConsoleColor.Blue, true, 1, 0) }, - { "Lava", new Biome("Lava", '#', ConsoleColor.Red, 2, 0) } + { "Water", new Biome("Water", '-', ConsoleColor.Blue, true, 0, 0) }, + { "Lava", new Biome("Lava", '#', ConsoleColor.Red, true, 5, 0) }, + { "Rock_spikes", new Biome("Rock_spikes", ';', ConsoleColor.Gray, 2, 1) } }; public static void Generate(int width, int height) { @@ -62,16 +63,16 @@ namespace Bitspace_2._0.Game_map { Biome currBiome; if (randomNumber.Next(4) > 0) { // 3/4 chance that the biome will not hurt and will not suffocate - currBiome = biomeDB.Values.Where(x => x.DamagePoints == 0).ElementAt(randomNumber.Next(biomeDB.Values.Count(x => x.DamagePoints == 0))); + currBiome = Biomes.Values.Where(x => x.DamagePoints == 0).ElementAt(randomNumber.Next(Biomes.Values.Count(x => x.DamagePoints == 0))); } else { if (randomNumber.Next(5) > 0) { // 4/5 chance that the biome will hurt and suffocate - currBiome = biomeDB.Values.Where(x => x.DamagePoints > 0 && x.Suffocate) - .ElementAt(randomNumber.Next(biomeDB.Values.Count(x => x.DamagePoints > 0 && x.Suffocate))); + currBiome = Biomes.Values.Where(x => x.DamagePoints > 0 && x.Suffocate) + .ElementAt(randomNumber.Next(Biomes.Values.Count(x => x.DamagePoints > 0 && x.Suffocate))); } else { // 1/5 chance that the biome will hurt but won't suffocate - currBiome = biomeDB.Values.Where(x => x.DamagePoints > 0 && !x.Suffocate) - .ElementAt(randomNumber.Next(biomeDB.Values.Count(x => x.DamagePoints > 0 && !x.Suffocate))); + currBiome = Biomes.Values.Where(x => x.DamagePoints > 0 && !x.Suffocate) + .ElementAt(randomNumber.Next(Biomes.Values.Count(x => x.DamagePoints > 0 && !x.Suffocate))); } } return currBiome; diff --git a/Bitspace 2.0/Bitspace 2.0/Graphics.cs b/Bitspace 2.0/Bitspace 2.0/Graphics.cs index 480125e..d9fa4cb 100644 --- a/Bitspace 2.0/Bitspace 2.0/Graphics.cs +++ b/Bitspace 2.0/Bitspace 2.0/Graphics.cs @@ -17,20 +17,36 @@ namespace Bitspace_2._0 { if (Mono) Console.WriteLine(Map.StringWorld); else { - foreach(var row in Map.World) { - foreach(var character in row.ToString()) - { - if (Map.biomeDB.Any(b => b.Value.Ground == character)) { - Console.ForegroundColor = Map.biomeDB.Values.First(b => b.Ground == character).Color; - } - else if (Creatures.AllAliveCreatures.Any(c => c.Body == character)) { - Console.ForegroundColor = Creatures.AllAliveCreatures.First(c => c.Body == character).Color; - } - Console.Write(character); + PrintWorld(); + + PrintMobInfo(); + } + } + + private static void PrintWorld() { + foreach (var row in Map.World) { + foreach (var character in row.ToString()) { + if (Map.Biomes.Any(b => b.Value.Ground == character)) { + Console.ForegroundColor = Map.Biomes.Values.First(b => b.Ground == character).Color; + } + else if (Creatures.AllAliveCreatures.Any(c => c.Body == character)) { + Console.ForegroundColor = Creatures.AllAliveCreatures.First(c => c.Body == character).Color; } - Console.WriteLine(); + Console.Write(character); + } + Console.WriteLine(); + } + } + + private static void PrintMobInfo() { + Console.ForegroundColor = ConsoleColor.Gray; + + foreach(var currPlayer in Creatures.Players.Values) { + Console.WriteLine(currPlayer); + + foreach(var fightingWithPlayer in Creatures.AllAliveCreatures.Where(c => c.fightingWithPlayer == currPlayer)) { + Console.WriteLine(" " + fightingWithPlayer); } - Console.WriteLine(Creatures.Players["Player1"]); } } diff --git a/Bitspace 2.0/Bitspace 2.0/Program.cs b/Bitspace 2.0/Bitspace 2.0/Program.cs index 95fd7b4..ccad6c6 100644 --- a/Bitspace 2.0/Bitspace 2.0/Program.cs +++ b/Bitspace 2.0/Bitspace 2.0/Program.cs @@ -13,10 +13,10 @@ namespace Bitspace_2._0 { Map.Generate(20, 10); Console.CursorVisible = false; - for (ulong gameTick = 0; ; gameTick++, Thread.Sleep(70)) { + for (ulong gameTick = 0; ; gameTick++, Thread.Sleep(80)) { if (Console.KeyAvailable) { if (Creatures.Players.Count(p => p.Value.IsAlive()) > 0) { - Creatures.Players["Player1"].InputAction(); + Creatures.Players["Player1"].InputAction(); //temporary } else { break; } @@ -33,7 +33,7 @@ namespace Bitspace_2._0 { if (gameTick % 3 == 0) { if (Creatures.AllAliveCreatures.Count() > 0) { foreach (var currCreature in Creatures.AllAliveCreatures) { - currCreature.GetAffectedByBiome(Map.biomeDB.Values.First(b => b.Ground == Map.MapLayer[currCreature.YPos][currCreature.XPos])); + currCreature.GetAffectedByBiome(Map.Biomes.Values.First(b => b.Ground == Map.MapLayer[currCreature.YPos][currCreature.XPos])); } } } -- cgit v1.2.3 From 3967e21a428281bc6a8df364f70c451b93ef9e7a Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 14 Sep 2019 09:31:07 +0300 Subject: Did issue #54, Inventory is fully implimented --- Bitspace 2.0/Bitspace 2.0/Bitspace 2.0.csproj | 1 + Bitspace 2.0/Bitspace 2.0/Game creatures/Animal.cs | 10 +-- Bitspace 2.0/Bitspace 2.0/Game creatures/Mob.cs | 22 ++++--- Bitspace 2.0/Bitspace 2.0/Game creatures/Player.cs | 16 +++-- Bitspace 2.0/Bitspace 2.0/Game items/Item.cs | 16 ++++- Bitspace 2.0/Bitspace 2.0/Graphics.cs | 1 + Bitspace 2.0/Bitspace 2.0/Inventory.cs | 71 ++++++++++++++++++++++ Bitspace 2.0/Bitspace 2.0/KeyBindings.cs | 5 ++ 8 files changed, 122 insertions(+), 20 deletions(-) create mode 100644 Bitspace 2.0/Bitspace 2.0/Inventory.cs 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 @@ + 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 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(); + 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 Items = new Dictionary() { + { "Next", ConsoleKey.E }, + { "Previous", ConsoleKey.Q } + }; } } -- cgit v1.2.3 From 7fc10ca322425deeb3ca5c51cf602718b28863be Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 15 Sep 2019 09:37:04 +0300 Subject: Worked on issue #59 Left out only the settings menu (2nd checkbox) --- Bitspace 2.0/Bitspace 2.0/Bitspace 2.0.csproj | 1 + Bitspace 2.0/Bitspace 2.0/Menu.cs | 87 +++++++++++++++++++++++++++ Bitspace 2.0/Bitspace 2.0/Program.cs | 2 +- 3 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 Bitspace 2.0/Bitspace 2.0/Menu.cs 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 f388bf7..0d06311 100644 --- a/Bitspace 2.0/Bitspace 2.0/Bitspace 2.0.csproj +++ b/Bitspace 2.0/Bitspace 2.0/Bitspace 2.0.csproj @@ -55,6 +55,7 @@ + diff --git a/Bitspace 2.0/Bitspace 2.0/Menu.cs b/Bitspace 2.0/Bitspace 2.0/Menu.cs new file mode 100644 index 0000000..b65ef98 --- /dev/null +++ b/Bitspace 2.0/Bitspace 2.0/Menu.cs @@ -0,0 +1,87 @@ +using System; +using Bitspace_2._0.Game_map; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Bitspace_2._0 { + public static class Menu { + private static int yPos; + + public static void StartMenu() { + yPos = 2; + while (true) { + Console.Clear(); + + Console.ForegroundColor = ConsoleColor.Gray; + Console.WriteLine("Bitspace"); + Console.WriteLine(); + Console.WriteLine(" New game"); + Console.WriteLine(" Load game (unavalable)"); + Console.WriteLine(" Settings"); + + if (!MenuCursor(2, 4)) break; + } + switch (yPos) { + case 2: ProgressMenu(); MapSizeMenu(); break; + //case 4: SettingsMenu(); break; + } + } + + private static void MapSizeMenu() { + yPos = 2; + while (true) { + Console.Clear(); + + Console.ForegroundColor = ConsoleColor.Gray; + Console.WriteLine("Choose map size:"); + Console.WriteLine(); + Console.WriteLine(" Small (5 x 10)"); + Console.WriteLine(" Medium (10 x 20)"); + Console.WriteLine(" Large (20 x 40)"); + + if (!MenuCursor(2, 4)) break; + } + switch (yPos) { + case 2: Map.Generate(5, 10); break; + case 3: Map.Generate(10, 20); break; + case 4: Map.Generate(20, 40); break; + } + + } + + private static void ProgressMenu() { + yPos = 2; + while (true) { + Console.Clear(); + + Console.ForegroundColor = ConsoleColor.Gray; + Console.WriteLine("Choose progress saving mode:"); + Console.WriteLine(); + Console.WriteLine(" Get over it! (No saving)"); + Console.WriteLine(" Fanatic (Constant saving) UNAVALABLE"); + + if (!MenuCursor(2, 3)) break; + } + switch(yPos) { + case 3: + case 2: break; + } + } + + private static bool MenuCursor(int minValue, int maxValue) { //returns false when enter is pressed + Console.ForegroundColor = ConsoleColor.Red; + Console.SetCursorPosition(0, yPos); + Console.Write('>'); + + var pressedKey = Console.ReadKey().Key; + + if (pressedKey == ConsoleKey.UpArrow && yPos > minValue) yPos--; + else if (pressedKey == ConsoleKey.DownArrow && yPos < maxValue) yPos++; + else if (pressedKey == ConsoleKey.Enter) return false; + + return true; + } + } +} diff --git a/Bitspace 2.0/Bitspace 2.0/Program.cs b/Bitspace 2.0/Bitspace 2.0/Program.cs index ccad6c6..e249b19 100644 --- a/Bitspace 2.0/Bitspace 2.0/Program.cs +++ b/Bitspace 2.0/Bitspace 2.0/Program.cs @@ -10,8 +10,8 @@ using Bitspace_2._0.Game_creatures; namespace Bitspace_2._0 { class Program { static void Main(string[] args) { - Map.Generate(20, 10); Console.CursorVisible = false; + Menu.StartMenu(); for (ulong gameTick = 0; ; gameTick++, Thread.Sleep(80)) { if (Console.KeyAvailable) { -- cgit v1.2.3 From 0d812232081174c1b7a3e50c03c847eab117cdfa Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 19 Sep 2019 18:50:47 +0300 Subject: Fixed screen printing and tweaked some things Rather than writing and then clearing the screen, now cursor psition is moved to the beginning and writes over old screen. Mobs now heal only after they have regained all their "Air". Made map sizes bigger. Creatures get affected by biomes more slowly. --- Bitspace 2.0/Bitspace 2.0/Game creatures/Mob.cs | 10 +++++++--- Bitspace 2.0/Bitspace 2.0/Graphics.cs | 3 ++- Bitspace 2.0/Bitspace 2.0/Menu.cs | 13 +++++++------ 3 files changed, 16 insertions(+), 10 deletions(-) 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 497c418..094e308 100644 --- a/Bitspace 2.0/Bitspace 2.0/Game creatures/Mob.cs +++ b/Bitspace 2.0/Bitspace 2.0/Game creatures/Mob.cs @@ -57,7 +57,7 @@ namespace Bitspace_2._0.Game_creatures { } public void GetAffectedByBiome(Biome currBiome) { - this.Heal(currBiome.HealPoints); + if (HasFullLungs()) this.Heal(currBiome.HealPoints); if (currBiome.Suffocate) this.Suffocate(); else this.TakeBreather(); @@ -73,11 +73,15 @@ namespace Bitspace_2._0.Game_creatures { } public void TakeBreather() { - if (IsAlive() && LungCapacity < MaxLungCapacity) { + if (IsAlive() && !HasFullLungs()) { LungCapacity++; } } + private bool HasFullLungs() { + return LungCapacity == MaxLungCapacity; + } + public void Suffocate() { if (this.LungCapacity > 0) { this.LungCapacity--; @@ -145,7 +149,7 @@ namespace Bitspace_2._0.Game_creatures { var toReturn = new StringBuilder(new string('O', this.LungCapacity)); for (int i = this.LungCapacity; i < this.MaxLungCapacity; i++) { - toReturn.Append(' '); + toReturn.Append('*'); } return toReturn.ToString(); } diff --git a/Bitspace 2.0/Bitspace 2.0/Graphics.cs b/Bitspace 2.0/Bitspace 2.0/Graphics.cs index fdf52bd..5837631 100644 --- a/Bitspace 2.0/Bitspace 2.0/Graphics.cs +++ b/Bitspace 2.0/Bitspace 2.0/Graphics.cs @@ -11,7 +11,8 @@ namespace Bitspace_2._0 { public static bool Mono = false; public static void ReWriteScreen() { - Console.Clear(); + Console.SetCursorPosition(0, 0); + Console.CursorVisible = false; UpdateLayers(); diff --git a/Bitspace 2.0/Bitspace 2.0/Menu.cs b/Bitspace 2.0/Bitspace 2.0/Menu.cs index b65ef98..e306803 100644 --- a/Bitspace 2.0/Bitspace 2.0/Menu.cs +++ b/Bitspace 2.0/Bitspace 2.0/Menu.cs @@ -13,6 +13,7 @@ namespace Bitspace_2._0 { yPos = 2; while (true) { Console.Clear(); + Console.CursorVisible = false; Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine("Bitspace"); @@ -37,16 +38,16 @@ namespace Bitspace_2._0 { Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine("Choose map size:"); Console.WriteLine(); - Console.WriteLine(" Small (5 x 10)"); - Console.WriteLine(" Medium (10 x 20)"); - Console.WriteLine(" Large (20 x 40)"); + Console.WriteLine(" Small (30 x 10)"); + Console.WriteLine(" Medium (60 x 30)"); + Console.WriteLine(" Large (100 x 40)"); if (!MenuCursor(2, 4)) break; } switch (yPos) { - case 2: Map.Generate(5, 10); break; - case 3: Map.Generate(10, 20); break; - case 4: Map.Generate(20, 40); break; + case 2: Map.Generate(30, 10); break; + case 3: Map.Generate(60, 30); break; + case 4: Map.Generate(100, 40); break; } } -- cgit v1.2.3 From 5f05f6ce4c577bbb1c85e63cb6ad2dcda9e069cf Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 19 Sep 2019 18:50:56 +0300 Subject: Update Program.cs --- Bitspace 2.0/Bitspace 2.0/Program.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Bitspace 2.0/Bitspace 2.0/Program.cs b/Bitspace 2.0/Bitspace 2.0/Program.cs index e249b19..e738084 100644 --- a/Bitspace 2.0/Bitspace 2.0/Program.cs +++ b/Bitspace 2.0/Bitspace 2.0/Program.cs @@ -12,6 +12,7 @@ namespace Bitspace_2._0 { static void Main(string[] args) { Console.CursorVisible = false; Menu.StartMenu(); + Console.Clear(); for (ulong gameTick = 0; ; gameTick++, Thread.Sleep(80)) { if (Console.KeyAvailable) { @@ -30,7 +31,7 @@ namespace Bitspace_2._0 { } } - if (gameTick % 3 == 0) { + if (gameTick % 4 == 0) { if (Creatures.AllAliveCreatures.Count() > 0) { foreach (var currCreature in Creatures.AllAliveCreatures) { currCreature.GetAffectedByBiome(Map.Biomes.Values.First(b => b.Ground == Map.MapLayer[currCreature.YPos][currCreature.XPos])); -- cgit v1.2.3 From 530b4b4b4e2e4a350ec3e9819135266cb6186b94 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 28 Sep 2019 19:52:42 +0300 Subject: Started work on a lot of issues Added classes Item and AmbientItem. Started work on fighting mechanic. --- Bitspace 2.0/Bitspace 2.0/Bitspace 2.0.csproj | 1 + .../Bitspace 2.0/Game creatures/Creatures.cs | 6 +-- Bitspace 2.0/Bitspace 2.0/Game creatures/Mob.cs | 46 ++++++++++++++++++++-- Bitspace 2.0/Bitspace 2.0/Game creatures/Player.cs | 6 +-- .../Bitspace 2.0/Game items/AmbientItem.cs | 7 +++- Bitspace 2.0/Bitspace 2.0/Game items/Item.cs | 22 ++++------- Bitspace 2.0/Bitspace 2.0/Game items/Items.cs | 29 ++++++++++++++ Bitspace 2.0/Bitspace 2.0/Game items/Weapon.cs | 7 +++- Bitspace 2.0/Bitspace 2.0/KeyBindings.cs | 9 ++++- Bitspace 2.0/Bitspace 2.0/Program.cs | 1 + 10 files changed, 106 insertions(+), 28 deletions(-) create mode 100644 Bitspace 2.0/Bitspace 2.0/Game items/Items.cs 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 @@ + 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 AllAliveNPCCreatures { get { - var toReturn = new List(); - - toReturn.AddRange(Animals.Values.Where(x => x.IsAlive())); - - return toReturn; + return new List(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 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(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 Weapons = new Dictionary() { + { "Stick", new Weapon("Stick", '|', ConsoleColor.Gray, 1, 1, 1) } + }; + + public static List AllWeapons { + get { + return new List(Weapons.Values); + } + } + + public static List AllItems { + get { + List toReturn = new List(); + + 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 Items = new Dictionary() { + public static Dictionary Inventory = new Dictionary() { { "Next", ConsoleKey.E }, { "Previous", ConsoleKey.Q } }; + + public static Dictionary Item = new Dictionary() { + { "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) { -- cgit v1.2.3