aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSyndamia <kami02882@gmail.com>2019-04-25 21:20:52 +0300
committerSyndamia <kami02882@gmail.com>2019-04-25 21:20:52 +0300
commit9f625b5a73421cb2aa2441b85064e14b1ba56f71 (patch)
treef8baf821225fd47ef357a1b5f7ad669ca8ba7cff
parentcac27eb5957559194c66dbf2f1784a03710a37bd (diff)
downloadShower-9f625b5a73421cb2aa2441b85064e14b1ba56f71.tar
Shower-9f625b5a73421cb2aa2441b85064e14b1ba56f71.tar.gz
Shower-9f625b5a73421cb2aa2441b85064e14b1ba56f71.zip
Stats of mob(s) that the player is fighting, mobs now get out of damaging biomes, made weapon printing and damaging code structure much better
-rw-r--r--Bitspace/Bitspace/Mob.cs11
-rw-r--r--Bitspace/Bitspace/Program.cs80
-rw-r--r--Bitspace/Bitspace/Weapon.cs62
3 files changed, 111 insertions, 42 deletions
diff --git a/Bitspace/Bitspace/Mob.cs b/Bitspace/Bitspace/Mob.cs
index 3c210f5..d898253 100644
--- a/Bitspace/Bitspace/Mob.cs
+++ b/Bitspace/Bitspace/Mob.cs
@@ -9,9 +9,10 @@ namespace Game
class Mob
{
public bool Alive { set; get; }
+ public bool FightingWithPlayer { set; get; }
- private ushort health;
- private ushort maxHealth;
+ private int health;
+ private int maxHealth;
private List<Weapon> weaponsList;
@@ -37,16 +38,16 @@ namespace Game
public string Stats() //prints the mob's stats, i.e. health, armour, lung capacity, only used for player
{
- return $"Health: {Health} | Armour: {Armour} | Air: {new string('O', LungCapacity)}\r\nX: {XPos} | Y: {YPos}";
+ return $"{Name} | Health: {Health} | Armour: {Armour} | Air: {new string('O', LungCapacity)}\r\nX: {XPos} | Y: {YPos}";
}
- public ushort Health
+ public int Health
{
set { health = value; }
get { return health; }
}
- public ushort MaxHealth
+ public int MaxHealth
{
set { maxHealth = value; }
get { return maxHealth; }
diff --git a/Bitspace/Bitspace/Program.cs b/Bitspace/Bitspace/Program.cs
index 172c42c..6606f0c 100644
--- a/Bitspace/Bitspace/Program.cs
+++ b/Bitspace/Bitspace/Program.cs
@@ -9,6 +9,8 @@ namespace Game
{
class Program
{
+ private static string[] map;
+
//collection of all biomes
private static Dictionary<string, Biome> biomeDict = new Dictionary<string, Biome>
{
@@ -47,7 +49,7 @@ namespace Game
mobDict["Player"].WeaponsList = new List<Weapon> { weaponDict["Stick"]}; //temporary, just for tests
- string[] map = new string[s];
+ map = new string[s];
MapGenerate(map);
ulong gameTick = 0; //we use a var so that movement is as fast as possible, but taking damage, healing, drowning, ... is slower
@@ -86,18 +88,7 @@ namespace Game
if(gameTick % 2 == 0)
{
- //chooses random movement for mobs (that arent player)
- var rndDirection = new Random();
- foreach (var mob in mobDict.Values.Where(m => m.Name != "Player" && m.Alive == true))
- {
- 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;
- }
- }
+ MobMovement();
}
if (gameTick % 3 == 0)
@@ -105,7 +96,7 @@ namespace Game
//damage-regeneation mechanism from biomes
foreach (var mob in mobDict.Values.Where(m => m.Alive == true))
{
- var biome = biomeDict.Values.ToList().Find(b => b.Floor == map[mob.YPos][mob.XPos]);
+ var biome = biomeDict.Values.Where(b => b.Floor == map[mob.YPos][mob.XPos]).Single();
if(biome.Damage > 0)
{
@@ -120,6 +111,14 @@ namespace Game
}
}
+ if (gameTick % 60 == 0)
+ {
+ foreach (var mob in mobDict.Values.Where(m => m.FightingWithPlayer && m.Alive))
+ {
+ mob.FightingWithPlayer = false;
+ }
+ }
+
ReWriteScreen(map);
gameTick++;
@@ -136,6 +135,45 @@ namespace Game
ConsoleKey endProgram = Console.ReadKey().Key;
}
+ private static void MobMovement()
+ {
+ //chooses random movement for mobs (that arent player)
+ var rndDirection = new Random();
+
+ foreach (var mob in mobDict.Values.Where(m => m.Name != "Player" && m.Alive == true))
+ {
+ int rnd = rndDirection.Next(20);
+
+ if (biomeDict.Values.Where(b => b.Floor == map[mob.YPos][mob.XPos]).Single().Damage > 0)
+ {
+ try
+ {
+ if (biomeDict.Values.Where(b => b.Floor == map[mob.YPos][mob.XPos - 1]).Single().Damage == 0) rnd = 3;
+ } catch { }
+ try
+ {
+ if (biomeDict.Values.Where(b => b.Floor == map[mob.YPos][mob.XPos + 1]).Single().Damage == 0) rnd = 4;
+ } catch { }
+ try
+ {
+ if (biomeDict.Values.Where(b => b.Floor == map[mob.YPos - 1][mob.XPos]).Single().Damage == 0) rnd = 1;
+ } catch { }
+ try
+ {
+ if (biomeDict.Values.Where(b => b.Floor == map[mob.YPos + 1][mob.XPos]).Single().Damage == 0) rnd = 2;
+ } catch { }
+ }
+
+ switch (rnd) //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;
+ }
+ }
+ }
+
private static void ReWriteScreen(string[] map)
{
Console.Clear();
@@ -154,13 +192,13 @@ namespace Game
{
//this prints all mobs that are on the line that was just drawn
if (mob.YPos == i) mob.Print();
-
- //prints weapon when the line under the mob is drawn ; so that the weapon is not overwritten by the biome
- if (mob.WeaponsList.Count > 0 && i == mob.YPos + 1)
+
+ //prints weapon when the line under the mob is drawn (so that the weapon is not overwritten by the biome) or is on the last line
+ if (mob.WeaponsList.Count > 0 && (i == mob.YPos + 1 || i == map.Length - 1))
{
foreach (var weapon in mob.WeaponsList)
{
- weapon.PrintAndDamage(mobDict["Player"], map.Length * 2, map.Length, mobDict.Values.ToList());
+ weapon.PrintAndDoDamage(mob, mobDict, map.Length * 2, map.Length);
weapon.Direction = 0;
}
}
@@ -172,6 +210,12 @@ namespace Game
Console.SetCursorPosition(0, map.Length + 1); //sets cursor at the very end
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine(mobDict["Player"].Stats());
+
+ foreach(var mob in mobDict.Values.Where(m => m.FightingWithPlayer && m.Alive))
+ {
+ Console.WriteLine(mob.Stats());
+ }
+
Console.CursorVisible = false;
}
diff --git a/Bitspace/Bitspace/Weapon.cs b/Bitspace/Bitspace/Weapon.cs
index 522b6dc..a00b6b3 100644
--- a/Bitspace/Bitspace/Weapon.cs
+++ b/Bitspace/Bitspace/Weapon.cs
@@ -8,6 +8,9 @@ namespace Game
{
class Weapon
{
+ private int xPos;
+ private int yPos;
+
private string name;
private ushort damage;
@@ -19,31 +22,33 @@ namespace Game
private char skinUp;
private char skinDown;
- public void PrintAndDamage(Mob player, int maxX, int maxY, List<Mob> mobsList)
+ public void PrintAndDoDamage(Mob fightingMob, Dictionary<string, Mob> mobDict, int maxX, int maxY)
{
- int xPos = player.XPos; int yPos = player.YPos;
-
- char swordChar = SwordSwing(direction);
+ SwordPosition(fightingMob, maxX, maxY);
+ Print(maxX, maxY);
+ DoDamage(mobDict, fightingMob);
+ }
- if(swordChar != '\0')
+ private void Print(int maxX, int maxY)
+ {
+ if (SwordIsSwung())
{
Console.ForegroundColor = Color;
+ Console.SetCursorPosition(xPos, yPos);
+ Console.Write(SwordChar(direction));
+ }
+ }
- switch (direction)
- {
- 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;
- }
-
- //prints weapon
- Console.SetCursorPosition(xPos, yPos); Console.Write(swordChar);
-
+ private void DoDamage(Dictionary<string, Mob> mobDict, Mob fightingMob)
+ {
+ if (SwordIsSwung())
+ {
//takes all mobs that are in the position of the weapon and remove health/armour points
- foreach (var mob in mobsList.Where(m => m.XPos == xPos && m.YPos == yPos))
+ foreach (var mob in mobDict.Values.Where(m => m.XPos == xPos && m.YPos == yPos))
{
- for (int d = Damage; d > 0 && mob.Health > 0; d--)
+ if (mobDict["Player"] == fightingMob) mob.FightingWithPlayer = true;
+
+ for (ushort 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--;
@@ -53,7 +58,26 @@ namespace Game
}
}
- private char SwordSwing(byte direction)
+ private bool SwordIsSwung()
+ {
+ return (SwordChar(direction) != '\0') && (yPos != -1) && (xPos != -1);
+ }
+
+ //changes the inputed xPos and yPos variables
+ private void SwordPosition(Mob mobWithWeapon, int maxX, int maxY)
+ {
+ xPos = -1; yPos = -1;
+
+ switch (direction)
+ {
+ case 1: if (mobWithWeapon.XPos > 0) xPos = mobWithWeapon.XPos - 1; yPos = mobWithWeapon.YPos; break;
+ case 2: if (mobWithWeapon.XPos < maxX - 1) xPos = mobWithWeapon.XPos + 1; yPos = mobWithWeapon.YPos; break;
+ case 3: if (mobWithWeapon.YPos > 0) yPos = mobWithWeapon.YPos - 1; xPos = mobWithWeapon.XPos; break;
+ case 4: if (mobWithWeapon.YPos < maxY - 1) yPos = mobWithWeapon.YPos + 1; xPos = mobWithWeapon.XPos; break;
+ }
+ }
+
+ private char SwordChar(byte direction)
{
switch (direction)
{