-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
91 lines (88 loc) · 2.69 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
namespace Space_Invaders_2
{
class Program
{
static void Main(string[] args)
{
World world = new World();
Player p = new Player();
File.WriteAllText("data.txt", "10");
world.ghostMap = new Ghost[world.ghCntY + 1, world.ghCntX + 1];
int ghStartX = (world.wallX1 + world.wallX2) / 2 - world.ghCntX - 1;
for (int y = 1; y <= world.ghCntY; y++)
{
for (int x = 1; x <= world.ghCntX; x++)
{
world.ghostMap[y, x] = new Ghost(2 * y, ghStartX + 2 * x);
}
}
Thread t = new Thread(input);
t.Start();
while (!world.GameOver)
{
world.ShowWall();
for (int y = 1; y <= world.ghCntY; y++)
{
for (int x = 1; x <= world.ghCntX; x++)
{
world.ghostMap[y, x].Show();
}
}
if (File.Exists("data.txt"))
{
try
{
p.setx(int.Parse(File.ReadAllText("data.txt")));
File.Delete("data.txt");
}
catch (IOException e)
{
}
}
p.Show();
Thread.Sleep(200);
world.MoveGhosts();
Console.Clear();
}
}
static void input()
{
Player p = new Player();
int cord = 10;
while (true)
{
Console.SetCursorPosition(27, 27);
ConsoleKeyInfo key = Console.ReadKey();
if (key.Key == ConsoleKey.LeftArrow)
{
p.move(-1);
}
else if (key.Key == ConsoleKey.RightArrow)
{
p.move(1);
}
else if (key.Key == ConsoleKey.Spacebar)
{
p.shoot();
}
cord = p.getx();
try
{
File.WriteAllText("data.txt", cord.ToString());
}
catch (IOException e)
{
}
Thread.Sleep(30);
}
}
}
}