aboutsummaryrefslogtreecommitdiff
path: root/Bitspace
diff options
context:
space:
mode:
authorSyndamia <kami02882@gmail.com>2019-04-26 14:16:08 +0300
committerSyndamia <kami02882@gmail.com>2019-04-26 14:16:08 +0300
commitf2efbc848a61f3000b814febd6a84ff248d918a8 (patch)
tree577b4f180dcaa557927a64222cb6e7b8a7afcb7a /Bitspace
parent9e67b4552c71f13fb4bd3df3f4af809e6157059d (diff)
downloadShower-f2efbc848a61f3000b814febd6a84ff248d918a8.tar
Shower-f2efbc848a61f3000b814febd6a84ff248d918a8.tar.gz
Shower-f2efbc848a61f3000b814febd6a84ff248d918a8.zip
Added class Item, mobs have an item inventory and it can be printed, more flexible map generation (can generate with one biome and up)
Diffstat (limited to 'Bitspace')
-rw-r--r--Bitspace/Bitspace/Bitspace.csproj1
-rw-r--r--Bitspace/Bitspace/Item.cs29
-rw-r--r--Bitspace/Bitspace/Mob.cs65
-rw-r--r--Bitspace/Bitspace/Program.cs59
-rw-r--r--Bitspace/Bitspace/Weapon.cs30
5 files changed, 142 insertions, 42 deletions
diff --git a/Bitspace/Bitspace/Bitspace.csproj b/Bitspace/Bitspace/Bitspace.csproj
index 2e4673a..04aa7a7 100644
--- a/Bitspace/Bitspace/Bitspace.csproj
+++ b/Bitspace/Bitspace/Bitspace.csproj
@@ -45,6 +45,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Biome.cs" />
+ <Compile Include="Item.cs" />
<Compile Include="Mob.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
diff --git a/Bitspace/Bitspace/Item.cs b/Bitspace/Bitspace/Item.cs
new file mode 100644
index 0000000..7e98145
--- /dev/null
+++ b/Bitspace/Bitspace/Item.cs
@@ -0,0 +1,29 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Game
+{
+ class Item
+ {
+ private string name;
+ private char skin;
+ private ConsoleColor color;
+ private byte amount;
+
+ public Item(string name, char skin, ConsoleColor color, byte amount)
+ {
+ Name = name;
+ Skin = skin;
+ Color = color;
+ Amount = amount;
+ }
+
+ public string Name { get => name; set => name = value; }
+ public char Skin { get => skin; set => skin = value; }
+ public ConsoleColor Color { get => color; set => color = value; }
+ public byte Amount { get => amount; set => amount = value; }
+ }
+}
diff --git a/Bitspace/Bitspace/Mob.cs b/Bitspace/Bitspace/Mob.cs
index 45a43bc..d1b2ecf 100644
--- a/Bitspace/Bitspace/Mob.cs
+++ b/Bitspace/Bitspace/Mob.cs
@@ -15,6 +15,8 @@ namespace Game
private int maxHealth;
private List<Weapon> weaponsList;
+ private List<Item> itemsList;
+ private byte selectedItem;
private ushort armour;
private ushort maxArmour;
@@ -36,6 +38,42 @@ namespace Game
Console.Write(Body);
}
+ public string ItemsInventory()
+ {
+ byte slots = 3;
+
+ StringBuilder inventory = new StringBuilder($"┌{new string('─', (slots * 4) - 1)}┐\r\n│");
+ for (int i = 1; i < slots * 2; i++)
+ {
+ if (i % 2 == 0) inventory.Append("│");
+ else
+ {
+ if (ItemsList.Count() > i - 1) inventory.Append(" " + ItemsList[i - 1].Skin + " ");
+ else inventory.Append(" ");
+ }
+ }
+
+ inventory.Append($"│\r\n│");
+
+ for (int i = 1; i < slots * 2; i++)
+ {
+ if (i % 2 == 0) inventory.Append("│");
+ else
+ {
+ if (ItemsList.Count() > i - 1)
+ {
+ if (ItemsList[i - 1].Amount < 10) inventory.Append(" " + ItemsList[i - 1].Amount + " ");
+ else if (ItemsList[i - 1].Amount < 100) inventory.Append(" " + ItemsList[i - 1].Amount);
+ else inventory.Append(ItemsList[i - 1].Amount);
+ }
+ else inventory.Append(" ");
+ }
+ }
+
+ inventory.Append($"│\r\n└{new string('─', (slots * 4) - 1)}┘");
+ return inventory.ToString();
+ }
+
public string Stats()
{
return $"{Name} | Health: {Health} | Armour: {Armour} | Air: {new string('O', LungCapacity)}\r\nX: {XPos} | Y: {YPos}";
@@ -116,23 +154,35 @@ namespace Game
get { return weaponsList; }
}
+ public List<Item> ItemsList
+ {
+ get { return itemsList; }
+ set { itemsList = value; }
+ }
+
+ public byte SelectedItem
+ {
+ get { return selectedItem; }
+ set { selectedItem = value; }
+ }
+
public Mob(string name, char body, ConsoleColor color, ushort health) : this(name, body, color, health, 0, 0, health, 0, 0, 0, 0, true)
- { WeaponsList = new List<Weapon>(); }
+ { WeaponsList = new List<Weapon>(); ItemsList = new List<Item>(); }
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)
- { WeaponsList = new List<Weapon>(); }
+ { WeaponsList = new List<Weapon>(); ItemsList = new List<Item>(); }
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>(); }
+ { WeaponsList = new List<Weapon>(); ItemsList = new List<Item>(); }
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>(); }
+ { WeaponsList = new List<Weapon>(); ItemsList = new List<Item>(); }
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>(); }
+ { WeaponsList = new List<Weapon>(); ItemsList = new List<Item>(); }
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>(); }
+ { WeaponsList = new List<Weapon>(); ItemsList = new List<Item>(); }
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)
{
@@ -148,6 +198,9 @@ namespace Game
Color = color;
XPos = xPos;
YPos = yPos;
+
+ WeaponsList = new List<Weapon>();
+ ItemsList = new List<Item>();
}
}
}
diff --git a/Bitspace/Bitspace/Program.cs b/Bitspace/Bitspace/Program.cs
index f0bbfa1..85c06ee 100644
--- a/Bitspace/Bitspace/Program.cs
+++ b/Bitspace/Bitspace/Program.cs
@@ -27,6 +27,11 @@ namespace Game
{ "Smiley2", new Mob("Smiley1", 'U', ConsoleColor.Magenta, 5, 5, 5) }
};
+ private static Dictionary<string, Item> itemDict = new Dictionary<string, Item>
+ {
+
+ };
+
private static Dictionary<string, Weapon> weaponDict = new Dictionary<string, Weapon>()
{
{ "Stick", new Weapon("Stick", 5, '-', '|') }
@@ -35,7 +40,8 @@ namespace Game
private static Dictionary<string, ConsoleKey> keyBindingsDict = new Dictionary<string, ConsoleKey>()
{
{ "forward", ConsoleKey.W }, { "backward", ConsoleKey.S }, { "left", ConsoleKey.A }, { "right", ConsoleKey.D },
- { "swingUp", ConsoleKey.UpArrow }, { "swingDown", ConsoleKey.DownArrow }, { "swingLeft", ConsoleKey.LeftArrow }, { "swingRight", ConsoleKey.RightArrow }
+ { "swingUp", ConsoleKey.UpArrow }, { "swingDown", ConsoleKey.DownArrow }, { "swingLeft", ConsoleKey.LeftArrow },
+ { "swingRight", ConsoleKey.RightArrow }
};
static void Main(string[] args)
@@ -45,7 +51,8 @@ namespace Game
int s = MapSize();
//TODO: better weapon adding to mobs
- mobDict["Player"].WeaponsList = new List<Weapon> { weaponDict["Stick"]};
+ mobDict["Player"].WeaponsList = new List<Weapon> { weaponDict["Stick"]};
+ mobDict["Player"].ItemsList.Add(new Item("test", 't', ConsoleColor.Cyan, 119));
map = new string[s];
GenerateMap(map);
@@ -71,16 +78,16 @@ namespace Game
{ if (mobDict["Player"].XPos < map.Length * 2 - 1) mobDict["Player"].XPos++; }
else if (keyPressed == keyBindingsDict["swingLeft"])
- { mobDict["Player"].WeaponsList.First().Direction = 1; }
+ { mobDict["Player"].WeaponsList.First().Direction = "left"; } // 1
else if (keyPressed == keyBindingsDict["swingRight"])
- { mobDict["Player"].WeaponsList.First().Direction = 2; }
+ { mobDict["Player"].WeaponsList.First().Direction = "right"; } // 2
else if (keyPressed == keyBindingsDict["swingUp"])
- { mobDict["Player"].WeaponsList.First().Direction = 3; }
+ { mobDict["Player"].WeaponsList.First().Direction = "up"; } // 3
else if (keyPressed == keyBindingsDict["swingDown"])
- { mobDict["Player"].WeaponsList.First().Direction = 4; }
+ { mobDict["Player"].WeaponsList.First().Direction = "down"; } // 4
}
if(gameTick % 2 == 0)
@@ -199,7 +206,7 @@ namespace Game
foreach (var weapon in mob.WeaponsList)
{
weapon.PrintAndDoDamage(mob, mobDict, map.Length * 2, map.Length);
- weapon.Direction = 0;
+ weapon.Direction = null;
}
}
}
@@ -209,6 +216,7 @@ namespace Game
Console.SetCursorPosition(0, map.Length + 1); //sets cursor at the very end
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine(mobDict["Player"].Stats());
+ Console.WriteLine(mobDict["Player"].ItemsInventory());
foreach(var mob in mobDict.Values.Where(m => m.FightingWithPlayer && m.Alive))
{
@@ -437,22 +445,31 @@ namespace Game
{
Biome currBiome = new Biome();
- if (randomNumber.Next(4) > 0) // 3/4 chance that the biome will not hurt the mob
- {
- currBiome = biomeDict.Where(x => x.Value.Damage == 0).ElementAt(randomNumber.Next(biomeDict.Count(x => x.Value.Damage == 0))).Value;
- }
- else
+ if (biomeDict.Count() == 0)
+ { throw new ArgumentException("There must be atleast one biome in the biome dictionary"); }
+
+ while (!biomeDict.Values.Contains(currBiome)) //mainly for tests, so you can remove biomes and it will still generate a map
{
- if (randomNumber.Next(5) > 0) // 4/5 chance that the biome will suffocate and hurt
- {
- currBiome = biomeDict.Where(x => x.Value.Damage > 0 && x.Value.Suffocate)
- .ElementAt(randomNumber.Next(biomeDict.Count(x => x.Value.Damage > 0 && x.Value.Suffocate))).Value;
- }
- else
+ try
{
- currBiome = biomeDict.Where(x => x.Value.Damage > 0 && !x.Value.Suffocate)
- .ElementAt(randomNumber.Next(biomeDict.Count(x => x.Value.Damage > 0 && !x.Value.Suffocate))).Value;
- }
+ if (randomNumber.Next(4) > 0) // 3/4 chance that the biome will not hurt the mob
+ {
+ currBiome = biomeDict.Where(x => x.Value.Damage == 0).ElementAt(randomNumber.Next(biomeDict.Count(x => x.Value.Damage == 0))).Value;
+ }
+ else
+ {
+ if (randomNumber.Next(5) > 0) // 4/5 chance that the biome will suffocate and hurt
+ {
+ currBiome = biomeDict.Where(x => x.Value.Damage > 0 && x.Value.Suffocate)
+ .ElementAt(randomNumber.Next(biomeDict.Count(x => x.Value.Damage > 0 && x.Value.Suffocate))).Value;
+ }
+ else
+ {
+ currBiome = biomeDict.Where(x => x.Value.Damage > 0 && !x.Value.Suffocate)
+ .ElementAt(randomNumber.Next(biomeDict.Count(x => x.Value.Damage > 0 && !x.Value.Suffocate))).Value;
+ }
+ }
+ } catch { }
}
return currBiome;
diff --git a/Bitspace/Bitspace/Weapon.cs b/Bitspace/Bitspace/Weapon.cs
index c5056f7..e5bbc93 100644
--- a/Bitspace/Bitspace/Weapon.cs
+++ b/Bitspace/Bitspace/Weapon.cs
@@ -15,7 +15,7 @@ namespace Game
private ushort damage;
private ConsoleColor color;
- private byte direction;
+ private string direction;
private char skinLeft;
private char skinRight;
@@ -35,7 +35,7 @@ namespace Game
{
Console.ForegroundColor = Color;
Console.SetCursorPosition(xPos, yPos);
- Console.Write(SwordChar(direction));
+ Console.Write(SwordChar());
}
}
@@ -59,30 +59,30 @@ namespace Game
private bool SwordIsSwung()
{
- return (SwordChar(direction) != '\0') && (yPos != -1) && (xPos != -1);
+ return (SwordChar() != '\0') && (yPos != -1) && (xPos != -1);
}
private void SwordPosition(Mob mobWithWeapon, int maxX, int maxY)
{
xPos = -1; yPos = -1;
- switch (direction)
+ 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;
+ case "left": if (mobWithWeapon.XPos > 0) xPos = mobWithWeapon.XPos - 1; yPos = mobWithWeapon.YPos; break;
+ case "right": if (mobWithWeapon.XPos < maxX - 1) xPos = mobWithWeapon.XPos + 1; yPos = mobWithWeapon.YPos; break;
+ case "up": if (mobWithWeapon.YPos > 0) yPos = mobWithWeapon.YPos - 1; xPos = mobWithWeapon.XPos; break;
+ case "down": if (mobWithWeapon.YPos < maxY - 1) yPos = mobWithWeapon.YPos + 1; xPos = mobWithWeapon.XPos; break;
}
}
- private char SwordChar(byte direction)
+ private char SwordChar()
{
- switch (direction)
+ switch (Direction)
{
- case 1: return SkinLeft;
- case 2: return SkinRight;
- case 3: return SkinUp;
- case 4: return SkinDown;
+ case "left": return SkinLeft;
+ case "right": return SkinRight;
+ case "up": return SkinUp;
+ case "down": return SkinDown;
default: return '\0'; // \0 is the char equivalent of null
}
}
@@ -118,7 +118,7 @@ namespace Game
public char SkinRight { get => skinRight; set => skinRight = value; }
public char SkinUp { get => skinUp; set => skinUp = value; }
public char SkinDown { get => skinDown; set => skinDown = value; }
- public byte Direction { get => direction; set => direction = value; }
+ public string Direction { get => direction; set => direction = value; }
public string Name { get => name; set => name = value; }
public ConsoleColor Color { get => color; set => color = value; }
}