aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Bitspace/Bitspace/Bitspace.csproj1
-rw-r--r--Bitspace/Bitspace/Item.cs29
-rw-r--r--Bitspace/Bitspace/Mob.cs102
-rw-r--r--Bitspace/Bitspace/Program.cs116
-rw-r--r--Bitspace/Bitspace/Weapon.cs17
-rw-r--r--Bitspace/Game.exebin19968 -> 26624 bytes
6 files changed, 142 insertions, 123 deletions
diff --git a/Bitspace/Bitspace/Bitspace.csproj b/Bitspace/Bitspace/Bitspace.csproj
index 04aa7a7..2e4673a 100644
--- a/Bitspace/Bitspace/Bitspace.csproj
+++ b/Bitspace/Bitspace/Bitspace.csproj
@@ -45,7 +45,6 @@
</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
deleted file mode 100644
index 7e98145..0000000
--- a/Bitspace/Bitspace/Item.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-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 d1b2ecf..475d83d 100644
--- a/Bitspace/Bitspace/Mob.cs
+++ b/Bitspace/Bitspace/Mob.cs
@@ -8,14 +8,14 @@ namespace Game
{
class Mob
{
+ public byte Slots { set; get; }
public bool Alive { set; get; }
public bool FightingWithPlayer { set; get; }
private int health;
private int maxHealth;
- private List<Weapon> weaponsList;
- private List<Item> itemsList;
+ private List<Weapon> itemsList;
private byte selectedItem;
private ushort armour;
@@ -38,40 +38,73 @@ namespace Game
Console.Write(Body);
}
- public string ItemsInventory()
+ public void PrintInventory()
{
- byte slots = 3;
+ Slots = 12;
+ if (SelectedItem > Slots) SelectedItem = Slots;
- StringBuilder inventory = new StringBuilder($"┌{new string('─', (slots * 4) - 1)}┐\r\n│");
- for (int i = 1; i < slots * 2; i++)
+ PrintTopOrBot(true);
+
+ PrintMid(false);
+ PrintMid(true);
+
+ PrintTopOrBot(false);
+ }
+
+ private void PrintMid(bool printingOnlyItemAmounts)
+ {
+ for (byte s = 1; s <= Slots; s++)
{
- if (i % 2 == 0) inventory.Append("│");
- else
+ Console.Write("│");
+
+ if (ItemsList.Count() > s - 1)
{
- if (ItemsList.Count() > i - 1) inventory.Append(" " + ItemsList[i - 1].Skin + " ");
- else inventory.Append(" ");
+ Console.ForegroundColor = ItemsList[s - 1].Color;
+
+ if (printingOnlyItemAmounts)
+ {
+ if (ItemsList[s - 1].Amount < 10) Console.Write(" " + ItemsList[s - 1].Amount + " ");
+ else if (ItemsList[s - 1].Amount < 100) Console.Write(" " + ItemsList[s - 1].Amount);
+ else Console.Write(ItemsList[s - 1].Amount);
+ }
+ else Console.Write(" " + ItemsList[s - 1].SkinUp + " ");
+
+ Console.ForegroundColor = ConsoleColor.Gray;
}
+ else Console.Write(" ");
}
- inventory.Append($"│\r\n│");
+ Console.WriteLine("│");
+ }
+
+ private void PrintTopOrBot(bool printingOnlyTop)
+ {
+ char leftAngle = '┌';
+ char rightAngle = '┐';
+
+ if (!printingOnlyTop)
+ { leftAngle = '└'; rightAngle = '┘'; }
- for (int i = 1; i < slots * 2; i++)
+ Console.Write(leftAngle);
+
+ for (int s = 1; s <= Slots; s++)
{
- if (i % 2 == 0) inventory.Append("│");
+ if (s == SelectedItem)
+ {
+ Console.ForegroundColor = ConsoleColor.Red;
+ Console.Write("***");
+ }
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(" ");
+ Console.ForegroundColor = ConsoleColor.Gray;
+ Console.Write("───");
}
+
+ Console.ForegroundColor = ConsoleColor.Gray;
+ if (s != Slots) Console.Write('─');
}
- inventory.Append($"│\r\n└{new string('─', (slots * 4) - 1)}┘");
- return inventory.ToString();
+ Console.WriteLine(rightAngle);
}
public string Stats()
@@ -148,16 +181,10 @@ namespace Game
get { return yPos; }
}
- public List<Weapon> WeaponsList
- {
- set { weaponsList = value; }
- get { return weaponsList; }
- }
-
- public List<Item> ItemsList
+ public List<Weapon> ItemsList
{
- get { return itemsList; }
set { itemsList = value; }
+ get { return itemsList; }
}
public byte SelectedItem
@@ -167,22 +194,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)
- { WeaponsList = new List<Weapon>(); ItemsList = new List<Item>(); }
+ { ItemsList = 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)
- { WeaponsList = new List<Weapon>(); ItemsList = new List<Item>(); }
+ { ItemsList = new List<Weapon>(); }
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>(); ItemsList = new List<Item>(); }
+ { ItemsList = 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>(); ItemsList = new List<Item>(); }
+ { ItemsList = 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>(); ItemsList = new List<Item>(); }
+ { ItemsList = 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>(); ItemsList = new List<Item>(); }
+ { ItemsList = 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)
{
@@ -199,8 +226,7 @@ namespace Game
XPos = xPos;
YPos = yPos;
- WeaponsList = new List<Weapon>();
- ItemsList = new List<Item>();
+ ItemsList = new List<Weapon>();
}
}
}
diff --git a/Bitspace/Bitspace/Program.cs b/Bitspace/Bitspace/Program.cs
index 85c06ee..75891ca 100644
--- a/Bitspace/Bitspace/Program.cs
+++ b/Bitspace/Bitspace/Program.cs
@@ -22,26 +22,22 @@ namespace Game
private static Dictionary<string, Mob> mobDict = new Dictionary<string, Mob>
{
{ "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) }
+ { "Smiley", new Mob("Smiley", 'U', ConsoleColor.Magenta, 50, 5, 5) },
+ { "Smiley1", new Mob("Smiley1", 'U', ConsoleColor.Magenta, 50, 5, 5) },
+ { "Smiley2", new Mob("Smiley1", 'U', ConsoleColor.Magenta, 50, 5, 5) }
};
- private static Dictionary<string, Item> itemDict = new Dictionary<string, Item>
+ private static Dictionary<string, Weapon> itemDict = new Dictionary<string, Weapon>()
{
-
- };
-
- private static Dictionary<string, Weapon> weaponDict = new Dictionary<string, Weapon>()
- {
- { "Stick", new Weapon("Stick", 5, '-', '|') }
+ { "Stick", new Weapon("Stick", 5, '-', '|', 1) },
+ { "Sling", new Weapon("Sling", 10, 'Y',ConsoleColor.Yellow, 112) }
};
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 }
+ { "swingRight", ConsoleKey.RightArrow }, { "itemsLeft", ConsoleKey.Q}, { "itemsRight", ConsoleKey.E}
};
static void Main(string[] args)
@@ -51,8 +47,9 @@ namespace Game
int s = MapSize();
//TODO: better weapon adding to mobs
- mobDict["Player"].WeaponsList = new List<Weapon> { weaponDict["Stick"]};
- mobDict["Player"].ItemsList.Add(new Item("test", 't', ConsoleColor.Cyan, 119));
+ mobDict["Player"].ItemsList.Add(itemDict["Stick"]);
+ mobDict["Player"].ItemsList.Add(itemDict["Sling"]);
+ mobDict["Player"].SelectedItem = 1;
map = new string[s];
GenerateMap(map);
@@ -76,18 +73,28 @@ namespace Game
else if (keyPressed == keyBindingsDict["right"])
{ if (mobDict["Player"].XPos < map.Length * 2 - 1) mobDict["Player"].XPos++; }
-
- else if (keyPressed == keyBindingsDict["swingLeft"])
- { mobDict["Player"].WeaponsList.First().Direction = "left"; } // 1
- else if (keyPressed == keyBindingsDict["swingRight"])
- { mobDict["Player"].WeaponsList.First().Direction = "right"; } // 2
+ else if (keyPressed == keyBindingsDict["itemsLeft"])
+ { if (mobDict["Player"].SelectedItem > 1) mobDict["Player"].SelectedItem--; }
+
+ else if (keyPressed == keyBindingsDict["itemsRight"])
+ { if (mobDict["Player"].SelectedItem < mobDict["Player"].Slots) mobDict["Player"].SelectedItem++; }
+
+ try
+ {
+ if (keyPressed == keyBindingsDict["swingLeft"])
+ { mobDict["Player"].ItemsList[mobDict["Player"].SelectedItem - 1].Direction = "left"; } // 1
+
+ else if (keyPressed == keyBindingsDict["swingRight"])
+ { mobDict["Player"].ItemsList[mobDict["Player"].SelectedItem - 1].Direction = "right"; } // 2
- else if (keyPressed == keyBindingsDict["swingUp"])
- { mobDict["Player"].WeaponsList.First().Direction = "up"; } // 3
+ else if (keyPressed == keyBindingsDict["swingUp"])
+ { mobDict["Player"].ItemsList[mobDict["Player"].SelectedItem - 1].Direction = "up"; } // 3
- else if (keyPressed == keyBindingsDict["swingDown"])
- { mobDict["Player"].WeaponsList.First().Direction = "down"; } // 4
+ else if (keyPressed == keyBindingsDict["swingDown"])
+ { mobDict["Player"].ItemsList[mobDict["Player"].SelectedItem - 1].Direction = "down"; } // 4
+ }
+ catch (Exception) { }
}
if(gameTick % 2 == 0)
@@ -133,24 +140,33 @@ namespace Game
if (biomeDict.Values.Where(b => b.Floor == map[mob.YPos][mob.XPos]).Single().Damage > 0)
{
- //a lot of try catches, so the code goes through all direction options, even if the player is at a wall/corner
- //x and y positions aren't set here because we have to check the mob position (not to repeat code)
- try
- {
- if (biomeDict.Values.Where(b => b.Floor == map[mob.YPos][mob.XPos - 1]).Single().Damage == 0) movementChooser = 3;
- } catch { }
- try
- {
- if (biomeDict.Values.Where(b => b.Floor == map[mob.YPos][mob.XPos + 1]).Single().Damage == 0) movementChooser = 4;
- } catch { }
- try
- {
- if (biomeDict.Values.Where(b => b.Floor == map[mob.YPos - 1][mob.XPos]).Single().Damage == 0) movementChooser = 1;
- } catch { }
- try
+ //this so if a mob is presented with more than one viable option, it doesn't always do the same thing
+ byte[] randomOrder = new byte[] { 1, 2, 3, 4};
+ randomOrder = randomOrder.OrderBy(x => rndDirection.Next()).ToArray();
+
+ foreach(var num in randomOrder)
{
- if (biomeDict.Values.Where(b => b.Floor == map[mob.YPos + 1][mob.XPos]).Single().Damage == 0) movementChooser = 2;
- } catch { }
+ try
+ {
+ switch (num)
+ {
+ case 1:
+ if (biomeDict.Values.Where(b => b.Floor == map[mob.YPos][mob.XPos - 1]).Single().Damage == 0) movementChooser = 3;
+ break;
+ case 2:
+ if (biomeDict.Values.Where(b => b.Floor == map[mob.YPos][mob.XPos + 1]).Single().Damage == 0) movementChooser = 4;
+ break;
+ case 3:
+ if (biomeDict.Values.Where(b => b.Floor == map[mob.YPos - 1][mob.XPos]).Single().Damage == 0) movementChooser = 1;
+ break;
+ case 4:
+ if (biomeDict.Values.Where(b => b.Floor == map[mob.YPos + 1][mob.XPos]).Single().Damage == 0) movementChooser = 2;
+ break;
+ }
+ }
+ catch (Exception)
+ { }
+ }
}
switch (movementChooser)
@@ -190,7 +206,7 @@ namespace Game
{
//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.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;
Console.WriteLine(map[i].TrimStart(map[i].First()));
@@ -201,13 +217,15 @@ namespace Game
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) or is on the last line, also for less cursor "jumping"
- if (mob.WeaponsList.Count > 0 && (i == mob.YPos + 1 || i == map.Length - 1))
+ if (mob.ItemsList.Count > 0 && (i == mob.YPos + 1 || i == map.Length - 1))
{
- foreach (var weapon in mob.WeaponsList)
+ try
{
+ var weapon = mob.ItemsList[mob.SelectedItem - 1];
+
weapon.PrintAndDoDamage(mob, mobDict, map.Length * 2, map.Length);
weapon.Direction = null;
- }
+ } catch (Exception) { }
}
}
Console.SetCursorPosition(0, i + 1);
@@ -216,7 +234,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());
+ mobDict["Player"].PrintInventory();
foreach(var mob in mobDict.Values.Where(m => m.FightingWithPlayer && m.Alive))
{
@@ -339,6 +357,8 @@ namespace Game
Console.WriteLine($" Swing weapon down: {keyBindingsDict["swingDown"]}");
Console.WriteLine($" Swing weapon left: {keyBindingsDict["swingLeft"]}");
Console.WriteLine($" Swing weapon right: {keyBindingsDict["swingRight"]}");
+ Console.WriteLine($" Scroll items to the left: {keyBindingsDict["itemsLeft"]}");
+ Console.WriteLine($" Scroll items to the right: {keyBindingsDict["itemsRight"]}");
Console.WriteLine(" Back");
Console.SetCursorPosition(0, cursorYPos);
@@ -351,7 +371,7 @@ namespace Game
switch (keyPressed)
{
case ConsoleKey.UpArrow: if (cursorYPos > 1) cursorYPos--; break;
- case ConsoleKey.DownArrow: if (cursorYPos < 9) cursorYPos++; break;
+ case ConsoleKey.DownArrow: if (cursorYPos < 11) cursorYPos++; break;
case ConsoleKey.Enter:
{
switch (cursorYPos)
@@ -364,10 +384,12 @@ namespace Game
case 6: cursosXPos = 20; keyToChange = "swingDown"; break;
case 7: cursosXPos = 20; keyToChange = "swingLeft"; break;
case 8: cursosXPos = 21; keyToChange = "swingRight"; break;
- case 9: stop = true; break;
+ case 9: cursosXPos = 27; keyToChange = "itemsLeft"; break;
+ case 10: cursosXPos = 28; keyToChange = "itemsRight"; break;
+ default: stop = true; break;
}
- if (cursorYPos != 9)
+ if (cursorYPos != 11)
{
Console.SetCursorPosition(cursosXPos, cursorYPos);
Console.CursorVisible = true;
diff --git a/Bitspace/Bitspace/Weapon.cs b/Bitspace/Bitspace/Weapon.cs
index e5bbc93..c5c6353 100644
--- a/Bitspace/Bitspace/Weapon.cs
+++ b/Bitspace/Bitspace/Weapon.cs
@@ -22,6 +22,8 @@ namespace Game
private char skinUp;
private char skinDown;
+ private byte amount;
+
public void PrintAndDoDamage(Mob fightingMob, Dictionary<string, Mob> mobDict, int maxX, int maxY)
{
SwordPosition(fightingMob, maxX, maxY);
@@ -87,22 +89,19 @@ namespace Game
}
}
- public Weapon(string name, ushort damage, char tetraChar) : this(name, damage, tetraChar, tetraChar, tetraChar, tetraChar, ConsoleColor.Gray)
- { }
-
- public Weapon(string name, ushort damage, char tetraChar, ConsoleColor color) : this(name, damage, tetraChar, tetraChar, tetraChar, tetraChar, color)
+ public Weapon(string name, ushort damage, char tetraChar, byte amount) : this(name, damage, tetraChar, tetraChar, tetraChar, tetraChar, ConsoleColor.Gray, amount)
{ }
- public Weapon(string name, ushort damage, char leftRight, char upDown) : this(name, damage, leftRight, leftRight, upDown, upDown, ConsoleColor.Gray)
+ public Weapon(string name, ushort damage, char tetraChar, ConsoleColor color, byte amount) : this(name, damage, tetraChar, tetraChar, tetraChar, tetraChar, color, amount)
{ }
- public Weapon(string name, ushort damage, char leftRight, char upDown, ConsoleColor color) : this(name, damage, leftRight, leftRight, upDown, upDown, color)
+ public Weapon(string name, ushort damage, char leftRight, char upDown, byte amount) : this(name, damage, leftRight, leftRight, upDown, upDown, ConsoleColor.Gray, amount)
{ }
- public Weapon(string name, ushort damage, char skinLeft, char skinRight, char skinUp, char skinDown) : this(name, damage, skinLeft, skinRight, skinUp, skinDown, ConsoleColor.Gray)
+ public Weapon(string name, ushort damage, char leftRight, char upDown, ConsoleColor color, byte amount) : this(name, damage, leftRight, leftRight, upDown, upDown, color, amount)
{ }
- public Weapon(string name, ushort damage, char skinLeft, char skinRight, char skinUp, char skinDown, ConsoleColor color)
+ public Weapon(string name, ushort damage, char skinLeft, char skinRight, char skinUp, char skinDown, ConsoleColor color, byte amount)
{
Damage = damage;
SkinLeft = skinLeft;
@@ -111,6 +110,7 @@ namespace Game
SkinDown = skinDown;
Name = name;
Color = color;
+ Amount = amount;
}
public ushort Damage { get => damage; set => damage = value; }
@@ -121,5 +121,6 @@ namespace Game
public string Direction { get => direction; set => direction = value; }
public string Name { get => name; set => name = value; }
public ConsoleColor Color { get => color; set => color = value; }
+ public byte Amount { get => amount; set => amount = value; }
}
}
diff --git a/Bitspace/Game.exe b/Bitspace/Game.exe
index a38c6bc..bc70101 100644
--- a/Bitspace/Game.exe
+++ b/Bitspace/Game.exe
Binary files differ