aboutsummaryrefslogtreecommitdiff
path: root/Bitspace 2.0
diff options
context:
space:
mode:
Diffstat (limited to 'Bitspace 2.0')
-rw-r--r--Bitspace 2.0/Bitspace 2.0/Bitspace 2.0.csproj6
-rw-r--r--Bitspace 2.0/Bitspace 2.0/Game creatures/Animal.cs10
-rw-r--r--Bitspace 2.0/Bitspace 2.0/Game creatures/Creatures.cs21
-rw-r--r--Bitspace 2.0/Bitspace 2.0/Game creatures/Mob.cs137
-rw-r--r--Bitspace 2.0/Bitspace 2.0/Game creatures/Player.cs16
-rw-r--r--Bitspace 2.0/Bitspace 2.0/Game items/AmbientItem.cs15
-rw-r--r--Bitspace 2.0/Bitspace 2.0/Game items/Item.cs88
-rw-r--r--Bitspace 2.0/Bitspace 2.0/Game items/Items.cs29
-rw-r--r--Bitspace 2.0/Bitspace 2.0/Game items/Weapon.cs15
-rw-r--r--Bitspace 2.0/Bitspace 2.0/Game map/Map.cs18
-rw-r--r--Bitspace 2.0/Bitspace 2.0/Graphics.cs48
-rw-r--r--Bitspace 2.0/Bitspace 2.0/Inventory.cs71
-rw-r--r--Bitspace 2.0/Bitspace 2.0/KeyBindings.cs12
-rw-r--r--Bitspace 2.0/Bitspace 2.0/Menu.cs88
-rw-r--r--Bitspace 2.0/Bitspace 2.0/Program.cs27
15 files changed, 539 insertions, 62 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..8de2a18 100644
--- a/Bitspace 2.0/Bitspace 2.0/Bitspace 2.0.csproj
+++ b/Bitspace 2.0/Bitspace 2.0/Bitspace 2.0.csproj
@@ -45,12 +45,18 @@
<ItemGroup>
<Compile Include="Game creatures\Animal.cs" />
<Compile Include="Game creatures\Creatures.cs" />
+ <Compile Include="Game items\AmbientItem.cs" />
+ <Compile Include="Game items\Items.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="Inventory.cs" />
<Compile Include="KeyBindings.cs" />
<Compile Include="Game map\Map.cs" />
<Compile Include="Game creatures\Mob.cs" />
+ <Compile Include="Menu.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
diff --git a/Bitspace 2.0/Bitspace 2.0/Game creatures/Animal.cs b/Bitspace 2.0/Bitspace 2.0/Game creatures/Animal.cs
index bdfe09b..b337a50 100644
--- a/Bitspace 2.0/Bitspace 2.0/Game creatures/Animal.cs
+++ b/Bitspace 2.0/Bitspace 2.0/Game creatures/Animal.cs
@@ -7,15 +7,15 @@ using System.Threading.Tasks;
namespace Bitspace_2._0.Game_creatures {
public class Animal : Mob {
public Animal(string name, char body, ConsoleColor color, int maxHealth)
- : base(name, body, color, 20, maxHealth, 10, 0) { }
+ : base(name, body, color, 20, maxHealth, 10, 0, 1) { }
public Animal(string name, char body, ConsoleColor color, int maxHealth, int maxLungCapacity)
- : base(name, body, color, 20, maxHealth, maxLungCapacity, 0) { }
+ : base(name, body, color, 20, maxHealth, maxLungCapacity, 0, 1) { }
public Animal(string name, char body, ConsoleColor color, int defaultMovementFactor, int maxHealth, int maxLungCapacity)
- : base(name, body, color, defaultMovementFactor, maxHealth, maxLungCapacity, 0) { }
+ : base(name, body, color, defaultMovementFactor, maxHealth, maxLungCapacity, 0, 1) { }
- public Animal(string name, char body, ConsoleColor color, int defaultMovementFactor, int maxHealth, int maxLungCapacity, int maxArmour)
- : base(name, body, color, defaultMovementFactor, maxHealth, maxLungCapacity, maxArmour) { }
+ public Animal(string name, char body, ConsoleColor color, int defaultMovementFactor, int maxHealth, int maxLungCapacity, int maxArmour, int inventorySize)
+ : base(name, body, color, defaultMovementFactor, maxHealth, maxLungCapacity, maxArmour, inventorySize) { }
}
}
diff --git a/Bitspace 2.0/Bitspace 2.0/Game creatures/Creatures.cs b/Bitspace 2.0/Bitspace 2.0/Game creatures/Creatures.cs
index 8d81dc6..62c04f2 100644
--- a/Bitspace 2.0/Bitspace 2.0/Game creatures/Creatures.cs
+++ b/Bitspace 2.0/Bitspace 2.0/Game creatures/Creatures.cs
@@ -1,25 +1,32 @@
using Bitspace_2._0.Game_creatures;
using System;
+using System.Linq;
using System.Collections.Generic;
namespace Bitspace_2._0.Game_creatures {
- public static class Creatures { //when adding new collections, update Graphics.Update()
+ public static class Creatures { //when adding new collections, update properties at the bottom
public static Dictionary<string, Player> Players = new Dictionary<string, Player>() {
{ "Player1", new Player("The player", '@', ConsoleColor.White, 10) }
};
public static Dictionary<string, Animal> Animals = new Dictionary<string, Animal>() {
- { "Smiley", new Animal("Smiley", 'U', ConsoleColor.Magenta, 5) }
+ { "Smiley", new Animal("Smiley", 'U', ConsoleColor.Magenta, 3) }
};
- public static void DoToAll(Action action) {
- foreach(var pl in Players.Values) {
- action.Invoke();
+ public static List<Mob> AllAliveCreatures {
+ get {
+ var toReturn = AllAliveNPCCreatures;
+
+ toReturn.AddRange(Players.Values.Where(x => x.IsAlive()));
+
+ return toReturn;
}
}
- public static void DoToAllNonPlayers(Action action) {
-
+ public static List<Mob> AllAliveNPCCreatures {
+ get {
+ return new List<Mob>(Animals.Values.Where(x => x.IsAlive()));
+ }
}
}
}
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 544e8bd..6ab94fa 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,17 @@
using Bitspace_2._0.Game_map;
+using Bitspace_2._0.Game_items;
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; }
+ protected string name;
+ protected char body;
+ public ConsoleColor Color { get; set; }
public int XPos { get; set; }
public int YPos { get; set; }
@@ -22,12 +25,59 @@ namespace Bitspace_2._0.Game_creatures {
public int Armour { get; protected set; }
public int MaxArmour { get; protected set; }
- public void MoveRandomly() {
+ public Player fightingWithPlayer { get; set; }
+
+ public Dictionary<string, int> ItemInventory { get; protected set; }
+ protected int inventorySize;
+ protected int selectedItem;
+
+ public string PrintInventory() {
+ var temp = new Item[inventorySize];
+ foreach(Item toAdd in Items.AllItems.Where(i => this.ItemInventory.Keys.Any(ii => ii == i.Name))) {
+ temp.Last(x => x == null) = toAdd;
+ }
+ return Inventory.PrintInventory(temp, selectedItem);
+ }
+
+ public void PickUpItem(string name) {
+ ItemInventory.Add(name, Items.AllItems.First(i => i.Name == name).Quantity);
+ }
+
+ public void PickUpItem(string name, int quantity) {
+ ItemInventory.Add(name, quantity);
+ }
+
+ 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
Move(randomDirection);
}
+
+ public void UseItem(string pressedKeyBinding) {
+ Item itemToUse = Items.AllItems.First(w => w.Name == this.ItemInventory.ElementAt(selectedItem).Key);
+
+ if (Items.AllWeapons.Contains(itemToUse)) UseWeapon((Weapon)itemToUse, pressedKeyBinding);
+ }
+ private void UseWeapon(Weapon weaponToUse, string pressedKeyBinding) {
+ int wepXPos = this.XPos, wepYPos = this.YPos;
+
+ switch (pressedKeyBinding) {
+ case "UseForward": if (wepYPos > Map.MinY) wepYPos--; break;
+ case "UseBackward": if (wepYPos < Map.MaxY) wepYPos++; break;
+ case "UseLeft": if (wepXPos > Map.MinX) wepXPos--; break;
+ case "UseRight": if (wepXPos < Map.MaxX) wepXPos++; break;
+ }
+
+ if (wepXPos != this.XPos || wepYPos != this.YPos) {
+ Map.ItemLayer[wepYPos][wepXPos] = weaponToUse.Body;
+
+ foreach(var cr in Creatures.AllAliveCreatures.Where(c => c.XPos == wepXPos && c.YPos == wepYPos)) {
+ weaponToUse.DoDirectDamage(cr);
+ }
+ }
+ }
+
protected void Move(int direction) {
switch (direction) {
case 1: //North
@@ -45,55 +95,76 @@ namespace Bitspace_2._0.Game_creatures {
}
}
- public void AffectedByBiome(Biome currBiome) {
- this.Heal(currBiome.HealPoints);
+ public void GetAffectedByBiome(Biome currBiome) {
+ if (HasFullLungs()) this.Heal(currBiome.HealPoints);
+
+ if (currBiome.Suffocate) this.Suffocate();
+ else this.TakeBreather();
- if (this.CanSuffocate()) this.Suffocate();
- else this.RecieveDamage(currBiome.DamagePoints);
+ 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 RecieveDamage(int points) {
- if (IsAlive()) {
- if (points > this.Armour / 4) { //all damage under a fourth of the armor doesn't affect mob
- this.Armour -= 2 / 3 * points;
- //this.Health -= Math.Ceiling(Convert.ToDecimal(1.0 / 3.0 * points));
- }
+ public void TakeBreather() {
+ if (IsAlive() && !HasFullLungs()) {
+ LungCapacity++;
}
}
+ private bool HasFullLungs() {
+ return LungCapacity == MaxLungCapacity;
+ }
+
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
+ this.Armour -= 2 / 3 * points;
+ this.Health -= (int)Math.Ceiling(1M / 3 * points);
- if (this.LungCapacity < 0) this.LungCapacity = 0;
+ if (this.Armour < 0) {
+ this.Health += this.Armour; //health will go down because a + -b = a - b
+ this.Armour = 0;
+ }
+ }
+ else LooseHealth(points);
}
}
- public bool IsAlive() {
- return (this.Health > 0) ? true : false;
+ public void LooseHealth(int points) {
+ if (IsAlive()) {
+ this.Health -= points;
+ }
}
- public bool CanSuffocate() {
- return (this.LungCapacity > 0) ? true : false;
+ public bool IsAlive() {
+ return this.Health > 0;
}
public Mob (string name, char body, ConsoleColor color, int maxHealth)
- : this(name, body, color, 20, maxHealth, 10, 0) { }
+ : this(name, body, color, 20, maxHealth, 10, 0, 3) { }
public Mob (string name, char body, ConsoleColor color, int maxHealth, int maxLungCapacity)
- : this(name, body, color, 20, maxHealth, maxLungCapacity, 0) { }
+ : this(name, body, color, 20, maxHealth, maxLungCapacity, 0, 3) { }
public Mob(string name, char body, ConsoleColor color, int defaultMovementFactor, int maxHealth, int maxLungCapacity)
- : this(name, body, color, defaultMovementFactor, maxHealth, maxLungCapacity, 0) { }
+ : this(name, body, color, defaultMovementFactor, maxHealth, maxLungCapacity, 0, 3) { }
- public Mob (string name, char body, ConsoleColor color, int defaultMovementFactor, int maxHealth, int maxLungCapacity, int maxArmour) {
+ public Mob (string name, char body, ConsoleColor color, int defaultMovementFactor, int maxHealth, int maxLungCapacity, int maxArmour, int inventorySize) {
this.Name = name;
this.Body = body;
this.Color = color;
@@ -104,11 +175,23 @@ namespace Bitspace_2._0.Game_creatures {
this.Health = this.MaxHealth = maxHealth;
this.LungCapacity = this.MaxLungCapacity = maxLungCapacity;
this.Armour = this.MaxArmour = maxArmour;
+
+ this.ItemInventory = new Dictionary<string, int>(inventorySize);
+ this.inventorySize = inventorySize;
+ this.selectedItem = 0;
}
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 creatures/Player.cs b/Bitspace 2.0/Bitspace 2.0/Game creatures/Player.cs
index 77acb57..9f6c010 100644
--- a/Bitspace 2.0/Bitspace 2.0/Game creatures/Player.cs
+++ b/Bitspace 2.0/Bitspace 2.0/Game creatures/Player.cs
@@ -14,19 +14,27 @@ namespace Bitspace_2._0.Game_creatures {
case "Right": Move(4); break;
}
}
+ else if (KeyBindings.Inventory.ContainsValue(pressedKey)) {
+ switch (KeyBindings.Inventory.First(kp => kp.Value == pressedKey).Key) {
+ case "Next": if (this.selectedItem < this.inventorySize - 1) this.selectedItem++; break;
+ case "Previous": if (this.selectedItem > 0) this.selectedItem--; break;
+ }
+ }
}
public Player(string name, char body, ConsoleColor color, int maxHealth)
- : base(name, body, color, 20, maxHealth, 10, 0) { }
+ : base(name, body, color, 20, maxHealth, 10, 0, 10) { }
public Player(string name, char body, ConsoleColor color, int maxHealth, int maxLungCapacity)
- : base(name, body, color, 20, maxHealth, maxLungCapacity, 0) { }
+ : base(name, body, color, 20, maxHealth, maxLungCapacity, 0, 10) { }
public Player(string name, char body, ConsoleColor color, int defaultMovementFactor, int maxHealth, int maxLungCapacity)
- : base(name, body, color, defaultMovementFactor, maxHealth, maxLungCapacity, 0) { }
+ : base(name, body, color, defaultMovementFactor, maxHealth, maxLungCapacity, 0, 10) { }
public Player(string name, char body, ConsoleColor color, int defaultMovementFactor, int maxHealth, int maxLungCapacity, int maxArmour)
- : base(name, body, color, defaultMovementFactor, maxHealth, maxLungCapacity, maxArmour) { }
+ : base(name, body, color, defaultMovementFactor, maxHealth, maxLungCapacity, maxArmour, 10) { }
+ public Player(string name, char body, ConsoleColor color, int defaultMovementFactor, int maxHealth, int maxLungCapacity, int maxArmour, int inventorySize)
+ : base(name, body, color, defaultMovementFactor, maxHealth, maxLungCapacity, maxArmour, inventorySize) { }
}
}
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..71f53fb
--- /dev/null
+++ b/Bitspace 2.0/Bitspace 2.0/Game items/AmbientItem.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Bitspace_2._0.Game_items {
+ public class AmbientItem : Item {
+ public AmbientItem(string name, char body, ConsoleColor color, int health, int maxHealth, int damage) : base(name, body, color, health, maxHealth, damage) {
+ }
+
+ public AmbientItem(string name, char body, ConsoleColor color, int health, int maxHealth, int damage, bool canPlace, bool canWalkOver) : base(name, body, color, health, maxHealth, damage, canPlace, canWalkOver) {
+ }
+ }
+}
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..2c93e75
--- /dev/null
+++ b/Bitspace 2.0/Bitspace 2.0/Game items/Item.cs
@@ -0,0 +1,88 @@
+using Bitspace_2._0.Game_creatures;
+using System;
+using System.Linq;
+
+namespace Bitspace_2._0 {
+ public abstract class Item {
+ protected string name;
+ protected char body;
+ protected int initialQuantity;
+ public ConsoleColor Color { 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;
+ }
+
+ 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 DoDirectDamage(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;
+ }
+ }
+
+ public int Quantity {
+ get { return this.initialQuantity; }
+ set {
+ if (value < 1) {
+ throw new ArgumentException("Quantity of items can't be less than 1");
+ }
+ this.initialQuantity = value;
+ }
+ }
+ }
+}
diff --git a/Bitspace 2.0/Bitspace 2.0/Game items/Items.cs b/Bitspace 2.0/Bitspace 2.0/Game items/Items.cs
new file mode 100644
index 0000000..14e2739
--- /dev/null
+++ b/Bitspace 2.0/Bitspace 2.0/Game items/Items.cs
@@ -0,0 +1,29 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Bitspace_2._0.Game_items {
+ static class Items {
+ private static Dictionary<string, Weapon> Weapons = new Dictionary<string, Weapon>() {
+ { "Stick", new Weapon("Stick", '|', ConsoleColor.Gray, 1, 1, 1) }
+ };
+
+ public static List<Weapon> AllWeapons {
+ get {
+ return new List<Weapon>(Weapons.Values);
+ }
+ }
+
+ public static List<Item> AllItems {
+ get {
+ List<Item> toReturn = new List<Item>();
+
+ toReturn.AddRange(AllWeapons);
+
+ return toReturn;
+ }
+ }
+ }
+}
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..4c37acb
--- /dev/null
+++ b/Bitspace 2.0/Bitspace 2.0/Game items/Weapon.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Bitspace_2._0.Game_items {
+ public class Weapon : Item {
+ public Weapon(string name, char body, ConsoleColor color, int health, int maxHealth, int damage) : base(name, body, color, health, maxHealth, damage) {
+ }
+
+ public Weapon(string name, char body, ConsoleColor color, int health, int maxHealth, int damage, bool canPlace, bool canWalkOver) : base(name, body, color, health, maxHealth, damage, canPlace, canWalkOver) {
+ }
+ }
+}
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 a012185..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;
- private 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;
@@ -103,7 +104,6 @@ namespace Bitspace_2._0.Game_map {
foreach (var row in World) {
toReturn.AppendLine(row.ToString());
}
-
return toReturn.ToString();
}
}
diff --git a/Bitspace 2.0/Bitspace 2.0/Graphics.cs b/Bitspace 2.0/Bitspace 2.0/Graphics.cs
index baa9f94..5837631 100644
--- a/Bitspace 2.0/Bitspace 2.0/Graphics.cs
+++ b/Bitspace 2.0/Bitspace 2.0/Graphics.cs
@@ -8,15 +8,51 @@ using System.Threading.Tasks;
namespace Bitspace_2._0 {
static class Graphics {
+ public static bool Mono = false;
+
public static void ReWriteScreen() {
- Console.Clear();
+ Console.SetCursorPosition(0, 0);
+ Console.CursorVisible = false;
+
+ UpdateLayers();
+
+ if (Mono) Console.WriteLine(Map.StringWorld);
+ else {
+ PrintWorld();
- Update();
+ PrintMobInfo();
+ }
+ }
- Console.WriteLine(Map.StringWorld);
+ 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.Write(character);
+ }
+ Console.WriteLine();
+ }
+ }
+
+ private static void PrintMobInfo() {
+ Console.ForegroundColor = ConsoleColor.Gray;
+
+ foreach(var currPlayer in Creatures.Players.Values) {
+ Console.WriteLine(currPlayer);
+ Console.WriteLine(currPlayer.PrintInventory());
+
+ foreach(var fightingWithPlayer in Creatures.AllAliveCreatures.Where(c => c.fightingWithPlayer == currPlayer)) {
+ Console.WriteLine(" " + fightingWithPlayer);
+ }
+ }
}
- private static void Update() {
+ private static void UpdateLayers() {
UpdateMobLayer();
//UpdateItemLayer();
}
@@ -24,8 +60,8 @@ namespace Bitspace_2._0 {
private static void UpdateMobLayer() {
Map.ClearLayer("MobLayer");
- foreach(var pl in Creatures.Players.Values) {
- Map.MobLayer[pl.YPos][pl.XPos] = pl.Body;
+ foreach(var cr in Creatures.AllAliveCreatures) {
+ Map.MobLayer[cr.YPos][cr.XPos] = cr.Body;
}
}
}
diff --git a/Bitspace 2.0/Bitspace 2.0/Inventory.cs b/Bitspace 2.0/Bitspace 2.0/Inventory.cs
new file mode 100644
index 0000000..7b644b3
--- /dev/null
+++ b/Bitspace 2.0/Bitspace 2.0/Inventory.cs
@@ -0,0 +1,71 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Bitspace_2._0 {
+ public static class Inventory {
+ public static string PrintInventory(Item[] items, int selectedItem) {
+ StringBuilder toReturn = new StringBuilder();
+
+ toReturn.Append(PrintTopOrBot(true, items, selectedItem));
+ toReturn.Append(PrintMid(items, selectedItem));
+ toReturn.Append(PrintTopOrBot(false, items, selectedItem));
+
+ return toReturn.ToString();
+ }
+
+ private static string PrintMid(Item[] items, int selectedItem) {
+ StringBuilder toReturn = new StringBuilder();
+
+ for (int row = 0; row < 2; row++, toReturn.AppendLine()) {
+ toReturn.Append("│");
+
+ for (int i = 0; i < items.Length; i++) {
+ switch(row) {
+ case 0:
+ if (items[i] != null) {
+ toReturn.Append(" " + items[i].Body + " │");
+ continue;
+ } break;
+ case 1:
+ if (items[i] != null) {
+ if (items[i].Quantity > 1) {
+ switch(items[i].Quantity.ToString().Length) {
+ case 1: toReturn.Append(" " + items[i].Quantity + " │"); break;
+ case 2: toReturn.Append(" " + items[i].Quantity + "│"); break;
+ case 3: toReturn.Append(items[i].Quantity + "│"); break;
+ } continue;
+ }
+ } break;
+ }
+ toReturn.Append(" │");
+ }
+ }
+ return toReturn.ToString();
+ }
+
+ private static string PrintTopOrBot(bool printTop, Item[] items, int selectedItem) {
+ StringBuilder toReturn = new StringBuilder();
+
+ if (printTop) toReturn.Append("┌");
+ else toReturn.Append("└");
+
+ for (int i = 0; i < items.Length ; i++) {
+ if (selectedItem == i) {
+ toReturn.Append("***");
+ } else {
+ toReturn.Append("───");
+ }
+
+ if (i + 1 < items.Length) toReturn.Append("─");
+ }
+
+ if (printTop) toReturn.AppendLine("┐");
+ else toReturn.AppendLine("┘");
+
+ return toReturn.ToString();
+ }
+ }
+}
diff --git a/Bitspace 2.0/Bitspace 2.0/KeyBindings.cs b/Bitspace 2.0/Bitspace 2.0/KeyBindings.cs
index 61d585c..fb5ec69 100644
--- a/Bitspace 2.0/Bitspace 2.0/KeyBindings.cs
+++ b/Bitspace 2.0/Bitspace 2.0/KeyBindings.cs
@@ -9,5 +9,17 @@ namespace Bitspace_2._0 {
{ "Left", ConsoleKey.A },
{ "Right", ConsoleKey.D }
};
+
+ public static Dictionary<string, ConsoleKey> Inventory = new Dictionary<string, ConsoleKey>() {
+ { "Next", ConsoleKey.E },
+ { "Previous", ConsoleKey.Q }
+ };
+
+ public static Dictionary<string, ConsoleKey> Item = new Dictionary<string, ConsoleKey>() {
+ { "UseForward", ConsoleKey.UpArrow },
+ { "UseBackward", ConsoleKey.DownArrow },
+ { "UseLeft", ConsoleKey.LeftArrow },
+ { "UseRight", ConsoleKey.RightArrow }
+ };
}
}
diff --git a/Bitspace 2.0/Bitspace 2.0/Menu.cs b/Bitspace 2.0/Bitspace 2.0/Menu.cs
new file mode 100644
index 0000000..e306803
--- /dev/null
+++ b/Bitspace 2.0/Bitspace 2.0/Menu.cs
@@ -0,0 +1,88 @@
+using System;
+using Bitspace_2._0.Game_map;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Bitspace_2._0 {
+ public static class Menu {
+ private static int yPos;
+
+ public static void StartMenu() {
+ yPos = 2;
+ while (true) {
+ Console.Clear();
+ Console.CursorVisible = false;
+
+ Console.ForegroundColor = ConsoleColor.Gray;
+ Console.WriteLine("Bitspace");
+ Console.WriteLine();
+ Console.WriteLine(" New game");
+ Console.WriteLine(" Load game (unavalable)");
+ Console.WriteLine(" Settings");
+
+ if (!MenuCursor(2, 4)) break;
+ }
+ switch (yPos) {
+ case 2: ProgressMenu(); MapSizeMenu(); break;
+ //case 4: SettingsMenu(); break;
+ }
+ }
+
+ private static void MapSizeMenu() {
+ yPos = 2;
+ while (true) {
+ Console.Clear();
+
+ Console.ForegroundColor = ConsoleColor.Gray;
+ Console.WriteLine("Choose map size:");
+ Console.WriteLine();
+ Console.WriteLine(" Small (30 x 10)");
+ Console.WriteLine(" Medium (60 x 30)");
+ Console.WriteLine(" Large (100 x 40)");
+
+ if (!MenuCursor(2, 4)) break;
+ }
+ switch (yPos) {
+ case 2: Map.Generate(30, 10); break;
+ case 3: Map.Generate(60, 30); break;
+ case 4: Map.Generate(100, 40); break;
+ }
+
+ }
+
+ private static void ProgressMenu() {
+ yPos = 2;
+ while (true) {
+ Console.Clear();
+
+ Console.ForegroundColor = ConsoleColor.Gray;
+ Console.WriteLine("Choose progress saving mode:");
+ Console.WriteLine();
+ Console.WriteLine(" Get over it! (No saving)");
+ Console.WriteLine(" Fanatic (Constant saving) UNAVALABLE");
+
+ if (!MenuCursor(2, 3)) break;
+ }
+ switch(yPos) {
+ case 3:
+ case 2: break;
+ }
+ }
+
+ private static bool MenuCursor(int minValue, int maxValue) { //returns false when enter is pressed
+ Console.ForegroundColor = ConsoleColor.Red;
+ Console.SetCursorPosition(0, yPos);
+ Console.Write('>');
+
+ var pressedKey = Console.ReadKey().Key;
+
+ if (pressedKey == ConsoleKey.UpArrow && yPos > minValue) yPos--;
+ else if (pressedKey == ConsoleKey.DownArrow && yPos < maxValue) yPos++;
+ else if (pressedKey == ConsoleKey.Enter) return false;
+
+ return true;
+ }
+ }
+}
diff --git a/Bitspace 2.0/Bitspace 2.0/Program.cs b/Bitspace 2.0/Bitspace 2.0/Program.cs
index 6cbaf76..01c15e2 100644
--- a/Bitspace 2.0/Bitspace 2.0/Program.cs
+++ b/Bitspace 2.0/Bitspace 2.0/Program.cs
@@ -10,20 +10,39 @@ using Bitspace_2._0.Game_creatures;
namespace Bitspace_2._0 {
class Program {
static void Main(string[] args) {
- Map.Generate(20, 10);
Console.CursorVisible = false;
+ Menu.StartMenu();
+ Console.Clear();
- for (ulong gameTick = 0; ; gameTick++, Thread.Sleep(70)) {
+ Creatures.Players["Player1"].ItemInventory.Add("Stick", 1);
+ for (ulong gameTick = 0; ; gameTick++, Thread.Sleep(80)) {
if (Console.KeyAvailable) {
- Creatures.Players["Player1"].InputAction();
+ if (Creatures.Players.Count(p => p.Value.IsAlive()) > 0) {
+ Creatures.Players["Player1"].InputAction(); //temporary
+ } else {
+ break;
+ }
}
if (gameTick % 2 == 0) {
- foreach (var currMob in )
+ if (Creatures.AllAliveNPCCreatures.Count() > 0) {
+ foreach (var currNPC in Creatures.AllAliveNPCCreatures) {
+ currNPC.ChooseRndMovement();
+ }
+ }
+ }
+
+ if (gameTick % 4 == 0) {
+ if (Creatures.AllAliveCreatures.Count() > 0) {
+ foreach (var currCreature in Creatures.AllAliveCreatures) {
+ currCreature.GetAffectedByBiome(Map.Biomes.Values.First(b => b.Ground == Map.MapLayer[currCreature.YPos][currCreature.XPos]));
+ }
+ }
}
Graphics.ReWriteScreen();
}
+ Console.WriteLine("GAME OVER");
}
}
}