-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoard.cs
More file actions
214 lines (184 loc) · 6.78 KB
/
Copy pathBoard.cs
File metadata and controls
214 lines (184 loc) · 6.78 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ex2
{
internal class Board
{
internal class BoardSquare
{
private Location m_Coordinates;
private Piece m_Checker;
internal BoardSquare(eShape i_Shape, Location i_Location, ePlayerColor i_Color)
{
m_Checker = new Piece(i_Location, i_Shape, i_Color);
m_Coordinates = i_Location;
}
internal BoardSquare(Location i_Location)
{
m_Checker = null;
m_Coordinates = i_Location;
}
public Piece BoardSquareChecker
{
get { return m_Checker; }
set { m_Checker = value; }
}
public Location Coordinates
{
get { return m_Coordinates; }
set { m_Coordinates = value; }
}
public eShape GetShape
{
get
{
eShape output;
if (m_Checker == null)
{
output = eShape.Blank;
}
else
{
output = m_Checker.Shape;
}
return output;
}
}
}
private int m_Size;
private BoardSquare[,] m_BoardSquares;
internal Board(int i_Size)
{
m_Size = i_Size;
this.m_BoardSquares = initiateBoard(i_Size);
}
internal BoardSquare[,] Matrix
{
get { return m_BoardSquares; }
}
internal int Size
{
get { return m_Size; }
}
private BoardSquare[,] initiateBoard(int i_Size)
{
BoardSquare[,] BoardSquares = new BoardSquare[i_Size, i_Size];
int NumberOfCheckersLine = (i_Size / 2) - 1;
for(int i = 0; i < NumberOfCheckersLine; i++)
{
for(int j = 0; j < i_Size; j++)
{
if (i % 2 == 0 && j % 2 != 0)
{
BoardSquares[i, j] = new BoardSquare(eShape.Black, new Location(i, j), ePlayerColor.Black);
BoardSquares[i_Size - i - 1, i_Size - j - 1] = new BoardSquare(eShape.White, new Location(i_Size - i - 1, i_Size - j - 1), ePlayerColor.White);
}
else if (i % 2 != 0 && j % 2 == 0)
{
BoardSquares[i, j] = new BoardSquare(eShape.Black, new Location(i, j), ePlayerColor.Black);
BoardSquares[i_Size - i - 1, i_Size - j - 1] = new BoardSquare(eShape.White, new Location(i_Size - i - 1, i_Size - j - 1), ePlayerColor.White);
}
else
{
BoardSquares[i, j] = new BoardSquare(new Location(i, j));
BoardSquares[i_Size - i - 1, i_Size - j - 1] = new BoardSquare(new Location(i_Size - i - 1, i_Size - j - 1));
}
}
}
for (int i = 0; i < i_Size; i++)
{
BoardSquares[NumberOfCheckersLine, i] = new BoardSquare(new Location(NumberOfCheckersLine, i));
BoardSquares[NumberOfCheckersLine + 1, i] = new BoardSquare(new Location(NumberOfCheckersLine + 1, i));
}
return BoardSquares;
}
internal BoardSquare getBoardSquare(int i_Row, int i_Col)
{
return m_BoardSquares[i_Row, i_Col];
}
internal void setBoardSquare(int i_Row, int i_Col, eShape i_Shape, ePlayerColor i_Color)
{
m_BoardSquares[i_Row, i_Col] = new BoardSquare(i_Shape, new Location(i_Row, i_Col), i_Color);
}
internal void PrintBoard()
{
StringBuilder output = new StringBuilder();
StringBuilder LineSeperator = createLineSeperator();
string newLine = Environment.NewLine;
char RowIndex = 'a';
string CurrentSquareToString;
output.Append(createColIndexes());
output.Append(newLine + LineSeperator + newLine);
for(int i = 0; i < m_Size; i++)
{
output.Append(RowIndex++).Append('|');
for (int j = 0; j < m_Size; j++)
{
switch (m_BoardSquares[i, j].GetShape)
{
case eShape.Black:
CurrentSquareToString = " O |";
break;
case eShape.White:
CurrentSquareToString = " X |";
break;
case eShape.BlackKing:
CurrentSquareToString = " U |";
break;
case eShape.WhiteKing:
CurrentSquareToString = " K |";
break;
default:
CurrentSquareToString = " |";
break;
}
output.Append(CurrentSquareToString);
}
output.Append(newLine + LineSeperator + newLine);
}
Console.Write(output.ToString());
}
private StringBuilder createColIndexes()
{
char ColIndex = 'A';
StringBuilder output = new StringBuilder();
output.Append(" ");
for(int i = 0; i < m_Size; i++)
{
output.Append(ColIndex + " ");
ColIndex++;
}
return output;
}
private StringBuilder createLineSeperator()
{
StringBuilder LineSeperator = new StringBuilder();
LineSeperator.Append(' ');
for (int i = 0; i < (m_Size * 4) + 1; i++)
{
LineSeperator.Append('=');
}
return LineSeperator;
}
private int getNumberOfCheckersLines(int i_Size)
{
int output = 0;
if(i_Size == 6)
{
output = 2;
}
if(i_Size == 8)
{
output = 3;
}
if(i_Size == 10)
{
output = 4;
}
return output;
}
}
}