diff options
| author | Syndamia <kami02882@gmail.com> | 2019-05-14 22:40:19 +0300 |
|---|---|---|
| committer | Syndamia <kami02882@gmail.com> | 2019-05-14 22:40:19 +0300 |
| commit | ae174d115f5139bccbc3362f69902e7f624f221f (patch) | |
| tree | 8514b15e7c59847b753b930354897793a964b14b /Bitspace | |
| parent | 5b6c70a242c37f142dee8642fde3303c7a82c34d (diff) | |
| download | Shower-ae174d115f5139bccbc3362f69902e7f624f221f.tar Shower-ae174d115f5139bccbc3362f69902e7f624f221f.tar.gz Shower-ae174d115f5139bccbc3362f69902e7f624f221f.zip | |
Fixed item breaking, added possibility of a mob to walk over a certain item, fixed inventory scroll issue (#29)
Diffstat (limited to 'Bitspace')
| -rw-r--r-- | Bitspace/Bitspace/Program.cs | 92 | ||||
| -rw-r--r-- | Bitspace/Bitspace/Weapon.cs | 26 | ||||
| -rw-r--r-- | Bitspace/Game.exe | bin | 26624 -> 31232 bytes |
3 files changed, 72 insertions, 46 deletions
diff --git a/Bitspace/Bitspace/Program.cs b/Bitspace/Bitspace/Program.cs index bdc8612..7156953 100644 --- a/Bitspace/Bitspace/Program.cs +++ b/Bitspace/Bitspace/Program.cs @@ -11,6 +11,7 @@ namespace Game { private static string[] map; private static StringBuilder[] objectMap; + private static List<Weapon> objectMapObjectsInfo; private static Dictionary<string, Biome> biomeDict = new Dictionary<string, Biome> { @@ -30,8 +31,9 @@ namespace Game private static Dictionary<string, Weapon> itemDict = new Dictionary<string, Weapon>() { - { "Stick", new Weapon("Stick", 3, 5, 1, '-', '|', false, 1) }, - { "Wall", new Weapon("Wall", 10, 3, 0, 'i', ConsoleColor.Yellow, true, 20) } + { "Stick", new Weapon("Stick", 3, 5, 1, '-', '|', false, false, 1) }, + { "Wall", new Weapon("Wall", 10, 3, 0, 'i', ConsoleColor.Yellow, true, false, 20) }, + { "Bridge", new Weapon("Bridge", 2, 1, 0, 'H', ConsoleColor.Cyan, true, true, 15) } }; private static Dictionary<string, ConsoleKey> keyBindingsDict = new Dictionary<string, ConsoleKey>() @@ -50,10 +52,12 @@ namespace Game //TODO: better weapon adding to mobs mobDict["Player"].ItemsList.Add(itemDict["Stick"]); mobDict["Player"].ItemsList.Add(itemDict["Wall"]); + mobDict["Player"].ItemsList.Add(itemDict["Bridge"]); mobDict["Player"].SelectedItem = 1; map = new string[s]; objectMap = new StringBuilder[s]; + objectMapObjectsInfo = new List<Weapon>(); GenerateMap(map); ulong gameTick = 0; //this is so that stuff like taking damage, drowning, ... is a bit slower than the almost instant game refresh @@ -64,28 +68,40 @@ namespace Game var keyPressed = Console.ReadKey().Key; int playerYPos = mobDict["Player"].YPos, playerXPos = mobDict["Player"].XPos; - //we can't use switch, because it requires constant values, i.e. not variables, so with switch you can't customise button mappings - if (keyPressed == keyBindingsDict["forward"]) - { if (playerYPos > 0 && objectMap[playerYPos - 1][playerXPos] == '\0') mobDict["Player"].YPos--; } + try + { + //we can't use switch, because it requires constant values, i.e. not variables, so with switch you can't customise button mappings + if (keyPressed == keyBindingsDict["forward"] && playerYPos > 0) + { + if (objectMap[playerYPos - 1][playerXPos] == '\0') mobDict["Player"].YPos--; + else if (objectMapObjectsInfo.Single(o => o.YPos == playerYPos - 1 && o.XPos == playerXPos).WalkOver) mobDict["Player"].YPos--; + } - else if (keyPressed == keyBindingsDict["backward"]) - { if (playerYPos < map.Length - 1 && objectMap[playerYPos + 1][playerXPos] == '\0') mobDict["Player"].YPos++; } + else if (keyPressed == keyBindingsDict["backward"] && playerYPos < map.Length - 1) + { + if (objectMap[playerYPos + 1][playerXPos] == '\0') mobDict["Player"].YPos++; + else if (objectMapObjectsInfo.Single(o => o.YPos == playerYPos + 1 && o.XPos == playerXPos).WalkOver) mobDict["Player"].YPos++; + } - else if (keyPressed == keyBindingsDict["left"]) - { if (playerXPos > 0 && objectMap[playerYPos][playerXPos - 1] == '\0') mobDict["Player"].XPos--; } + else if (keyPressed == keyBindingsDict["left"] && playerXPos > 0) + { + if (objectMap[playerYPos][playerXPos - 1] == '\0') mobDict["Player"].XPos--; + else if (objectMapObjectsInfo.Single(o => o.YPos == playerYPos && o.XPos == playerXPos - 1).WalkOver) mobDict["Player"].XPos--; + } - else if (keyPressed == keyBindingsDict["right"]) - { if (playerXPos < map.Length * 2 - 1 && objectMap[playerYPos][playerXPos + 1] == '\0') mobDict["Player"].XPos++; } + else if (keyPressed == keyBindingsDict["right"] && playerXPos < map.Length * 2 - 1) + { + if (objectMap[playerYPos][playerXPos + 1] == '\0') mobDict["Player"].XPos++; + else if (objectMapObjectsInfo.Single(o => o.YPos == playerYPos && o.XPos == playerXPos + 1).WalkOver) mobDict["Player"].XPos++; + } - else if (keyPressed == keyBindingsDict["itemsLeft"]) - { if (mobDict["Player"].SelectedItem > 1) mobDict["Player"].SelectedItem--; } + 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++; } + else if (keyPressed == keyBindingsDict["itemsRight"]) + { if (mobDict["Player"].SelectedItem < mobDict["Player"].Slots) mobDict["Player"].SelectedItem++; } - try - { - if (keyPressed == keyBindingsDict["swingLeft"]) + else if (keyPressed == keyBindingsDict["swingLeft"]) { mobDict["Player"].ItemsList[mobDict["Player"].SelectedItem - 1].Direction = "left"; } // 1 else if (keyPressed == keyBindingsDict["swingRight"]) @@ -189,7 +205,7 @@ namespace Game { var biome = biomeDict.Values.Where(b => b.Floor == map[mob.YPos][mob.XPos]).Single(); - if (biome.Damage > 0) + if (biome.Damage > 0 && objectMap[mob.YPos][mob.XPos] == '\0') { if (biome.Suffocate && mob.LungCapacity > 0) mob.LungCapacity--; else mob.Health -= biome.Damage; @@ -221,16 +237,18 @@ namespace Game if (objectMap[row][col] != '\0') { - try + Weapon currItem = objectMapObjectsInfo.Single(w => w.XPos == col && w.YPos == row); + + if (currItem.Health <= 0) { - if (itemDict.Values.First(x => x.XPos == col && x.YPos == row).Health <= 0) objectMap[row][col] = '\0'; - else throw new Exception(); + objectMap[row][col] = '\0'; + objectMapObjectsInfo.Remove(currItem); } - catch (Exception) + else { Console.ForegroundColor = itemDict.Values.First(x => x.SkinUp == objectMap[row][col]).Color; Console.Write(objectMap[row][col]); - }; + } } } Console.WriteLine(); @@ -245,26 +263,26 @@ namespace Game { try { - var item = mob.ItemsList[mob.SelectedItem - 1]; + var selectedItem = mob.ItemsList[mob.SelectedItem - 1]; - if (!item.Placable) item.PrintAndDoDamage(mob, mobDict, itemDict, map.Length * 2, map.Length); + if (!selectedItem.Placable) selectedItem.PrintAndDoDamage(mob, mobDict, objectMapObjectsInfo, map.Length * 2, map.Length); - else if (item.Direction != null) + else if (selectedItem.Direction != null) { - item.WeaponPosition(mob, map.Length * 2, map.Length); + selectedItem.WeaponPosition(mob, map.Length * 2, map.Length); - if (objectMap[item.YPos][item.XPos] == '\0') + if (objectMap[selectedItem.YPos][selectedItem.XPos] == '\0') { - objectMap[item.YPos][item.XPos] = item.SkinUp; - item.Amount--; + objectMapObjectsInfo.Add(new Weapon(selectedItem.Name, selectedItem.Health, selectedItem.HealthDamage, selectedItem.BreakDamage, selectedItem.SkinLeft, selectedItem.SkinRight, selectedItem.SkinUp, selectedItem.SkinDown, selectedItem.Color, true, selectedItem.WalkOver, 1, selectedItem.XPos, selectedItem.YPos)); + objectMap[selectedItem.YPos][selectedItem.XPos] = selectedItem.SkinUp; + selectedItem.Amount--; - if (item.Amount == 0) mob.ItemsList.Remove(item); + if (selectedItem.Amount == 0) mob.ItemsList.Remove(selectedItem); } - } + } - item.Direction = null; - } - catch (Exception) { } + selectedItem.Direction = null; + } catch (Exception) { } } } Console.SetCursorPosition(0, row + 1); @@ -280,7 +298,7 @@ namespace Game Console.WriteLine(mob.Stats()); } - foreach(var breakable in itemDict.Values.Where(b => b.BrokenByPlayer)) + foreach(var breakable in objectMapObjectsInfo.Where(b => b.BrokenByPlayer)) { Console.WriteLine(breakable.Stats()); } diff --git a/Bitspace/Bitspace/Weapon.cs b/Bitspace/Bitspace/Weapon.cs index a1ab064..5f73021 100644 --- a/Bitspace/Bitspace/Weapon.cs +++ b/Bitspace/Bitspace/Weapon.cs @@ -27,13 +27,14 @@ namespace Game private char skinDown; private bool placable; + private bool walkOver; private byte amount; - public void PrintAndDoDamage(Mob fightingMob, Dictionary<string, Mob> mobDict, Dictionary<string, Weapon> itemsDict, int maxX, int maxY) + public void PrintAndDoDamage(Mob fightingMob, Dictionary<string, Mob> mobDict, List<Weapon> objectMapObjectsInfo, int maxX, int maxY) { Print(fightingMob, maxX, maxY); DoHealthDamage(mobDict, fightingMob); - DoBreakDamage(itemsDict, fightingMob); + DoBreakDamage(objectMapObjectsInfo, fightingMob); } private void Print(Mob fightingMob, int maxX, int maxY) @@ -71,11 +72,11 @@ namespace Game } } - private void DoBreakDamage(Dictionary<string, Weapon> itemsDict, Mob fightingMob) + private void DoBreakDamage(List<Weapon> objectMapObjectsInfo, Mob fightingMob) { if (WeaponIsSwung()) { - foreach (var obj in itemsDict.Values.Where(o => (o.XPos == XPos && o.YPos == YPos) && o.Health > 0 && o != fightingMob.ItemsList[fightingMob.SelectedItem - 1])) + foreach (var obj in objectMapObjectsInfo.Where(o => (o.XPos == XPos && o.YPos == YPos) && o.Health > 0 && o != fightingMob.ItemsList[fightingMob.SelectedItem - 1])) { if (fightingMob.Name == "Player") obj.BrokenByPlayer = true; @@ -114,19 +115,22 @@ namespace Game } } - public Weapon(string name, int health, ushort healthDamage, ushort breakDamage, char tetraChar, bool placeable, byte amount) : this(name, health, healthDamage, breakDamage, tetraChar, tetraChar, tetraChar, tetraChar, ConsoleColor.Gray, placeable, amount) + public Weapon(string name, int health, ushort healthDamage, ushort breakDamage, char tetraChar, bool placeable, bool walkOver, byte amount) : this(name, health, healthDamage, breakDamage, tetraChar, tetraChar, tetraChar, tetraChar, ConsoleColor.Gray, placeable, walkOver, amount, 0, 0) { } - public Weapon(string name, int health, ushort healthDamage, ushort breakDamage, char tetraChar, ConsoleColor color, bool placeable, byte amount) : this(name, health, healthDamage, breakDamage, tetraChar, tetraChar, tetraChar, tetraChar, color, placeable, amount) + public Weapon(string name, int health, ushort healthDamage, ushort breakDamage, char tetraChar, ConsoleColor color, bool placeable, bool walkOver, byte amount) : this(name, health, healthDamage, breakDamage, tetraChar, tetraChar, tetraChar, tetraChar, color, placeable, walkOver, amount, 0, 0) { } - public Weapon(string name, int health, ushort healthDamage, ushort breakDamage, char leftRight, char upDown, bool placeable, byte amount) : this(name, health, healthDamage, breakDamage, leftRight, leftRight, upDown, upDown, ConsoleColor.Gray, placeable, amount) + public Weapon(string name, int health, ushort healthDamage, ushort breakDamage, char leftRight, char upDown, bool placeable, bool walkOver, byte amount) : this(name, health, healthDamage, breakDamage, leftRight, leftRight, upDown, upDown, ConsoleColor.Gray, placeable, walkOver, amount, 0, 0) { } - public Weapon(string name, int health, ushort healthDamage, ushort breakDamage, char leftRight, char upDown, ConsoleColor color, bool placeable, byte amount) : this(name, health, healthDamage, breakDamage, leftRight, leftRight, upDown, upDown, color, placeable, amount) + public Weapon(string name, int health, ushort healthDamage, ushort breakDamage, char leftRight, char upDown, ConsoleColor color, bool placeable, bool walkOver, byte amount) : this(name, health, healthDamage, breakDamage, leftRight, leftRight, upDown, upDown, color, placeable, walkOver, amount, 0, 0) { } - public Weapon(string name, int health, ushort healthDamage, ushort breakDamage, char skinLeft, char skinRight, char skinUp, char skinDown, ConsoleColor color, bool placable ,byte amount) + public Weapon(string name, int health, ushort healthDamage, ushort breakDamage, char skinLeft, char skinRight, char skinUp, char skinDown, ConsoleColor color, bool placable, bool walkOver, byte amount) : this(name, health, healthDamage, breakDamage, skinLeft, skinRight, skinUp, skinDown, color, placable, walkOver, amount, 0, 0) + { } + + public Weapon(string name, int health, ushort healthDamage, ushort breakDamage, char skinLeft, char skinRight, char skinUp, char skinDown, ConsoleColor color, bool placable, bool walkOver, byte amount, int xPos, int yPos) { Health = health; HealthDamage = healthDamage; @@ -139,6 +143,9 @@ namespace Game Color = color; Amount = amount; Placable = placable; + WalkOver = walkOver; + XPos = xPos; + YPos = yPos; } public ushort HealthDamage { get => healthDamage; set => healthDamage = value; } @@ -155,5 +162,6 @@ namespace Game public int YPos { get => yPos; private set => yPos = value; } public int Health { get => health; set => health = value; } public ushort BreakDamage { get => breakDamage; set => breakDamage = value; } + public bool WalkOver { get => walkOver; set => walkOver = value; } } } diff --git a/Bitspace/Game.exe b/Bitspace/Game.exe Binary files differindex bc70101..1636066 100644 --- a/Bitspace/Game.exe +++ b/Bitspace/Game.exe |
