aboutsummaryrefslogtreecommitdiff
path: root/Bitspace
diff options
context:
space:
mode:
authorSyndamia <kami02882@gmail.com>2019-04-23 11:18:32 +0300
committerSyndamia <kami02882@gmail.com>2019-04-23 11:18:32 +0300
commitcac27eb5957559194c66dbf2f1784a03710a37bd (patch)
treebb077b60238fc835e930a0e752d9771e96f3b796 /Bitspace
parentd6133872475adc6eb367f96b81a30637dd5f77b4 (diff)
downloadShower-cac27eb5957559194c66dbf2f1784a03710a37bd.tar
Shower-cac27eb5957559194c66dbf2f1784a03710a37bd.tar.gz
Shower-cac27eb5957559194c66dbf2f1784a03710a37bd.zip
Added comments that exaplin a bit more the code
Diffstat (limited to 'Bitspace')
-rw-r--r--Bitspace/Bitspace/Program.cs38
-rw-r--r--Bitspace/Bitspace/Weapon.cs2
2 files changed, 22 insertions, 18 deletions
diff --git a/Bitspace/Bitspace/Program.cs b/Bitspace/Bitspace/Program.cs
index 3524218..172c42c 100644
--- a/Bitspace/Bitspace/Program.cs
+++ b/Bitspace/Bitspace/Program.cs
@@ -41,8 +41,6 @@ namespace Game
static void Main(string[] args)
{
-
-
Console.BackgroundColor = ConsoleColor.Black;
StartMenu();
int s = MapSize();
@@ -52,15 +50,15 @@ namespace Game
string[] map = new string[s];
MapGenerate(map);
- ulong gameTick = 0;
+ ulong gameTick = 0; //we use a var so that movement is as fast as possible, but taking damage, healing, drowning, ... is slower
while (mobDict["Player"].Alive == true)
{
if (Console.KeyAvailable) // checkes if the player has pressed any key
{
var keyPressed = Console.ReadKey().Key;
- //changes player position depending on pressed key
- //we can't use switch, because it requires constant values, i.e. not variables, so with switch you can't customise buttons
+ //changes player position and swings weapon depending on pressed key
+ //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 == keysDict["forward"])
{ if (mobDict["Player"].YPos > 0) mobDict["Player"].YPos--; }
@@ -125,7 +123,8 @@ namespace Game
ReWriteScreen(map);
gameTick++;
- foreach(var dead in mobDict.Values.Where(m => m.Health < 1))
+ //mobs that have health <= 0 are "killed", i.e. var alive is false
+ foreach(var dead in mobDict.Values.Where(m => m.Health <= 0))
{ dead.Alive = false; }
for(int i = 0; i < 34000000; i++)
@@ -151,11 +150,12 @@ namespace Game
Console.ForegroundColor = biomeDict.Values.ToList().Find(x => x.Floor == map[i].Last()).Color;
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.Alive == true))
{
- if(mob.YPos == i) mob.Print();
+ //this prints all mobs that are on the line that was just drawn
+ 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
if (mob.WeaponsList.Count > 0 && i == mob.YPos + 1)
{
foreach (var weapon in mob.WeaponsList)
@@ -178,7 +178,7 @@ namespace Game
private static void StartMenu()
{
Console.CursorVisible = false;
- int y = 0;
+ int y = 0; //tracks cursor position
bool stop = false;
while (!stop)
@@ -211,7 +211,7 @@ namespace Game
{
Mob player = mobDict["Player"];
bool stop = false;
- int y = 1;
+ int y = 1; // tracks cursor position
while (!stop)
{
@@ -262,16 +262,17 @@ namespace Game
}
}
- if (y == 3) KeyBindings();
+ //this is not in switch, so when you exit key bindings and then exit settings, you go into the start menu, you don't continue with settings loop
+ if (y == 3) KeyBindings();
else StartMenu();
}
private static void KeyBindings()
{
bool stop = false;
- int y = 1;
- int x = 0;
- string key = null;
+ int y = 1; //tracks position of cursor
+ int x = 0; // used to change cursor position when changing a button
+ string key = null; //tracks which button should be changed
while (!stop)
{
@@ -336,7 +337,7 @@ namespace Game
private static int MapSize()
{
int size = 0;
- int y = 1;
+ int y = 1; //tracks cursor position
while (size == 0)
{
@@ -402,13 +403,13 @@ namespace Game
{
if (rnd.Next(5) > 0) // 4/5 chance if the biome will suffocate and hurt
{
- //for all biomes that hurt but don't suffocate, choose a random one of them
+ //for all biomes that hurt and suffocate, chose a random one of them
currBiome = biomeDict.Where(x => x.Value.Damage > 0 && x.Value.Suffocate)
.ElementAt(rnd.Next(biomeDict.Count(x => x.Value.Damage > 0 && x.Value.Suffocate))).Value;
}
else
{
- //for all biomes that hurt and suffocate, chose a random one of them
+ //for all biomes that hurt but don't suffocate, choose a random one of them
currBiome = biomeDict.Where(x => x.Value.Damage > 0 && !x.Value.Suffocate)
.ElementAt(rnd.Next(biomeDict.Count(x => x.Value.Damage > 0 && !x.Value.Suffocate))).Value;
}
@@ -419,7 +420,7 @@ namespace Game
private static ConsoleColor ColorPicker(ConsoleColor defaultColor)
{
- int y = 1;
+ int y = 1; //tracks cursor position
while (true)
{
@@ -431,6 +432,7 @@ namespace Game
Console.ForegroundColor = defaultColor;
Console.WriteLine($" Default");
+ //not using a cycle, because where the console colors are situated is a bit too advanced (this game's idea is to mostly train my knowledge)
Console.ForegroundColor = ConsoleColor.Black;
Console.WriteLine($" Black");
diff --git a/Bitspace/Bitspace/Weapon.cs b/Bitspace/Bitspace/Weapon.cs
index b2a1392..522b6dc 100644
--- a/Bitspace/Bitspace/Weapon.cs
+++ b/Bitspace/Bitspace/Weapon.cs
@@ -37,8 +37,10 @@ namespace Game
case 4: if (yPos < maxY - 1) yPos++; break;
}
+ //prints weapon
Console.SetCursorPosition(xPos, yPos); Console.Write(swordChar);
+ //takes all mobs that are in the position of the weapon and remove health/armour points
foreach (var mob in mobsList.Where(m => m.XPos == xPos && m.YPos == yPos))
{
for (int d = Damage; d > 0 && mob.Health > 0; d--)