Browse Source

First interactive things

master
parent
commit
0b4278e9ee
  1. 23
      theGame/Game.cs
  2. 21
      theGame/Item.cs
  3. 12
      theGame/PlayerCraft.cs
  4. 67
      theGame/Program.cs
  5. 3
      theGame/theGame.csproj

23
theGame/Game.cs

@ -0,0 +1,23 @@
using System;
namespace theGame
{
public class Game
{
public bool GameOver;
private int hitCount;
public PlayerCraft playerCraft;
public Game()
{
this.GameOver = false;
this.hitCount = 0;
this.playerCraft = new PlayerCraft();
playerCraft.positionX = 10;
playerCraft.positionY = 12;
}
}
}

21
theGame/Item.cs

@ -0,0 +1,21 @@
using System;
namespace theGame
{
public class Item
{
public int positionX;
public int positionY;
public int sizeWidth;
public int sizeHeight;
public Item()
{
sizeWidth = 0;
sizeHeight = 0;
positionX = 0;
positionY = 0;
}
}
}

12
theGame/PlayerCraft.cs

@ -0,0 +1,12 @@
using System;
namespace theGame
{
public class PlayerCraft : Item
{
int Health;
public PlayerCraft()
{
Health = 100;
}
}
}

67
theGame/Program.cs

@ -7,6 +7,73 @@ namespace theGame
public static void Main(string[] args) public static void Main(string[] args)
{ {
Console.WriteLine("Hello World!"); Console.WriteLine("Hello World!");
Console.WriteLine("Hello World!");
Console.WriteLine("Hello World!");
Game game = new Game();
System.Threading.Thread th = new System.Threading.Thread(GetKeys);
th.Start(game);
while (game.GameOver != true)
{
System.Threading.Thread.Sleep(100);
Console.SetWindowSize(80, 25);
Console.Clear();
for (int i = 0; i < 20; i++)
{
int lineNumber = i + 1;
bool line_printed = false;
if (lineNumber == 1 || lineNumber == 20)
{
Console.WriteLine("|---");
line_printed = true;
}
if (game.playerCraft.positionY == i)
{
Console.WriteLine("| ###");
line_printed = true;
}
if (!line_printed)
{
Console.WriteLine("|");
}
}
}
}
public static void GetKeys(object game_object)
{
Game game = new Game();
game.GameOver = true;
if (game_object is Game)
{
game = (Game)game_object;
}
ConsoleKeyInfo key_info = Console.ReadKey(true);
while (key_info.Key != ConsoleKey.Q)
{
if (key_info.Key != ConsoleKey.UpArrow)
{
game.playerCraft.positionY += 1;
}
if (key_info.Key != ConsoleKey.DownArrow)
{
game.playerCraft.positionY -= 1;
}
key_info = Console.ReadKey(true);
}
game.GameOver = true;
} }
} }
} }

3
theGame/theGame.csproj

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