aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSyndamia <kami02882@gmail.com>2019-04-16 23:09:52 +0300
committerSyndamia <kami02882@gmail.com>2019-04-16 23:09:52 +0300
commitf6f6943c3ebedb719d98f83ee95768a144e2ebbb (patch)
tree5c705e842fac1b23b18584b6c76566a6bde515d9
parentc36dd556603ce6905066710497cd6d85488a3f0b (diff)
downloadShower-f6f6943c3ebedb719d98f83ee95768a144e2ebbb.tar
Shower-f6f6943c3ebedb719d98f83ee95768a144e2ebbb.tar.gz
Shower-f6f6943c3ebedb719d98f83ee95768a144e2ebbb.zip
Added a start menu, with settings, fixed weapon printing, weapons now do damage, fixed and made better biome-health system, made game tick system better
-rw-r--r--Bitspace/Bitspace/Program.cs286
-rw-r--r--Bitspace/Bitspace/Weapon.cs42
-rw-r--r--Bitspace/Game.exebin13824 -> 19968 bytes
3 files changed, 268 insertions, 60 deletions
diff --git a/Bitspace/Bitspace/Program.cs b/Bitspace/Bitspace/Program.cs
index c119aee..c88d16c 100644
--- a/Bitspace/Bitspace/Program.cs
+++ b/Bitspace/Bitspace/Program.cs
@@ -9,7 +9,7 @@ namespace Game
{
class Program
{
- //collection of all biomes, WARNING: biomes that do damage must be ON TOP of biomes that do not
+ //collection of all biomes
private static Dictionary<string, Biome> biomeDict = new Dictionary<string, Biome>
{
{ "Water", new Biome("Water", '-', ConsoleColor.Blue, 1, true) },
@@ -34,6 +34,7 @@ namespace Game
static void Main(string[] args)
{
Console.BackgroundColor = ConsoleColor.Black;
+ StartMenu();
int s = MapSize();
mobDict["Player"].WeaponsList = new List<Weapon> { weaponDict["Stick"]}; //temporary, just for tests
@@ -41,7 +42,7 @@ namespace Game
string[] map = new string[s];
MapGenerate(map);
- ushort gameTick = 0;
+ ulong gameTick = 0;
while (mobDict["Player"].Alive == true)
{
if (Console.KeyAvailable) // checkes if the player has pressed any key
@@ -63,13 +64,13 @@ namespace Game
}
}
- if(gameTick == 1)
+ 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(10))
+ switch (rndDirection.Next(20))
{
case 1: if (mob.YPos > 0) mob.YPos--; break;
case 2: if (mob.YPos < map.Length - 1) mob.YPos++; break;
@@ -80,57 +81,40 @@ namespace Game
}
}
- if (gameTick == 2)
+ if (gameTick % 3 == 0)
{
- //damage-regeneation mechanism, at the moment you only get damaged in water, program crashes when player dies
+ //damage-regeneation mechanism from biomes
foreach (var mob in mobDict.Values.Where(m => m.Alive == true))
{
- foreach (var biome in biomeDict.Values)
- {
- if (biome.Floor == map[mob.YPos][mob.XPos] && biome.Damage > 0)
- {
- if (mob.LungCapacity > 0 && biome.Suffocate) mob.LungCapacity--;
- else mob.Health -= biome.Damage;
+ var biome = biomeDict.Values.ToList().Find(b => b.Floor == map[mob.YPos][mob.XPos]);
- break;
- }
- else
- {
- if (mob.LungCapacity < mob.MaxLungCapacity) mob.LungCapacity++;
- if (mob.Health < mob.MaxHealth) mob.Health++;
- }
+ if(biome.Damage > 0)
+ {
+ if (biome.Suffocate && mob.LungCapacity > 0) mob.LungCapacity--;
+ else mob.Health -= biome.Damage;
+ }
+ else
+ {
+ if (mob.LungCapacity < mob.MaxLungCapacity) mob.LungCapacity++;
+ else if (mob.Health < mob.MaxHealth && gameTick % 10 == 0) mob.Health++;
}
-
- if (mob.Health == 0) mob.Alive = false;
}
-
- gameTick = 0;
}
ReWriteScreen(map);
- Thread.Sleep(80);
gameTick++;
+
+ foreach(var dead in mobDict.Values.Where(m => m.Health < 1))
+ { dead.Alive = false; }
+
+ for(int i = 0; i < 34000000; i++)
+ { } //replace of Thread.Sleep(80); because we haven't learned about thread stuff for now
}
Console.WriteLine("GAME OVER. YOU DIED.");
ConsoleKey endProgram = Console.ReadKey().Key;
}
- private static void MapGenerate(string[] map)
- {
- Random rnd = new Random();
-
- //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;
- map[i] = new string(currBiome.Floor, map.Length * 2 - rnd.Next(map.Length + 1));
-
- currBiome = biomeDict.ElementAt(rnd.Next(biomeDict.Count)).Value;
- map[i] = map[i] + new string(currBiome.Floor, map.Length * 2 - map[i].Length);
- }
- }
-
private static void ReWriteScreen(string[] map)
{
Console.Clear();
@@ -145,18 +129,16 @@ namespace Game
Console.WriteLine(map[i].TrimStart(map[i].First()));
//If an alive mob is at the same line as the cycle is, print it
- foreach (var mob in mobDict.Values.Where(m => m.YPos == i && m.Alive == true))
+ foreach (var mob in mobDict.Values.Where(m => m.Alive == true))
{
- mob.Print();
-
- if (mob.WeaponsList.Count > 0)
+ if(mob.YPos == i) mob.Print();
+
+ if (mob.WeaponsList.Count > 0 && i == mob.YPos + 1)
{
foreach (var weapon in mob.WeaponsList)
{
-
- weapon.Print(mobDict["Player"].XPos, mobDict["Player"].YPos, map.Length * 2, map.Length);
-
- if (weapon.Direction != 4) weapon.Direction = 0;
+ weapon.PrintAndDamage(mobDict["Player"].XPos, mobDict["Player"].YPos, map.Length * 2, map.Length, mobDict.Values.ToList());
+ weapon.Direction = 0;
}
}
}
@@ -170,6 +152,91 @@ namespace Game
Console.CursorVisible = false;
}
+ private static void StartMenu()
+ {
+ Console.CursorVisible = false;
+ int y = 0;
+ bool stop = false;
+
+ while (!stop)
+ {
+ Console.Clear();
+
+ Console.ForegroundColor = ConsoleColor.Gray;
+ Console.WriteLine(" New game");
+ Console.WriteLine(" Settings");
+
+ Console.ForegroundColor = ConsoleColor.Red;
+ Console.SetCursorPosition(0, y);
+ Console.Write('>');
+ Console.CursorVisible = false;
+
+ var keyPressed = Console.ReadKey().Key;
+
+ switch (keyPressed)
+ {
+ 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;
+ }
+ }
+ }
+
+ private static void Settings()
+ {
+ Mob player = mobDict["Player"];
+ bool stop = false;
+ int y = 1;
+
+ while (!stop)
+ {
+ Console.Clear();
+
+ Console.ForegroundColor = ConsoleColor.Gray;
+ Console.WriteLine("Settings:");
+ Console.WriteLine($" Player char: {player.Body}");
+ Console.WriteLine($" Player color: {player.Color}");
+ Console.WriteLine(" Back");
+
+ Console.SetCursorPosition(0, y);
+ Console.ForegroundColor = ConsoleColor.Red;
+ Console.Write('>');
+ Console.CursorVisible = false;
+
+ var keyPressed = Console.ReadKey().Key;
+
+ switch (keyPressed)
+ {
+ case ConsoleKey.UpArrow: if (y > 1) y--; break;
+ case ConsoleKey.DownArrow: if (y < 3) y++; break;
+ case ConsoleKey.Enter:
+ {
+ switch (y)
+ {
+ case 1:
+ {
+ Console.SetCursorPosition(14, 1);
+ Console.CursorVisible = true;
+
+ player.Body = Console.ReadKey().KeyChar;
+
+ Console.CursorVisible = false;
+ Console.SetCursorPosition(0, 1);
+
+ } break;
+ case 2:
+ {
+ player.Color = ColorPicker(player.Color);
+ } break;
+ case 3: stop = true; StartMenu(); break;
+ }
+ }
+ break;
+ }
+ }
+ }
+
private static int MapSize()
{
int size = 0;
@@ -181,9 +248,9 @@ namespace Game
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine("Choose map size:");
- Console.WriteLine("-Small");
- Console.WriteLine("-Medium");
- Console.WriteLine("-Large");
+ Console.WriteLine("-Small (5 x 10)");
+ Console.WriteLine("-Medium (10 x 20)");
+ Console.WriteLine("-Large (20 x 40) !FLICKER!");
Console.SetCursorPosition(0, y);
Console.ForegroundColor = ConsoleColor.Red;
@@ -204,11 +271,126 @@ namespace Game
case 2: size = 10; break;
case 3: size = 20; break;
}
- } break;
+ }
+ break;
}
}
-
return size;
}
+
+ private static void MapGenerate(string[] map)
+ {
+ Random rnd = new Random();
+
+ //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;
+ map[i] = new string(currBiome.Floor, map.Length * 2 - rnd.Next(map.Length + 1));
+
+ currBiome = biomeDict.ElementAt(rnd.Next(biomeDict.Count)).Value;
+ map[i] = map[i] + new string(currBiome.Floor, map.Length * 2 - map[i].Length);
+ }
+ }
+
+ private static ConsoleColor ColorPicker(ConsoleColor defaultColor)
+ {
+ int y = 1;
+
+ while (true)
+ {
+ Console.Clear();
+
+ Console.ForegroundColor = ConsoleColor.Gray;
+ Console.WriteLine("Settings:");
+
+ Console.ForegroundColor = defaultColor;
+ Console.WriteLine($" Default");
+
+ Console.ForegroundColor = ConsoleColor.Black;
+ Console.WriteLine($" Black");
+
+ Console.ForegroundColor = ConsoleColor.Blue;
+ Console.WriteLine($" Blue");
+
+ Console.ForegroundColor = ConsoleColor.Cyan;
+ Console.WriteLine($" Cyan");
+
+ Console.ForegroundColor = ConsoleColor.DarkBlue;
+ Console.WriteLine($" Dark Blue");
+
+ Console.ForegroundColor = ConsoleColor.DarkCyan;
+ Console.WriteLine($" Dark Cyan");
+
+ Console.ForegroundColor = ConsoleColor.DarkGray;
+ Console.WriteLine($" Dark Gray");
+
+ Console.ForegroundColor = ConsoleColor.DarkGreen;
+ Console.WriteLine(" Dark Green");
+
+ Console.ForegroundColor = ConsoleColor.DarkMagenta;
+ Console.WriteLine(" Dark Magenta");
+
+ Console.ForegroundColor = ConsoleColor.DarkRed;
+ Console.WriteLine(" Dark Red");
+
+ Console.ForegroundColor = ConsoleColor.DarkYellow;
+ Console.WriteLine(" Dark Yellow");
+
+ Console.ForegroundColor = ConsoleColor.Gray;
+ Console.WriteLine(" Gray");
+
+ Console.ForegroundColor = ConsoleColor.Green;
+ Console.WriteLine(" Green");
+
+ Console.ForegroundColor = ConsoleColor.Magenta;
+ Console.WriteLine(" Magenta");
+
+ Console.ForegroundColor = ConsoleColor.Red;
+ Console.WriteLine(" Red");
+
+ Console.ForegroundColor = ConsoleColor.White;
+ Console.WriteLine(" White");
+
+ Console.ForegroundColor = ConsoleColor.Yellow;
+ Console.WriteLine(" Yellow");
+
+ Console.SetCursorPosition(0, y);
+ Console.Write('>');
+ Console.CursorVisible = false;
+
+ var keyPressed = Console.ReadKey().Key;
+
+ switch (keyPressed)
+ {
+ case ConsoleKey.UpArrow: if (y > 1) y--; break;
+ case ConsoleKey.DownArrow: if (y < 17) y++; break;
+ case ConsoleKey.Enter:
+ {
+ switch (y)
+ {
+ case 1: return default;
+ case 2: return ConsoleColor.Black;
+ case 3: return ConsoleColor.Blue;
+ case 4: return ConsoleColor.Cyan;
+ case 5: return ConsoleColor.DarkBlue;
+ case 6: return ConsoleColor.DarkCyan;
+ case 7: return ConsoleColor.DarkGray;
+ case 8: return ConsoleColor.DarkGreen;
+ case 9: return ConsoleColor.DarkMagenta;
+ case 10: return ConsoleColor.DarkRed;
+ case 11: return ConsoleColor.DarkYellow;
+ case 12: return ConsoleColor.Gray;
+ case 13: return ConsoleColor.Green;
+ case 14: return ConsoleColor.Magenta;
+ case 15: return ConsoleColor.Red;
+ case 16: return ConsoleColor.White;
+ case 17: return ConsoleColor.Yellow;
+ }
+ }
+ break;
+ }
+ }
+ }
}
}
diff --git a/Bitspace/Bitspace/Weapon.cs b/Bitspace/Bitspace/Weapon.cs
index 4ecd62c..e9d2e0d 100644
--- a/Bitspace/Bitspace/Weapon.cs
+++ b/Bitspace/Bitspace/Weapon.cs
@@ -11,6 +11,7 @@ namespace Game
private string name;
private ushort damage;
+ private ConsoleColor color;
private byte direction;
private char skinLeft;
@@ -18,18 +19,32 @@ namespace Game
private char skinUp;
private char skinDown;
- public void Print(int xPos, int yPos, int maxX, int maxY)
+ public void PrintAndDamage(int xPos, int yPos, int maxX, int maxY, List<Mob> mobsList)
{
char swordChar = SwordSwing(direction);
if(swordChar != '\0')
{
+ Console.ForegroundColor = Color;
+
switch (direction)
{
- case 1: if (xPos > 0) { Console.SetCursorPosition(xPos - 1, yPos); Console.Write(swordChar); } break;
- case 2: if (xPos < maxX - 1) { Console.SetCursorPosition(xPos + 1, yPos); Console.Write(swordChar); } break;
- case 3: if (yPos > 0) { Console.SetCursorPosition(xPos, yPos - 1); Console.Write(swordChar); } break;
- case 4: if (yPos < maxY - 1) { Console.SetCursorPosition(xPos, yPos + 1); Console.Write(swordChar); } break;
+ 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;
}
}
}
@@ -46,13 +61,22 @@ namespace Game
}
}
- public Weapon(string name, ushort damage, char tetraChar) : this(name, damage, tetraChar, tetraChar, tetraChar, tetraChar)
+ 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 leftRight, char upDown) : this(name, damage, leftRight, leftRight, upDown, upDown, ConsoleColor.Gray)
+ { }
+
+ 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) : this(name, damage, leftRight, leftRight, upDown, upDown)
+ 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 skinLeft, char skinRight, char skinUp, char skinDown)
+ public Weapon(string name, ushort damage, char skinLeft, char skinRight, char skinUp, char skinDown, ConsoleColor color)
{
Damage = damage;
SkinLeft = skinLeft;
@@ -60,6 +84,7 @@ namespace Game
SkinUp = skinUp;
SkinDown = skinDown;
Name = name;
+ Color = color;
}
public ushort Damage { get => damage; set => damage = value; }
@@ -69,5 +94,6 @@ namespace Game
public char SkinDown { get => skinDown; set => skinDown = value; }
public byte Direction { get => direction; set => direction = value; }
public string Name { get => name; set => name = value; }
+ public ConsoleColor Color { get => color; set => color = value; }
}
}
diff --git a/Bitspace/Game.exe b/Bitspace/Game.exe
index 5c47902..a38c6bc 100644
--- a/Bitspace/Game.exe
+++ b/Bitspace/Game.exe
Binary files differ