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(-) (limited to 'Bitspace 2.0') 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