-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameField.cs
91 lines (86 loc) · 2.61 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
89
90
91
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Snake
{
class GameField
{
public int Width { get; set; }
public int Height { get; set; }
private List<List<Cell>> _field = new List<List<Cell>>();
public List<List<Cell>> Field
{
get { return _field; }
}
public GameField(int aWidth, int aHeight)
{
Width = aWidth;
Height = aHeight;
InitField();
}
private void InitField()
{
for (int i = 0; i < Height; i++)
{
List<Cell> lRow = new List<Cell>();
for (int j = 0; j < Width; j++)
{
Cell lCell = new Cell(" ", ConsoleColor.White);
lRow.Add(lCell);
}
_field.Add(lRow);
}
}
public void ClearField()
{
for (int i = 0; i < Height; i++)
{
//List<string> lRow = new List<string>();
for (int j = 0; j < Width; j++)
{
_field[i][j].Val = " ";
_field[i][j].Color = ConsoleColor.White;
}
}
}
public void Draw()
{
Console.Clear();
Console.CursorVisible = false;
Console.ForegroundColor = ConsoleColor.White;
for (int i = 0; i < Width + 2; i++)
{
Console.Write("#");
}
Console.WriteLine();
//Console.ForegroundColor = ConsoleColor.White;
for (int i = 0; i < Height; i++)
{
for (int j = 0; j < Width + 2; j++)
{
if (j == 0 || j == Width + 1)
{
Console.ForegroundColor = ConsoleColor.White;
Console.Write("#");
//Console.ForegroundColor = ConsoleColor.White;
}
else
{
Console.ForegroundColor = _field[i][j - 1].Color;
Console.Write(_field[i][j - 1].Val);
}
}
Console.WriteLine();
}
Console.ForegroundColor = ConsoleColor.White;
for (int i = 0; i < Width + 2; i++)
{
Console.Write("#");
}
Console.WriteLine();
//Console.ForegroundColor = ConsoleColor.White;
}
}
}