-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameFIeld.cs
88 lines (78 loc) · 6.4 KB
/
GameFIeld.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
namespace pac_man
{
internal class GameField
{
private const int Offset = 3;
private readonly char[][] StartField = {
['▒','▒','▒','▒','▒','▒','▒','▒','▒','▒','▒','▒','▒','▒','▒','▒','▒','▒','▒','▒','▒','▒','▒','▒','▒','▒','▒','▒'],
['▒','·','·','·','·','·','·','·','·','·','·','·','·','▒','▒','·','·','·','·','·','·','·','·','·','·','·','·','▒'],
['▒','·','▒','▒','▒','▒','·','▒','▒','▒','▒','▒','·','▒','▒','·','▒','▒','▒','▒','▒','·','▒','▒','▒','▒','·','▒'],
['▒','·','▒','▒','▒','▒','·','▒','▒','▒','▒','▒','·','▒','▒','·','▒','▒','▒','▒','▒','·','▒','▒','▒','▒','·','▒'],
['▒','·','▒','▒','▒','▒','·','▒','▒','▒','▒','▒','·','▒','▒','·','▒','▒','▒','▒','▒','·','▒','▒','▒','▒','·','▒'],
['▒','·','·','·','·','·','·','·','·','·','·','·','·','·','·','·','·','·','·','·','·','·','·','·','·','·','·','▒'],
['▒','·','▒','▒','▒','▒','·','▒','▒','·','▒','▒','▒','▒','▒','▒','▒','▒','·','▒','▒','·','▒','▒','▒','▒','·','▒'],
['▒','·','▒','▒','▒','▒','·','▒','▒','·','▒','▒','▒','▒','▒','▒','▒','▒','·','▒','▒','·','▒','▒','▒','▒','·','▒'],
['▒','·','·','·','·','·','·','▒','▒','·','·','·','·','▒','▒','·','·','·','·','▒','▒','·','·','·','·','·','·','▒'],
['▒','▒','▒','▒','▒','▒','·','▒','▒','▒','▒','▒',' ','▒','▒',' ','▒','▒','▒','▒','▒','·','▒','▒','▒','▒','▒','▒'],
[' ',' ',' ',' ',' ','▒','·','▒','▒','▒','▒','▒',' ','▒','▒',' ','▒','▒','▒','▒','▒','·','▒',' ',' ',' ',' ',' '],
[' ',' ',' ',' ',' ','▒','·','▒','▒',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','▒','▒','·','▒',' ',' ',' ',' ',' '],
[' ',' ',' ',' ',' ','▒','·','▒','▒',' ','▒','▒','▒',' ',' ','▒','▒','▒',' ','▒','▒','·','▒',' ',' ',' ',' ',' '],
['▒','▒','▒','▒','▒','▒','·','▒','▒',' ','▒',' ',' ',' ',' ',' ',' ','▒',' ','▒','▒','·','▒','▒','▒','▒','▒','▒'],
[' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','▒',' ',' ',' ',' ',' ',' ','▒',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '],
['▒','▒','▒','▒','▒','▒','·','▒','▒',' ','▒',' ',' ',' ',' ',' ',' ','▒',' ','▒','▒','·','▒','▒','▒','▒','▒','▒'],
[' ',' ',' ',' ',' ','▒','·','▒','▒',' ','▒','▒','▒','▒','▒','▒','▒','▒',' ','▒','▒','·','▒',' ',' ',' ',' ',' '],
[' ',' ',' ',' ',' ','▒','·','▒','▒',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','▒','▒','·','▒',' ',' ',' ',' ',' '],
['▒','▒','▒','▒','▒','▒','·','▒','▒',' ','▒','▒','▒','▒','▒','▒','▒','▒',' ','▒','▒','·','▒','▒','▒','▒','▒','▒'],
['▒','·','·','·','·','·','·','·','·','·','·','·','·','▒','▒','·','·','·','·','·','·','·','·','·','·','·','·','▒'],
['▒','·','▒','▒','▒','▒','·','▒','▒','▒','▒','▒','·','▒','▒','·','▒','▒','▒','▒','▒','·','▒','▒','▒','▒','·','▒'],
['▒','·','▒','▒','▒','▒','·','▒','▒','▒','▒','▒','·','▒','▒','·','▒','▒','▒','▒','▒','·','▒','▒','▒','▒','·','▒'],
['▒','·','·','·','▒','▒','·','·','·','·','·','·','·',' ',' ','·','·','·','·','·','·','·','▒','▒','·','·','·','▒'],
['▒','▒','▒','·','▒','▒','·','▒','▒','·','▒','▒','▒','▒','▒','▒','▒','▒','·','▒','▒','·','▒','▒','·','▒','▒','▒'],
['▒','▒','▒','·','▒','▒','·','▒','▒','·','▒','▒','▒','▒','▒','▒','▒','▒','·','▒','▒','·','▒','▒','·','▒','▒','▒'],
['▒','·','·','·','·','·','·','▒','▒','·','·','·','·','▒','▒','·','·','·','·','▒','▒','·','·','·','·','·','·','▒'],
['▒','·','▒','▒','▒','▒','▒','▒','▒','▒','▒','▒','·','▒','▒','·','▒','▒','▒','▒','▒','▒','▒','▒','▒','▒','·','▒'],
['▒','·','▒','▒','▒','▒','▒','▒','▒','▒','▒','▒','·','▒','▒','·','▒','▒','▒','▒','▒','▒','▒','▒','▒','▒','·','▒'],
['▒','·','·','·','·','·','·','·','·','·','·','·','·','·','·','·','·','·','·','·','·','·','·','·','·','·','·','▒'],
['▒','▒','▒','▒','▒','▒','▒','▒','▒','▒','▒','▒','▒','▒','▒','▒','▒','▒','▒','▒','▒','▒','▒','▒','▒','▒','▒','▒']
};
public int Width { get; }
public int Height { get; }
private char[][] Field;
public GameField()
{
Field = StartField;
Height = Field.GetLength(0);
Width = Field[0].GetLength(0);
}
public void UpdateCharacterPos((int x, int y) newPos, char Character)
{
Console.SetCursorPosition(newPos.y, newPos.x + Offset);
Console.Write(Character);
Console.SetCursorPosition(0, 0);
}
public bool ValidPosition((int x, int y) pos)
{
if (pos.x < 0 || Height <= pos.x) return false;
if (pos.y < 0 || Width <= pos.y) return false;
char c = Field[pos.x][pos.y];
return c is ' ' or '·';
}
public bool ConsumeToken((int x, int y) pos)
{
if (pos.x < 0 || Height <= pos.x) return false;
if (pos.y < 0 || Width <= pos.y) return false;
char c = Field[pos.x][pos.y];
if (c == '·') { Field[pos.x][pos.y] = ' '; return true; }
return false;
}
public void Redraw()
{
for (int i = 0; i < Height; i++)
{
Console.SetCursorPosition(0, i + Offset);
Console.Write(Field[i]);
Console.SetCursorPosition(0, 0);
}
}
}
}