Browse Source

some action added + ROCKS!!! )))

master
parent
commit
f3e1786fbd
  1. 57
      theGame/Game.cs
  2. 6
      theGame/Item.cs
  3. 17
      theGame/ItemPoint.cs
  4. 18
      theGame/PlayerCraft.cs
  5. 82
      theGame/Program.cs
  6. 1
      theGame/theGame.csproj

57
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<Item> 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>();
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--;
}
}
}
}

6
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<ItemPoint> points;
public Item()
{
sizeWidth = 0;
@ -16,6 +20,8 @@ namespace theGame
positionX = 0;
positionY = 0;
points = new List<ItemPoint>();
}
}
}

17
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 = '*';
}
}
}

18
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<ItemPoint>();
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 = '_' });
}
}
}

82
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)
string top_line = string.Empty;
for (int i = 0; i < game.ViewWidth + 2; i++)
{
Console.WriteLine("|---");
line_printed = true;
top_line += "-";
}
Console.WriteLine(top_line);
for (int i = 0; i < game.ViewHeight; i++)
{
int lineNumber = i;
string line = "|";
if (game.playerCraft.positionY == i)
for (int j = 0; j < game.ViewWidth; j++)
{
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)
{
Console.WriteLine("| ###");
line_printed = true;
if (r.positionX + point.relativeCordX == colNumber)
{
line += point.symbol;
col_added_to_print = true;
}
}
}
}
if (!line_printed)
if (!col_added_to_print)
{
Console.WriteLine("|");
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;

1
theGame/theGame.csproj

@ -37,6 +37,7 @@
<Compile Include="Item.cs" />
<Compile Include="PlayerCraft.cs" />
<Compile Include="Game.cs" />
<Compile Include="ItemPoint.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
Loading…
Cancel
Save