diff --git a/theGame/Game.cs b/theGame/Game.cs index 2cef6fa..319458b 100644 --- a/theGame/Game.cs +++ b/theGame/Game.cs @@ -1,23 +1,72 @@ using System; +using System.Collections.Generic; + namespace theGame { public class Game { public bool GameOver; - private int hitCount; - public PlayerCraft playerCraft; + public int ViewWidth; + public int ViewHeight; + + public List rocks; + public Game() { this.GameOver = false; - this.hitCount = 0; + this.ViewWidth = 78; + this.ViewHeight = 20; this.playerCraft = new PlayerCraft(); - playerCraft.positionX = 10; + playerCraft.positionX = 7; playerCraft.positionY = 12; + + rocks = new List(); + + Item rock1 = new Item(); + rock1.points.Add(new ItemPoint() { relativeCordX = 0, relativeCordY = 0, symbol = '#' }); + rock1.points.Add(new ItemPoint() { relativeCordX = -1, relativeCordY = 0, symbol = '#' }); + rock1.points.Add(new ItemPoint() { relativeCordX = 1, relativeCordY = 0, symbol = '#' }); + rock1.points.Add(new ItemPoint() { relativeCordX = 0, relativeCordY = 1, symbol = '#' }); + rock1.points.Add(new ItemPoint() { relativeCordX = 0, relativeCordY = -1, symbol = '#' }); + rock1.positionX = 80; + rock1.positionY = 5; + + Item rock2 = new Item(); + rock2.points.Add(new ItemPoint() { relativeCordX = 0, relativeCordY = 0, symbol = '#' }); + rock2.points.Add(new ItemPoint() { relativeCordX = -1, relativeCordY = 0, symbol = '#' }); + rock2.points.Add(new ItemPoint() { relativeCordX = 1, relativeCordY = 0, symbol = '#' }); + rock2.points.Add(new ItemPoint() { relativeCordX = 0, relativeCordY = 1, symbol = '#' }); + rock2.points.Add(new ItemPoint() { relativeCordX = 0, relativeCordY = -1, symbol = '#' }); + rock2.positionX = 85; + rock2.positionY = 13; + + Item rock3 = new Item(); + rock3.points.Add(new ItemPoint() { relativeCordX = 0, relativeCordY = 0, symbol = '#' }); + rock3.points.Add(new ItemPoint() { relativeCordX = -1, relativeCordY = 0, symbol = '#' }); + rock3.points.Add(new ItemPoint() { relativeCordX = 1, relativeCordY = 0, symbol = '#' }); + rock3.points.Add(new ItemPoint() { relativeCordX = 0, relativeCordY = 1, symbol = '#' }); + rock3.points.Add(new ItemPoint() { relativeCordX = 0, relativeCordY = -1, symbol = '#' }); + rock3.positionX = 75; + rock3.positionY = 17; + + rocks.Add(rock1); + rocks.Add(rock2); + rocks.Add(rock3); + + } + + public void DoMoves() + { + for (int i = 0; i < rocks.Count; i++) + { + rocks[i].positionX--; + } + } } } diff --git a/theGame/Item.cs b/theGame/Item.cs index 3a21234..a7409ab 100644 --- a/theGame/Item.cs +++ b/theGame/Item.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; + namespace theGame { public class Item @@ -9,6 +11,8 @@ namespace theGame public int sizeWidth; public int sizeHeight; + public List points; + public Item() { sizeWidth = 0; @@ -16,6 +20,8 @@ namespace theGame positionX = 0; positionY = 0; + + points = new List(); } } } diff --git a/theGame/ItemPoint.cs b/theGame/ItemPoint.cs new file mode 100644 index 0000000..4af934c --- /dev/null +++ b/theGame/ItemPoint.cs @@ -0,0 +1,17 @@ +using System; +namespace theGame +{ + public class ItemPoint + { + public int relativeCordX; + public int relativeCordY; + public char symbol; + + public ItemPoint() + { + this.relativeCordX = 0; + this.relativeCordY = 0; + this.symbol = '*'; + } + } +} diff --git a/theGame/PlayerCraft.cs b/theGame/PlayerCraft.cs index d388804..008c68b 100644 --- a/theGame/PlayerCraft.cs +++ b/theGame/PlayerCraft.cs @@ -1,12 +1,26 @@ using System; +using System.Collections.Generic; namespace theGame { public class PlayerCraft : Item { - int Health; + public int Health; + public PlayerCraft() { - Health = 100; + this.Health = 100; + + // _ + // \___\_> + + this.points = new List(); + this.points.Add(new ItemPoint() { relativeCordX = 0, relativeCordY = 0, symbol = '>' }); + this.points.Add(new ItemPoint() { relativeCordX = -1, relativeCordY = 0, symbol = '_' }); + this.points.Add(new ItemPoint() { relativeCordX = -2, relativeCordY = 0, symbol = '\\' }); + this.points.Add(new ItemPoint() { relativeCordX = -3, relativeCordY = 0, symbol = '_' }); + this.points.Add(new ItemPoint() { relativeCordX = -4, relativeCordY = 0, symbol = '_' }); + this.points.Add(new ItemPoint() { relativeCordX = -5, relativeCordY = 0, symbol = '\\' }); + this.points.Add(new ItemPoint() { relativeCordX = -6, relativeCordY = -1, symbol = '_' }); } } } diff --git a/theGame/Program.cs b/theGame/Program.cs index b507775..ed68e72 100644 --- a/theGame/Program.cs +++ b/theGame/Program.cs @@ -15,34 +15,84 @@ namespace theGame System.Threading.Thread th = new System.Threading.Thread(GetKeys); th.Start(game); + int draw_count = 0; + int action_draw_max = 10; + while (game.GameOver != true) { System.Threading.Thread.Sleep(100); Console.Clear(); - for (int i = 0; i < 20; i++) + if (draw_count > action_draw_max) { - int lineNumber = i + 1; - bool line_printed = false; + game.DoMoves(); + draw_count = 0; + } - if (lineNumber == 1 || lineNumber == 20) - { - Console.WriteLine("|---"); - line_printed = true; - } + string top_line = string.Empty; + for (int i = 0; i < game.ViewWidth + 2; i++) + { + top_line += "-"; + } + Console.WriteLine(top_line); - if (game.playerCraft.positionY == i) - { - Console.WriteLine("| ###"); - line_printed = true; - } + for (int i = 0; i < game.ViewHeight; i++) + { + int lineNumber = i; + + string line = "|"; - if (!line_printed) + for (int j = 0; j < game.ViewWidth; j++) { - Console.WriteLine("|"); + int colNumber = j; + bool col_added_to_print = false; + + foreach (ItemPoint point in game.playerCraft.points) + { + if (game.playerCraft.positionY + point.relativeCordY == lineNumber) + { + if (game.playerCraft.positionX + point.relativeCordX == colNumber) + { + line += point.symbol; + col_added_to_print = true; + } + } + } + + + foreach (Item r in game.rocks) + { + foreach (ItemPoint point in r.points) + { + if (r.positionY + point.relativeCordY == lineNumber) + { + if (r.positionX + point.relativeCordX == colNumber) + { + line += point.symbol; + col_added_to_print = true; + } + } + } + } + + + if (!col_added_to_print) + { + line += ' '; + } } + + line += '|'; + + Console.WriteLine(line); + } + + string bottom_line = string.Format("+-------[Health:{0:D3}]-----------------------------------------------------------+", game.playerCraft.Health); + Console.WriteLine(bottom_line); + + draw_count++; } } @@ -70,6 +120,16 @@ namespace theGame game.playerCraft.positionY -= 1; } + if (key_info.Key != ConsoleKey.RightArrow) + { + game.playerCraft.positionX = game.playerCraft.positionX - 1; + } + + if (key_info.Key != ConsoleKey.LeftArrow) + { + game.playerCraft.positionX = game.playerCraft.positionX + 1; + } + key_info = Console.ReadKey(true); } game.GameOver = true; diff --git a/theGame/theGame.csproj b/theGame/theGame.csproj index 482331d..82e4cea 100644 --- a/theGame/theGame.csproj +++ b/theGame/theGame.csproj @@ -37,6 +37,7 @@ + \ No newline at end of file