diff options
Diffstat (limited to 'Bitspace 2.0')
| -rw-r--r-- | Bitspace 2.0/Bitspace 2.0/Bitspace 2.0.csproj | 3 | ||||
| -rw-r--r-- | Bitspace 2.0/Bitspace 2.0/Game creatures/Mob.cs | 66 | ||||
| -rw-r--r-- | Bitspace 2.0/Bitspace 2.0/Game items/AmbientItem.cs | 10 | ||||
| -rw-r--r-- | Bitspace 2.0/Bitspace 2.0/Game items/Item.cs | 84 | ||||
| -rw-r--r-- | Bitspace 2.0/Bitspace 2.0/Game items/Weapon.cs | 10 | ||||
| -rw-r--r-- | Bitspace 2.0/Bitspace 2.0/Game map/Map.cs | 17 | ||||
| -rw-r--r-- | Bitspace 2.0/Bitspace 2.0/Graphics.cs | 40 | ||||
| -rw-r--r-- | Bitspace 2.0/Bitspace 2.0/Program.cs | 6 |
8 files changed, 194 insertions, 42 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 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 @@ <ItemGroup> <Compile Include="Game creatures\Animal.cs" /> <Compile Include="Game creatures\Creatures.cs" /> + <Compile Include="Game items\AmbientItem.cs" /> + <Compile Include="Game items\Weapon.cs" /> <Compile Include="Game map\Biome.cs" /> <Compile Include="Game creatures\Player.cs" /> <Compile Include="Graphics.cs" /> + <Compile Include="Game items\Item.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/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<Item> 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<Item>(); } 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<string, Biome> biomeDB = new Dictionary<string, Biome>() { + public static Dictionary<string, Biome> Biomes = new Dictionary<string, Biome>() { { "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])); } } } |
