diff options
| author | Syndamia <kami02882@gmail.com> | 2019-04-17 13:30:53 +0300 |
|---|---|---|
| committer | Syndamia <kami02882@gmail.com> | 2019-04-17 13:30:53 +0300 |
| commit | 2d703ea3fe66ddcecd9425db5b24c44ec34d6724 (patch) | |
| tree | 2117469af229827f4c8a47cff27e28b1b98cf1de /Bitspace | |
| parent | f6f6943c3ebedb719d98f83ee95768a144e2ebbb (diff) | |
| download | Shower-2d703ea3fe66ddcecd9425db5b24c44ec34d6724.tar Shower-2d703ea3fe66ddcecd9425db5b24c44ec34d6724.tar.gz Shower-2d703ea3fe66ddcecd9425db5b24c44ec34d6724.zip | |
Added armour system, made damage from weapons system better, added different chances of biome generation
Diffstat (limited to 'Bitspace')
| -rw-r--r-- | Bitspace/Bitspace/Biome.cs | 3 | ||||
| -rw-r--r-- | Bitspace/Bitspace/Mob.cs | 22 | ||||
| -rw-r--r-- | Bitspace/Bitspace/Program.cs | 58 | ||||
| -rw-r--r-- | Bitspace/Bitspace/Weapon.cs | 36 |
4 files changed, 70 insertions, 49 deletions
diff --git a/Bitspace/Bitspace/Biome.cs b/Bitspace/Bitspace/Biome.cs index 653cb2c..070c3fd 100644 --- a/Bitspace/Bitspace/Biome.cs +++ b/Bitspace/Bitspace/Biome.cs @@ -44,6 +44,9 @@ namespace Game get { return suffocate; } } + public Biome() : this(null, '\0', ConsoleColor.Black, 0, false) + { } + public Biome(string name, char floor, ConsoleColor color) : this(name, floor, color, 0, false) { } diff --git a/Bitspace/Bitspace/Mob.cs b/Bitspace/Bitspace/Mob.cs index cece13f..3c210f5 100644 --- a/Bitspace/Bitspace/Mob.cs +++ b/Bitspace/Bitspace/Mob.cs @@ -116,34 +116,22 @@ namespace Game } public Mob(string name, char body, ConsoleColor color, ushort health) : this(name, body, color, health, 0, 0, health, 0, 0, 0, 0, true) - { } - - public Mob(string name, char body, ConsoleColor color, ushort health, int xPos, int yPos) : this(name, body, color, health, 0, 0, health, 0, 0, xPos, yPos, true) - { } + { WeaponsList = new List<Weapon>(); } public Mob(string name, char body, ConsoleColor color, ushort health, ushort armour) : this(name, body, color, health, armour, 0, health, armour, 0, 0, 0, true) - { } - - public Mob(string name, char body, ConsoleColor color, ushort health, ushort armour, int xPos, int yPos) : this(name, body, color, health, armour, 0, health, armour, 0, xPos, yPos, true) - { } - - public Mob(string name, char body, ConsoleColor color, ushort health, byte lungCapacity) : this(name, body, color, health, 0, lungCapacity, health, 0, lungCapacity, 0, 0, true) { WeaponsList = new List<Weapon>(); } - public Mob(string name, char body, ConsoleColor color, ushort health, byte lungCapacity, int xPos, int yPos) : this(name, body, color, health, 0, lungCapacity, health, 0, lungCapacity, xPos, yPos, true) - { } - public Mob(string name, char body, ConsoleColor color, ushort health, ushort armour, byte lungCapacity) : this(name, body, color, health, armour, lungCapacity, health, armour, lungCapacity, 0, 0, true) - { } + { WeaponsList = new List<Weapon>(); } public Mob(string name, char body, ConsoleColor color, ushort health, ushort armour, byte lungCapacity, int xPos, int yPos) : this(name, body, color, health, armour, lungCapacity, health, armour, lungCapacity, xPos, yPos, true) - { } + { WeaponsList = new List<Weapon>(); } public Mob(string name, char body, ConsoleColor color, ushort health, ushort armour, byte lungCapacity, ushort maxHealth, ushort maxArmour, byte maxLungCapacity) : this(name, body, color, health, armour, lungCapacity, maxHealth, maxArmour, maxLungCapacity, 0, 0, true) - { } + { WeaponsList = new List<Weapon>(); } public Mob(string name, char body, ConsoleColor color, ushort health, ushort armour, byte lungCapacity, ushort maxHealth, ushort maxArmour, byte maxLungCapacity, int xPos, int yPos) : this(name, body, color, health, armour, lungCapacity, maxHealth, maxArmour, maxLungCapacity, xPos, yPos, true) - { } + { WeaponsList = new List<Weapon>(); } public Mob(string name, char body, ConsoleColor color, ushort health, ushort armour, byte lungCapacity, ushort maxHealth, ushort maxArmour, byte maxLungCapacity, int xPos, int yPos, bool alive) { diff --git a/Bitspace/Bitspace/Program.cs b/Bitspace/Bitspace/Program.cs index c88d16c..00508a3 100644 --- a/Bitspace/Bitspace/Program.cs +++ b/Bitspace/Bitspace/Program.cs @@ -13,6 +13,7 @@ namespace Game private static Dictionary<string, Biome> biomeDict = new Dictionary<string, Biome> { { "Water", new Biome("Water", '-', ConsoleColor.Blue, 1, true) }, + { "Lava", new Biome("Lava", '#', ConsoleColor.Red, 2) }, { "Grass land", new Biome("Grass land", ',', ConsoleColor.Green) }, { "Rocks", new Biome("Rocks", '.', ConsoleColor.Gray) } }; @@ -20,15 +21,15 @@ namespace Game //collection of all mobs private static Dictionary<string, Mob> mobDict = new Dictionary<string, Mob> { - { "Player", new Mob("Player", '@', ConsoleColor.White, 100, 10) }, - { "Smiley", new Mob("Smiley", 'U', ConsoleColor.Magenta, 5, 5) }, - { "Smiley1", new Mob("Smiley1", 'U', ConsoleColor.Magenta, 5, 5) }, - { "Smiley2", new Mob("Smiley1", 'U', ConsoleColor.Magenta, 5, 5) } + { "Player", new Mob("Player", '@', ConsoleColor.White, 100, 10, 10) }, + { "Smiley", new Mob("Smiley", 'U', ConsoleColor.Magenta, 5, 5, 5) }, + { "Smiley1", new Mob("Smiley1", 'U', ConsoleColor.Magenta, 5, 5, 5) }, + { "Smiley2", new Mob("Smiley1", 'U', ConsoleColor.Magenta, 5, 5, 5) } }; private static Dictionary<string, Weapon> weaponDict = new Dictionary<string, Weapon>() { - { "Stick", new Weapon("Stick", 1, '-', '|') } + { "Stick", new Weapon("Stick", 5, '-', '|') } }; static void Main(string[] args) @@ -57,10 +58,10 @@ namespace Game case ConsoleKey.A: if (mobDict["Player"].XPos > 0) mobDict["Player"].XPos--; break; case ConsoleKey.D: if (mobDict["Player"].XPos < map.Length * 2 - 1) mobDict["Player"].XPos++; break; - case ConsoleKey.UpArrow: mobDict["Player"].WeaponsList.First().Direction = 3; break; - case ConsoleKey.DownArrow: mobDict["Player"].WeaponsList.First().Direction = 4; break; case ConsoleKey.LeftArrow: mobDict["Player"].WeaponsList.First().Direction = 1; break; case ConsoleKey.RightArrow: mobDict["Player"].WeaponsList.First().Direction = 2; break; + case ConsoleKey.UpArrow: mobDict["Player"].WeaponsList.First().Direction = 3; break; + case ConsoleKey.DownArrow: mobDict["Player"].WeaponsList.First().Direction = 4; break; } } @@ -70,13 +71,12 @@ namespace Game var rndDirection = new Random(); foreach (var mob in mobDict.Values.Where(m => m.Name != "Player" && m.Alive == true)) { - switch (rndDirection.Next(20)) + switch (rndDirection.Next(20)) //number is bigger than cases, so mob has a higher chance of staying at the same place rather than movning { case 1: if (mob.YPos > 0) mob.YPos--; break; case 2: if (mob.YPos < map.Length - 1) mob.YPos++; break; case 3: if (mob.XPos > 0) mob.XPos--; break; case 4: if (mob.XPos < map.Length * 2 - 1) mob.XPos++; break; - case 5: break; //this is for the mob to do nothing, so it can just stay where it is } } } @@ -122,7 +122,8 @@ namespace Game //Prints the map for (int i = 0; i < map.Length; i++) { - Console.ForegroundColor = biomeDict.Values.ToList().Find(x => x.Floor == map[i].First()).Color; + //because a map line can be max 2 biomes, the first half is determined by the first char, and the second half by the last char + Console.ForegroundColor = biomeDict.Values.ToList().Find(x => x.Floor == map[i].First()).Color; Console.Write(map[i].Substring(0, (map[i].LastIndexOf(map[i].First())) + 1)); Console.ForegroundColor = biomeDict.Values.ToList().Find(x => x.Floor == map[i].Last()).Color; @@ -137,7 +138,7 @@ namespace Game { foreach (var weapon in mob.WeaponsList) { - weapon.PrintAndDamage(mobDict["Player"].XPos, mobDict["Player"].YPos, map.Length * 2, map.Length, mobDict.Values.ToList()); + weapon.PrintAndDamage(mobDict["Player"], map.Length * 2, map.Length, mobDict.Values.ToList()); weapon.Direction = 0; } } @@ -177,8 +178,7 @@ namespace Game { case ConsoleKey.UpArrow: if (y > 0) y--; break; case ConsoleKey.DownArrow: if (y < 1) y++; break; - case ConsoleKey.Enter: if(y == 0) { stop = true; } - else { Settings(); } break; + case ConsoleKey.Enter: if(y == 0) { stop = true; } else { Settings(); } break; } } } @@ -285,14 +285,42 @@ namespace Game //map is composed of rows and every row has 1 or 2 biomes in it for (int i = 0; i < map.Length; i++) { - Biome currBiome = biomeDict.ElementAt(rnd.Next(biomeDict.Count)).Value; + Biome currBiome = RandomBiome(rnd); map[i] = new string(currBiome.Floor, map.Length * 2 - rnd.Next(map.Length + 1)); - currBiome = biomeDict.ElementAt(rnd.Next(biomeDict.Count)).Value; + currBiome = RandomBiome(rnd); map[i] = map[i] + new string(currBiome.Floor, map.Length * 2 - map[i].Length); } } + private static Biome RandomBiome(Random rnd) + { + Biome currBiome = new Biome(); + + if (rnd.Next(4) > 0) // 3/4 chance if the biome will hurt the mob or not + { + //from all biomes that do no damage, choose a random one of them + currBiome = biomeDict.Where(x => x.Value.Damage == 0).ElementAt(rnd.Next(biomeDict.Count(x => x.Value.Damage == 0))).Value; + } + else + { + if (rnd.Next(5) > 0) // 4/5 chance if the biome will suffocate and hurt + { + //for all biomes that hurt but don't suffocate, choose a random one of them + currBiome = biomeDict.Where(x => x.Value.Damage > 0 && x.Value.Suffocate) + .ElementAt(rnd.Next(biomeDict.Count(x => x.Value.Damage > 0 && x.Value.Suffocate))).Value; + } + else + { + //for all biomes that hurt and suffocate, chose a random one of them + currBiome = biomeDict.Where(x => x.Value.Damage > 0 && !x.Value.Suffocate) + .ElementAt(rnd.Next(biomeDict.Count(x => x.Value.Damage > 0 && !x.Value.Suffocate))).Value; + } + } + + return currBiome; + } + private static ConsoleColor ColorPicker(ConsoleColor defaultColor) { int y = 1; diff --git a/Bitspace/Bitspace/Weapon.cs b/Bitspace/Bitspace/Weapon.cs index e9d2e0d..b2a1392 100644 --- a/Bitspace/Bitspace/Weapon.cs +++ b/Bitspace/Bitspace/Weapon.cs @@ -19,8 +19,10 @@ namespace Game private char skinUp; private char skinDown; - public void PrintAndDamage(int xPos, int yPos, int maxX, int maxY, List<Mob> mobsList) + public void PrintAndDamage(Mob player, int maxX, int maxY, List<Mob> mobsList) { + int xPos = player.XPos; int yPos = player.YPos; + char swordChar = SwordSwing(direction); if(swordChar != '\0') @@ -29,22 +31,22 @@ namespace Game switch (direction) { - case 1: if (xPos > 0) - { Console.SetCursorPosition(xPos - 1, yPos); Console.Write(swordChar); - mobsList.Where(m => m.XPos == xPos - 1 && m.YPos == yPos).Select(m => m.Health -= Damage).ToList(); - } break; - case 2: if (xPos < maxX - 1) - { Console.SetCursorPosition(xPos + 1, yPos); Console.Write(swordChar); - mobsList.Where(m => m.XPos == xPos + 1 && m.YPos == yPos).Select(m => m.Health -= Damage).ToList(); - } break; - case 3: if (yPos > 0) - { Console.SetCursorPosition(xPos, yPos - 1); Console.Write(swordChar); - mobsList.Where(m => m.XPos == xPos && m.YPos == yPos - 1).Select(m => m.Health -= Damage).ToList(); - } break; - case 4: if (yPos < maxY - 1) - { Console.SetCursorPosition(xPos, yPos + 1); Console.Write(swordChar); - mobsList.Where(m => m.XPos == xPos && m.YPos == yPos + 1).Select(m => m.Health -= Damage).ToList(); - } break; + case 1: if (xPos > 0) xPos--; break; + case 2: if (xPos < maxX - 1) xPos++; break; + case 3: if (yPos > 0) yPos--; break; + case 4: if (yPos < maxY - 1) yPos++; break; + } + + Console.SetCursorPosition(xPos, yPos); Console.Write(swordChar); + + foreach (var mob in mobsList.Where(m => m.XPos == xPos && m.YPos == yPos)) + { + for (int d = Damage; d > 0 && mob.Health > 0; d--) + { + if (Damage <= mob.Armour / 4) { } //does nothing, all damage that is below a fourth of the armour is nullified + else if (mob.Armour > 0 && d >= Damage * 2 / 3) mob.Armour--; + else mob.Health--; + } } } } |
