diff options
| -rw-r--r-- | Bitspace/Bitspace/Biome.cs | 15 | ||||
| -rw-r--r-- | Bitspace/Bitspace/Mob.cs | 10 | ||||
| -rw-r--r-- | Bitspace/Bitspace/Program.cs | 158 | ||||
| -rw-r--r-- | Bitspace/Game.exe | bin | 0 -> 13824 bytes |
4 files changed, 149 insertions, 34 deletions
diff --git a/Bitspace/Bitspace/Biome.cs b/Bitspace/Bitspace/Biome.cs index 396e37e..2713f80 100644 --- a/Bitspace/Bitspace/Biome.cs +++ b/Bitspace/Bitspace/Biome.cs @@ -11,12 +11,15 @@ namespace Game private string name; private char floor; //floor literally what the mobs "step on" private ConsoleColor color; + private ushort damage; + private bool suffocate; public string Name { set { name = value; } get { return name; } } + public char Floor { set { floor = value; } @@ -28,5 +31,17 @@ namespace Game set { color = value; } get { return color; } } + + public ushort Damage + { + set { damage = value; } + get { return damage; } + } + + public bool Suffocate + { + set { suffocate = value; } + get { return suffocate; } + } } } diff --git a/Bitspace/Bitspace/Mob.cs b/Bitspace/Bitspace/Mob.cs index 113a424..dc51a04 100644 --- a/Bitspace/Bitspace/Mob.cs +++ b/Bitspace/Bitspace/Mob.cs @@ -9,6 +9,7 @@ namespace Game class Mob { //Mobile objects = Mobs + private bool alive; private ushort health; private ushort maxHealth; @@ -37,7 +38,14 @@ namespace Game { Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Gray; - Console.WriteLine($"Health: {Health} | Armour: {Armour} | {new string('o', LungCapacity)}"); + Console.WriteLine($"Health: {Health} | Armour: {Armour} | Air: {new string('O', LungCapacity)}"); + Console.WriteLine($"X: {XPos} | Y: {YPos}"); + } + + public bool Alive + { + set { alive = value; } + get { return alive; } } public ushort Health diff --git a/Bitspace/Bitspace/Program.cs b/Bitspace/Bitspace/Program.cs index 80b73a6..1e8e842 100644 --- a/Bitspace/Bitspace/Program.cs +++ b/Bitspace/Bitspace/Program.cs @@ -9,37 +9,34 @@ namespace Game { class Program { - //collection of all biomes + //collection of all biomes, WARNING: biomes that do damage must be ON TOP of biomes that do not private static Dictionary<string, Biome> biomeDict = new Dictionary<string, Biome> { + { "Water", new Biome { Name = "Water",Floor = '-', Color = ConsoleColor.Blue, Damage = 1 , Suffocate = true } }, { "Grass land", new Biome { Name = "Grass land",Floor = ',', Color = ConsoleColor.Green} }, - { "Water", new Biome { Name = "Water",Floor = '-', Color = ConsoleColor.Blue } }, { "Rocks", new Biome { Name = "Rocks",Floor = '.', Color = ConsoleColor.Gray} } }; //collection of all mobs private static Dictionary<string, Mob> mobDict = new Dictionary<string, Mob> { - { "Player", new Mob {Name = "Player", Color = ConsoleColor.White, Body = '@', MaxHealth = 100, Health = 100, MaxLungCapacity = 10, LungCapacity = 10} }, - { "Smiley", new Mob {Name = "Smiley", Color = ConsoleColor.Magenta, Body = 'U', MaxHealth = 5, Health = 5, MaxLungCapacity = 5, LungCapacity = 5} }, - { "Smiley1", new Mob {Name = "Smiley1", Color = ConsoleColor.Magenta, Body = 'U', MaxHealth = 5, Health = 5, MaxLungCapacity = 5, LungCapacity = 5} }, - { "Smiley2", new Mob {Name = "Smiley2", Color = ConsoleColor.Magenta, Body = 'U', MaxHealth = 5, Health = 5, MaxLungCapacity = 5, LungCapacity = 5} } + { "Player", new Mob {Name = "Player", Color = ConsoleColor.White, Body = '@', Alive = true, MaxHealth = 100, Health = 100, MaxLungCapacity = 10, LungCapacity = 10} }, + { "Smiley", new Mob {Name = "Smiley", Color = ConsoleColor.Magenta, Body = 'U', Alive = true, MaxHealth = 5, Health = 5, MaxLungCapacity = 5, LungCapacity = 5} }, + { "Smiley1", new Mob {Name = "Smiley1", Color = ConsoleColor.Magenta, Body = 'U', Alive = true, MaxHealth = 5, Health = 5, MaxLungCapacity = 5, LungCapacity = 5} }, + { "Smiley2", new Mob {Name = "Smiley2", Color = ConsoleColor.Magenta, Body = 'U', Alive = true, MaxHealth = 5, Health = 5, MaxLungCapacity = 5, LungCapacity = 5} } }; static void Main(string[] args) { Console.BackgroundColor = ConsoleColor.Black; - Console.WriteLine("Please input map height (width will be double the number)"); - int s = int.Parse(Console.ReadLine()); Console.CursorVisible = false; + int s = MapSize(); + string[] map = new string[s]; MapGenerate(map); - while (true) + while (mobDict["Player"].Alive == true) { - ReWriteScreen(map); - Thread.Sleep(70); - if (Console.KeyAvailable) // checkes if the player has pressed any key { var keyPressed = Console.ReadKey().Key; @@ -47,16 +44,21 @@ namespace Game //changes player position depending on pressed key switch (keyPressed) { - case ConsoleKey.UpArrow: if (mobDict["Player"].YPos > 0) mobDict["Player"].YPos--; break; - case ConsoleKey.DownArrow: if (mobDict["Player"].YPos < map.Length - 1) mobDict["Player"].YPos++; break; - case ConsoleKey.LeftArrow: if (mobDict["Player"].XPos > 0) mobDict["Player"].XPos--; break; - case ConsoleKey.RightArrow: if (mobDict["Player"].XPos < map.Length * 2 - 1) mobDict["Player"].XPos++; break; + case ConsoleKey.W: if (mobDict["Player"].YPos > 0) mobDict["Player"].YPos--; break; + case ConsoleKey.S: if (mobDict["Player"].YPos < map.Length - 1) mobDict["Player"].YPos++; break; + case ConsoleKey.A: if (mobDict["Player"].XPos > 0) mobDict["Player"].XPos--; break; + case ConsoleKey.D: if (mobDict["Player"].XPos < map.Length * 2 - 1) mobDict["Player"].XPos++; break; + + case ConsoleKey.UpArrow: DamageDealing(map, ConsoleKey.UpArrow); break; + case ConsoleKey.DownArrow: DamageDealing(map, ConsoleKey.DownArrow); break; + case ConsoleKey.LeftArrow: DamageDealing(map, ConsoleKey.LeftArrow); break; + case ConsoleKey.RightArrow: DamageDealing(map, ConsoleKey.RightArrow); break; } } //chooses random movement for mobs (that arent player) var rndDirection = new Random(); - foreach (var mob in mobDict.Values.Where(m => m.Name != "Player")) + foreach (var mob in mobDict.Values.Where(m => m.Name != "Player" && m.Alive == true)) { switch (rndDirection.Next(6)) { @@ -69,36 +71,80 @@ namespace Game } //damage-regeneation mechanism, at the moment you only get damaged in water, program crashes when player dies - for (int i = 0; i < mobDict.Count; i++) + foreach (var mob in mobDict.Values.Where(m => m.Alive == true)) { - var mob = mobDict.ElementAt(i).Value; - - if (map[mob.YPos][0].Equals(biomeDict["Water"].Floor)) + foreach(var biome in biomeDict.Values) { - if (mob.LungCapacity > 0) mob.LungCapacity--; - else mob.Health--; + if (biome.Floor == map[mob.YPos][mob.XPos] && biome.Damage > 0) + { + if (mob.LungCapacity > 0 && biome.Suffocate) mob.LungCapacity--; + else mob.Health -= biome.Damage; + + break; + } + else + { + if (mob.LungCapacity < mob.MaxLungCapacity) mob.LungCapacity++; + if (mob.Health < mob.MaxHealth) mob.Health++; + } } - else + + if (mob.Health == 0) mob.Alive = false; + } + + ReWriteScreen(map); + Thread.Sleep(80); + } + + Console.WriteLine("GAME OVER. YOU DIED."); + ConsoleKey endProgram = Console.ReadKey().Key; + } + + private static void DamageDealing(string[] map, ConsoleKey direction) + { + int x = mobDict["Player"].XPos; + int y = mobDict["Player"].YPos; + char weapon = '.'; + + switch (direction) + { + case ConsoleKey.UpArrow: if (y > 0) { y--; weapon = '|'; } break; + case ConsoleKey.DownArrow: if (y < map.Length - 1) { y++; weapon = '|'; } break; + case ConsoleKey.LeftArrow: if (x > 0) { x--; weapon = '-'; } break; + case ConsoleKey.RightArrow: if (x < map.Length * 2 - 1) { x++; weapon = '-'; } break; + } + + if(weapon != '.') + { + Console.SetCursorPosition(x, y); + Console.Write(weapon); + + List<string> damagedMobs = mobDict.Values.Where(m => m.Alive == true && m.XPos == x && m.YPos == y).Select(m => m.Name).ToList(); + if (damagedMobs.Count > 0) + { + foreach (var dMob in damagedMobs) { - if (mob.LungCapacity < mob.MaxLungCapacity) mob.LungCapacity++; - if (mob.Health < mob.MaxHealth) mob.Health++; + mobDict[dMob].Health -= 1; + if (mobDict[dMob].Health == 0) mobDict[dMob].Alive = false; } - - if (mob.Health == 0) mobDict.Remove(mob.Name); } } + + Thread.Sleep(80); } private static void MapGenerate(string[] map) { Random rnd = new Random(); - //map is composed of rows and every row is a different biome + //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)); - map[i] = new string(currBiome.Floor, map.Length * 2); + currBiome = biomeDict.ElementAt(rnd.Next(biomeDict.Count)).Value; + map[i] = map[i] + new string(currBiome.Floor, map.Length * 2 - map[i].Length); } } @@ -109,12 +155,15 @@ namespace Game //Prints the map for (int i = 0; i < map.Length; i++) { - Console.ForegroundColor = biomeDict.Values.ToList().Find(x => x.Floor == map[i][0]).Color; - Console.WriteLine(map[i]); + 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.ForegroundColor = biomeDict.Values.ToList().Find(x => x.Floor == map[i].Last()).Color; + Console.WriteLine(map[i].TrimStart(map[i].First())); } //Prints mobs in their positions - foreach(var mob in mobDict.Values) + foreach(var mob in mobDict.Values.Where(m => m.Alive == true)) { mob.Print(); } @@ -123,7 +172,50 @@ namespace Game Console.SetCursorPosition(0, map.Length + 1); mobDict["Player"].PrintStats(); + //Console.WriteLine(biomeDict.Values.ToList().Find(b => map[mobDict["Player"].YPos][mobDict["Player"].XPos] == b.Floor).Name); + Console.CursorVisible = false; } + + private static int MapSize() + { + int size = 0; + int y = 1; + + while (size == 0) + { + Console.Clear(); + + Console.ForegroundColor = ConsoleColor.Gray; + Console.WriteLine("Choose map size:"); + Console.WriteLine("-Small"); + Console.WriteLine("-Medium"); + Console.WriteLine("-Large"); + + 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: size = 5; break; + case 2: size = 10; break; + case 3: size = 20; break; + } + } break; + } + } + + return size; + } } } diff --git a/Bitspace/Game.exe b/Bitspace/Game.exe Binary files differnew file mode 100644 index 0000000..5c47902 --- /dev/null +++ b/Bitspace/Game.exe |
