-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChessBoardMaker.cs
More file actions
195 lines (134 loc) · 4.86 KB
/
ChessBoardMaker.cs
File metadata and controls
195 lines (134 loc) · 4.86 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
using System;
using System.Collections.Generic;
using System.Text;
namespace ChessBoard
{
/// <summary>
/// This class creates the chess board. It uses the parameters provided by the user via the console input
/// The class has methods to create rows and columns
/// </summary>
class ChessBoardMaker
{
static string column = "|";
static string row = "-";
static string corner = "+";
static string hash = "#";
/// <summary>
/// This class makes the chess board using using parameters provided via console user input
/// </summary>
/// <param name="squaresize"></param>
/// <param name="boardsize"></param>
public void GetBoard(int squaresize, int boardsize)
{
//start with a top wall to the chess board
Console.WriteLine(string.Join(" ", GetEdges(squaresize, boardsize).ToArray()));
for (int k = 0; k < boardsize; k++)
{
//first condition creates top row
if (k % 2 == 0)
{
for (int i = 0; i < squaresize; i++)
{
Console.WriteLine(string.Join(" ", GetHashTopRow(squaresize, boardsize).ToArray()));
}
//create a wall between two rows of the chessboard
Console.WriteLine(string.Join(" ", GetEdges(squaresize, boardsize).ToArray()));
}
//else condition creates bottom row
else
{
for (int i = 0; i < squaresize; i++)
{
Console.WriteLine(string.Join(" ", GetHashBottomRow(squaresize, boardsize).ToArray()));
}
Console.WriteLine(string.Join(" ", GetEdges(squaresize, boardsize).ToArray()));
}
}
}
/// <summary>
/// This method again uses parameters provided by the user in the console input to create horizontal lines or the horizontal walls of the chessboard
/// </summary>
/// <param name="squaresize"></param>
/// <param name="boardsize"></param>
/// <returns></returns>
static List<string> GetEdges(int squaresize, int boardsize)
{
List<string> hor = new List<string>();
for (int i = 0; i < (boardsize); i++)
{
hor.Add(corner);
for (int j = 0; j < squaresize; j++)
{
hor.Add(row);
}
if (i == boardsize - 1)
{
hor.Add(corner);
}
}
return hor;
}
/// <summary>
/// This method uses the parameters to create the row of the chess board which starts with dark square first then empty square etc.
/// </summary>
/// <param name="squaresize"></param>
/// <param name="boardsize"></param>
/// <returns></returns>
static List<string> GetHashTopRow(int squaresize, int boardsize)
{
List<string> vert = new List<string>();
vert.Add(column);
for (int k = 0; k < boardsize; k++)
{
if (k % 2 == 0)
{
for (int j = 0; j < squaresize; j++)
{
vert.Add(hash);
}
vert.Add(column);
}
else
{
for (int j = 0; j < squaresize; j++)
{
vert.Add(" ");
}
vert.Add(column);
}
}
return vert;
}
/// <summary>
/// This method uses parameters to make row of the chess board that starts with empty square first then dark square etc
/// </summary>
/// <param name="squaresize"></param>
/// <param name="boardsize"></param>
/// <returns></returns>
static List<string> GetHashBottomRow(int squaresize, int boardsize)
{
List<string> vert = new List<string>();
vert.Add(column);
for (int k = 0; k < boardsize; k++)
{
if (k % 2 == 0)
{
for (int j = 0; j < squaresize; j++)
{
vert.Add(" ");
}
vert.Add(column);
}
else
{
for (int j = 0; j < squaresize; j++)
{
vert.Add(hash);
}
vert.Add(column);
}
}
return vert;
}
}
}