-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBoard.cs
59 lines (49 loc) · 1.88 KB
/
Board.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
namespace Treblecross
{
public class Board
{
private readonly int dimension_x;
private readonly int dimension_y;
public int[] Size => [dimension_y, dimension_x];
public GameState CurrentState { get; set; }
private string[,] displayedAry {get; set;}
public Board(int x, int y) {
dimension_x = x;
dimension_y = y;
GameState gameState = new GameState(new int[x,y]);
displayedAry = new string[gameState.State.GetLength(0), gameState.State.GetLength(1)];
CurrentState = gameState;
}
public Board(int x, int y, GameState state) {
dimension_x = x;
dimension_y = y;
displayedAry = new string[state.State.GetLength(0), state.State.GetLength(1)];
CurrentState = state;
}
public void Draw () {
if (CurrentState.State.GetLength(0) == 1) {
displayedAry = new string[CurrentState.State.GetLength(0), CurrentState.State.GetLength(1)];
if (CurrentState.Player == null) {
// init
Console.WriteLine("[{0}]", string.Join(", ", Common<string>.Convert1dArray(displayedAry)));
return;
}
for (int i=0; i < CurrentState.State.GetLength(1); i++) {
if (CurrentState.State[0, i] != 0) {
displayedAry[0, i] = CurrentState.Player.Piece.Print();
}
}
Console.WriteLine("[{0}]", string.Join(", ", Common<string>.Convert1dArray(displayedAry)));
} else {
// 2D board ..
}
}
public void Update(GameState state) {
CurrentState = state;
Draw();
}
public void Load(GameState state) {
Update(state);
}
}
}