-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameInterface.cs
More file actions
249 lines (225 loc) · 9.65 KB
/
Copy pathGameInterface.cs
File metadata and controls
249 lines (225 loc) · 9.65 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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace Ex2
{
internal class GameInterface
{
internal static void ShowWelcomeMessage()
{
string welcomeMSG = "Welcome to" + Environment.NewLine
+ "╔═╗┬ ┬┌─┐┌─┐┬┌─┌─┐┬─┐┌─┐" + Environment.NewLine
+ "║ ├─┤├┤ │ ├┴┐├┤ ├┬┘└─┐" + Environment.NewLine
+ "╚═╝┴ ┴└─┘└─┘┴ ┴└─┘┴└─└─┘ ";
Console.WriteLine(welcomeMSG);
}
internal static void ShowRulesMessage()
{
Ex02.ConsoleUtils.Screen.Clear();
string msg =
@"The object of the game is to prevent the opponent from being able to move when it is his turn to do so. This is accomplished either by capturing all of the opponent's Checkers, or by blocking those that remain so that none of them can be moved. If neither player can accomplish this, the game is a draw.
----------------------------------------------------------------------
You can not eat backwords, and if you have an option to eat it is your only valid move.
On each turn, you will see the board, and the previous player move in the format COLrow>COLrow.
You will have to write your move in the same format (COLrow>COLrow.)
For example if you have a checker on square Af and you want to move it to Be your input should be Af>Be.
----------------------------------------------------------------------
Good Luck & Enjoy!
----------------------------------------------------------------------
Please press Enter to start
----------------------------------------------------------------------";
Console.WriteLine(msg);
Console.ReadLine();
Ex02.ConsoleUtils.Screen.Clear();
}
internal static void EndGameMessage()
{
Console.WriteLine("Thanks for playing. We hope you enjoyed. (Copyrights) Peleg & Guy");
}
internal static bool PlayAnotherRound()
{
bool playAnother = false;
Console.WriteLine("Would you like to play another round? (Yes/No)");
string userInput = Console.ReadLine();
if(userInput.ToLower().Equals("yes"))
{
playAnother = true;
}
else if(userInput.ToLower().Equals("no"))
{
playAnother = false;
}
else
{
Console.WriteLine("Ilegal input, please enter Yes or No.");
playAnother = PlayAnotherRound();
}
return playAnother;
}
internal static void PrintEndOfRoundWin(Game.eGameStatus i_GameStatus, Player i_WiningPlayer, Player i_LosingPlayer)
{
Ex02.ConsoleUtils.Screen.Clear();
string msg = string.Format(
@"-----------------------------------------
Congrats! The winner of this round is {0}!!
Better luck next time {1}.
-----------------------------------------
-----------------------------------------
Current Scores
-----------------------------------------
{0}'s score is: {2}
{1}'s score is: {3}
-----------------------------------------",
i_WiningPlayer.GetName(),
i_LosingPlayer.GetName(),
i_WiningPlayer.Score,
i_LosingPlayer.Score);
Console.WriteLine(msg);
}
internal static void PrintEndOfRoundDraw(Game.eGameStatus i_GameStatus, Player i_PlayerOne, Player i_PlayerTwo)
{
Ex02.ConsoleUtils.Screen.Clear();
string msg = string.Format(
@"-----------------------------------------
It's a Draw!!
-----------------------------------------
-----------------------------------------
Current Scores
-----------------------------------------
{0}'s score is: {1}
{2}'s score is: {3}
-----------------------------------------",
i_PlayerOne.GetName(),
i_PlayerOne.Score,
i_PlayerTwo.GetName(),
i_PlayerTwo.Score );
Console.WriteLine(msg);
}
internal static void ShowStartTurnMessage(Board i_Board, Player i_CurrentPlayer)
{
i_Board.PrintBoard();
Console.WriteLine(i_CurrentPlayer.GetName() + "'s turn:");
}
internal static void ShowRoundDetails(Board i_Board, Player i_CurrentPlayer, Player i_OtherPlayer, string i_LastMove)
{
Ex02.ConsoleUtils.Screen.Clear();
i_Board.PrintBoard();
string roundDetails = string.Format(
@"{0}'s move was ({1}): {2}
{3}'s Turn ({4}): ",
i_CurrentPlayer.GetName(),
(char)i_CurrentPlayer.Color,
i_LastMove,
i_OtherPlayer.GetName(),
(char)i_OtherPlayer.Color);
Console.WriteLine(roundDetails);
}
internal static String InvalidMove(int i_BoardSize)
{
Console.WriteLine("Invalid Move. Please enter a valid move");
return getMove(i_BoardSize);
}
internal static bool IsLegalWithdraw(string i_Input, Turn i_Turn)
{
bool legalWithdraw = false;
if (i_Input.Equals("Q"))
{
legalWithdraw = i_Turn.IsWithdrawLegal();
if (!legalWithdraw)
{
Console.WriteLine("Only the losing player can withdraw.");
}
}
return legalWithdraw;
}
internal static String getMove(int i_BoardSize)
{
string userInput = Console.ReadLine();
while (!isLegalMoveInput(userInput, i_BoardSize))
{
Console.WriteLine("Invalid input. Please enter a valid move in the format COLrow>COLrow");
userInput = Console.ReadLine();
}
return userInput;
}
internal static Boolean isLegalMoveInput(string i_UserInput, int i_BoardSize)
{
bool output = false;
if (i_UserInput.Equals("Q"))
{
output = true;
}
else
{
string Pattern = string.Empty;
switch (i_BoardSize)
{
case 6:
Pattern = @"[A-F][a-f]>[A-F][a-f]";
break;
case 8:
Pattern = @"[A-H][a-h]>[A-H][a-h]";
break;
case 10:
Pattern = @"[A-J][a-j]>[A-J][a-j]";
break;
}
Match matcher = Regex.Match(i_UserInput, Pattern);
output = matcher.Success;
}
return output;
}
internal static Player getOpponent()
{
Console.WriteLine("Will you be playing against another user or a bot?(Enter \"user\" or \"bot\")");
string OpponentType = Console.ReadLine();
bool isLegalType = OpponentType.ToUpper().Equals("USER") || OpponentType.ToUpper().Equals("BOT");
while (!isLegalType)
{
Console.WriteLine("Sorry, you can not play against this type here. Please enter a valid type (User / Bot)");
OpponentType = Console.ReadLine();
isLegalType = OpponentType.ToUpper().Equals("USER") || OpponentType.ToUpper().Equals("BOT");
}
string OpponentName;
if (OpponentType.ToUpper().Equals("USER"))
{
OpponentName = getPlayerName();
}
else
{
OpponentName = "Bot";
}
return new Player(OpponentType, OpponentName, ePlayerColor.Black);
}
internal static String getPlayerName()
{
Console.WriteLine("Please enter your name. (spaceless and up to 20 characters)");
string PlayerName = Console.ReadLine();
bool isNameLegal = !PlayerName.Contains(" ") || PlayerName.Length <= 20;
while (!isNameLegal)
{
Console.WriteLine("Illegal name, please enter a valid name containing up to 20 characters and no spaces");
PlayerName = Console.ReadLine();
isNameLegal = !PlayerName.Contains(" ") || PlayerName.Length <= 20;
}
return PlayerName;
}
internal static int getBoardSize()
{
Console.WriteLine("please enter your preffered board size (6,8 or 10):");
int boardSize;
bool legalBoardSize = int.TryParse(Console.ReadLine(), out boardSize);
bool isLegal = legalBoardSize && (boardSize == 6 || boardSize == 8 || boardSize == 10);
while (!isLegal)
{
Console.WriteLine("Illegal board size, please enter a valid Integer board size:(6, 8 or 10)");
legalBoardSize = int.TryParse(Console.ReadLine(), out boardSize);
isLegal = legalBoardSize && (boardSize == 6 || boardSize == 8 || boardSize == 10);
}
return boardSize;
}
}
}