-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
829 lines (810 loc) · 35.9 KB
/
Program.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
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HyperspaceCheeseBattle
{
class Program
{
const int MAX_BOARD_LIMIT = 7;
const int MIN_BOARD_LIMIT = 0;
const int MAX_SIX_POWER = 3;
static int totPlayers;
static int[] diceValues = new int[] { 2, 2, 3, 3, 2, 2, 6, 5, 5, 6, 6, 5, 5 }; // Preset dice
static int diceValuePos = 0; // Preset dice index
static int diceMode = -1;
static Player[] players;
static bool gameOver = false;
static bool testMode = false;
static bool UsingSixPower;
static int SixPowerCount;
static string newGame;
static void Main(string[] args)
{
Console.Title = "Hyperspace Cheese Battle";
do
{
ResetGame();
while (!gameOver)
{
for (int i = 0; i < players.Length; i++)
{
PlayerTurn(i);
ShowStatus();
DrawBoard();
if (!gameOver)
{
Console.WriteLine("Press return for next turns.");
Console.ReadLine();
}
else
{
break;
}
}
}
newGame = ThisOrThat("\nDo you want to start another round? [Y or N]: ", "Invalid value. Enter Y for Yes or N for No.", "Y", "N");
if (newGame == "N")
{
Console.WriteLine("\n\n\n\nThank you for playing Hyperspace Cheese Battle");
Console.WriteLine("Copyright © - All Rights Reserved - 2013 - Federico Dalla Rizza");
Console.WriteLine("Press Enter to exit.");
Console.ReadLine();
}
} while (newGame == "Y");
}
/// <summary>
/// Gets the number of players and set the required elements in players to put each player at square (0,0)
/// </summary>
static void ResetGame()
{
Console.Clear();
gameOver = false;
Console.WriteLine("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░");
Console.WriteLine("░░░░\t \t░░░░");
Console.WriteLine("░░░░\tWelcome to Hyperspace Cheese Battle!\t░░░░");
Console.WriteLine("░░░░\t \t░░░░");
Console.WriteLine("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░");
if (ThisOrThat("\n\nRun the game in test mode? [Y or N]: ", "Invalid value. Enter Y for Yes or N for No.", "Y", "N") == "Y")
{
testMode = true;
diceMode = SelectDiceMethod();
}
else
{
testMode = false;
}
totPlayers = getNumber("\nHow many players? [MAX 4]: ", 2, 4);
Console.WriteLine();
players = new Player[totPlayers];
if (testMode) // Automatic players naming in test mode.
{
for (int i = 0; i < players.Length; i++)
{
int n = i + 1;
players[i].Name = "Rocket " + n;
players[i].X = 0;
players[i].Y = 0;
switch (i)
{
case 0:
players[i].Color = ConsoleColor.Cyan;
break;
case 1:
players[i].Color = ConsoleColor.Green;
break;
case 2:
players[i].Color = ConsoleColor.Red;
break;
case 3:
players[i].Color = ConsoleColor.Yellow;
break;
default:
break;
}
}
}
else
{
for (int i = 0; i < players.Length; i++)
{
players[i].Name = getName(i);
players[i].X = 0;
players[i].Y = 0;
switch (i)
{
case 0:
players[i].Color = ConsoleColor.Cyan;
break;
case 1:
players[i].Color = ConsoleColor.Green;
break;
case 2:
players[i].Color = ConsoleColor.Red;
break;
case 3:
players[i].Color = ConsoleColor.Yellow;
break;
default:
break;
}
}
}
Console.WriteLine();
}
/// <summary>
/// Gets a valid and unique name.
/// </summary>
/// <param name="playerNo">Index of the player.</param>
/// <returns>String player name.</returns>
static string getName(int playerNo)
{
bool goodName = false;
string playerName;
int n = playerNo + 1;
do
{
Console.Write("Enter Player {0} name: ", n);
playerName = Console.ReadLine();
for (int i = 0; i < players.Length; i++)
{
if (playerName == players[i].Name)
{
goodName = false;
Console.WriteLine("Error, the name is already being used. Enter a different one.");
break;
}
if (playerName.Length > 20)
{
goodName = false;
Console.WriteLine("Invalid value. The name is too long.");
break;
}
if (playerName == "")
{
goodName = false;
Console.WriteLine("Invalid value. Enter at least 1 character.");
break;
}
goodName = true;
}
} while (goodName == false);
return playerName;
}
/// <summary>
/// Makes the user decide which dice method to use.
/// </summary>
/// <returns>Integer 0 for preset mode, 1 for choose value mode, 2 for random mode and normal game</returns>
static int SelectDiceMethod()
{
string diceMethod;
do
{
Console.Write("Which dice method do you want to use? [P]reset, [C]hoose, [R]andom: ");
diceMethod = Console.ReadLine().ToUpper();
if (diceMethod != "P" && diceMethod != "C" && diceMethod != "R")
{
Console.WriteLine("Invalid value. Enter P for Preset, C for Choose or R for Random.");
}
} while (diceMethod != "P" && diceMethod != "C" && diceMethod != "R");
switch (diceMethod)
{
case "P":
return 0;
case "C":
return 1;
case "R":
return 2;
default:
return -1;
}
}
/// <summary>
/// Gets a dice number from 1 to 6. If no dice mode is specified, random mode will be used.
/// </summary>
/// <returns>Integer dice number.</returns>
static int DiceThrow(int diceMode)
{
Random rand = new Random();
switch (diceMode)
{
case 0:
int spot = diceValues[diceValuePos];
diceValuePos += 1;
if (diceValuePos == diceValues.Length)
{
diceValuePos = 0;
}
return spot;
case 1:
return getNumber("Enter the dice value: ", 1, 6);
case 2:
return rand.Next(1, 7);
default:
return rand.Next(1, 7);
}
}
/// <summary>
/// Show the position of each player on the board as text report.
/// </summary>
static void ShowStatus()
{
Console.WriteLine("\nHyperspace Cheese Battle Status Report");
Console.WriteLine("======================================\n");
Console.WriteLine("There are {0} players in the game", players.Length);
for (int i = 0; i < players.Length; i++)
{
Console.ForegroundColor = players[i].Color;
Console.Write("{0} ", players[i].Name);
Console.ResetColor();
Console.WriteLine("is on square ({0},{1})", players[i].X, players[i].Y);
}
Console.WriteLine();
}
/// <summary>
/// Shows the board with direction arrows, current rockets positions and cheese squares.
/// </summary>
static void DrawBoard()
{
Console.WriteLine();
for (int i = MAX_BOARD_LIMIT; i >= MIN_BOARD_LIMIT; i--)
{
Console.WriteLine(" │ ");
Console.Write(" {0} │ ", i); // Print square index Y on left side
for (int j = MIN_BOARD_LIMIT; j <= MAX_BOARD_LIMIT; j++)
{
switch (board[j, i])
{
case Direction.Up:
if (RocketInSquare(j, i))
{
Console.ForegroundColor = players[getPlayerIndex(j, i)].Color;
Console.Write(" ▲ ");
Console.ResetColor();
}
else if (CheeseBoard[j, i])
{
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.Write(" ↑ ");
Console.ResetColor();
}
else
Console.Write(" ↑ ");
break;
case Direction.Down:
if (RocketInSquare(j, i))
{
Console.ForegroundColor = players[getPlayerIndex(j, i)].Color;
Console.Write(" ▼ ");
Console.ResetColor();
}
else if (CheeseBoard[j, i])
{
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.Write(" ↓ ");
Console.ResetColor();
}
else
Console.Write(" ↓ ");
break;
case Direction.Left:
if (RocketInSquare(j, i))
{
Console.ForegroundColor = players[getPlayerIndex(j, i)].Color;
Console.Write(" ◄ ");
Console.ResetColor();
}
else if (CheeseBoard[j, i])
{
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.Write(" ← ");
Console.ResetColor();
}
else
Console.Write(" ← ");
break;
case Direction.Right:
if (RocketInSquare(j, i))
{
Console.ForegroundColor = players[getPlayerIndex(j, i)].Color;
Console.Write(" ► ");
Console.ResetColor();
}
else if (CheeseBoard[j, i])
{
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.Write(" → ");
Console.ResetColor();
}
else
Console.Write(" → ");
break;
case Direction.Win:
if (RocketInSquare(j, i))
{
Console.ForegroundColor = players[getPlayerIndex(j, i)].Color;
Console.Write(" ☺ ");
Console.ResetColor();
}
else
Console.Write(" ▓ ");
break;
default:
break;
}
}
Console.WriteLine("\n │ ");
}
Console.WriteLine(" │ ");
for (int i = MIN_BOARD_LIMIT; i <= MAX_BOARD_LIMIT; i++)
{
if (i == 0)
{
Console.Write("────┼───");
}
else
{
Console.Write("──────");
}
}
Console.WriteLine("\n │ ");
Console.Write(" │ ");
for (int i = MIN_BOARD_LIMIT; i <= MAX_BOARD_LIMIT; i++)
{
Console.Write(" {0} ", i); // Print square index X at bottom
}
Console.WriteLine("\n │ ");
Console.WriteLine("\n");
}
/// <summary>
/// Gets the player array index from the coordinates X and Y.
/// </summary>
/// <param name="x">X position value.</param>
/// <param name="y">Y position value.</param>
/// <returns>Integer player index if found, else -1</returns>
private static int getPlayerIndex(int x, int y)
{
for (int i = 0; i < players.Length; i++)
{
if (players[i].X == x && players[i].Y == y)
return i;
}
return -1;
}
/// <summary>
/// Shows the player dice throw, checks for collisions or cheese and eventually moves the player on the board.
/// </summary>
/// <param name="playerNo">Index of the player.</param>
private static void PlayerTurn(int playerNo)
{
bool bounce = true;
Console.WriteLine("\nPlayer {0} turn:", players[playerNo].Name);
int diceN = DiceThrow(diceMode);
if (diceN == 6)
{
SixPowerCount++;
UsingSixPower = true;
}
else
{
SixPowerCount = 0;
UsingSixPower = false;
}
Console.WriteLine("{0} rolled {1}", players[playerNo].Name, diceN);
while (bounce)
{
switch (board[players[playerNo].X, players[playerNo].Y]) // gets position X,Y of player on the board
{
case Direction.Up:
if (RocketInSquare(players[playerNo].X, players[playerNo].Y + diceN))
{
bounce = true;
}
else
{
bounce = false;
}
if (players[playerNo].Y + diceN <= MAX_BOARD_LIMIT) // checks if player goes out of the board UP
{
players[playerNo].Y += diceN;
Console.WriteLine("New position: {0},{1}", players[playerNo].X, players[playerNo].Y);
if (bounce)
{
Console.WriteLine("{0} landed on enemy and is bouncing on next space!", players[playerNo].Name);
diceN = 1;
}
else
{
CheeseInSquare(playerNo);
}
}
else
{
Console.WriteLine("The risk level for that journey is too high!");
Console.WriteLine("No movement for player {0}.", players[playerNo].Name);
}
break;
case Direction.Down:
if (RocketInSquare(players[playerNo].X, players[playerNo].Y - diceN))
{
bounce = true;
}
else
{
bounce = false;
}
if (players[playerNo].Y - diceN >= MIN_BOARD_LIMIT) // checks if player goes out of the board DOWN
{
players[playerNo].Y -= diceN;
Console.WriteLine("New position: {0},{1}", players[playerNo].X, players[playerNo].Y);
if (bounce)
{
Console.WriteLine("{0} landed on enemy and is bouncing on next space!", players[playerNo].Name);
diceN = 1;
}
else
{
CheeseInSquare(playerNo);
}
}
else
{
Console.WriteLine("The risk level for that journey is too high!");
Console.WriteLine("No movement for player {0}.", players[playerNo].Name);
}
break;
case Direction.Left:
if (RocketInSquare(players[playerNo].X - diceN, players[playerNo].Y))
{
bounce = true;
}
else
{
bounce = false;
}
if (players[playerNo].X - diceN >= MIN_BOARD_LIMIT) // checks if the players goes out of the board LEFT
{
players[playerNo].X -= diceN;
Console.WriteLine("New position: {0},{1}", players[playerNo].X, players[playerNo].Y);
if (bounce)
{
Console.WriteLine("{0} landed on enemy and is bouncing on next space!", players[playerNo].Name);
diceN = 1;
}
else
{
CheeseInSquare(playerNo);
}
}
else
{
Console.WriteLine("The risk level for that journey is too high!");
Console.WriteLine("No movement for player {0}.", players[playerNo].Name);
}
break;
case Direction.Right:
if (RocketInSquare(players[playerNo].X + diceN, players[playerNo].Y))
{
bounce = true;
}
else
{
bounce = false;
}
if (players[playerNo].X + diceN <= MAX_BOARD_LIMIT) // checks if the player goes out of the board RIGHT
{
players[playerNo].X += diceN;
Console.WriteLine("New position: {0},{1}", players[playerNo].X, players[playerNo].Y);
if (bounce)
{
Console.WriteLine("{0} landed on enemy and is bouncing on next space!", players[playerNo].Name);
diceN = 1;
}
else
{
CheeseInSquare(playerNo);
}
}
else
{
Console.WriteLine("The risk level for that journey is too high!");
Console.WriteLine("No movement for player {0}.", players[playerNo].Name);
}
break;
}
} // ╔═════════════╗
if (players[playerNo].X == MAX_BOARD_LIMIT && players[playerNo].Y == MAX_BOARD_LIMIT && SixPowerCount != MAX_SIX_POWER) // Print game-over message in the format: ║Player X won!║
{ // ╚═════════════╝
gameOver = true;
StringBuilder winMsg = new StringBuilder("║Player " + players[playerNo].Name + " won!║");
Console.Write("╔");
for (int i = 0; i < winMsg.Length - 2; i++)
{
Console.Write("═");
}
Console.WriteLine("╗");
Console.WriteLine(winMsg);
Console.Write("╚");
for (int i = 0; i < winMsg.Length - 2; i++)
{
Console.Write("═");
}
Console.WriteLine("╝");
}
else if (UsingSixPower)
{
bool freeSquare = false;
int NewPlayerX;
if (SixPowerCount == MAX_SIX_POWER)
{
Console.WriteLine("Player {0} tried too hard with the Six Power ability!", players[playerNo].Name);
Console.WriteLine("The rocket engines has exploded.");
Console.WriteLine("\nPlayer {0} decide the position on the bottom line of the board.", players[playerNo].Name);
do
{
NewPlayerX = getNumber("Enter a square between 0 and 7: ", 0, 7);
if (RocketInSquare(NewPlayerX, 0))
{
Console.WriteLine("That square is already occupied. Choose another one.");
}
else
{
freeSquare = true;
players[playerNo].X = NewPlayerX;
players[playerNo].Y = 0;
}
} while (!freeSquare);
Console.WriteLine("New position: {0},{1}", players[playerNo].X, players[playerNo].Y);
SixPowerCount = 0;
UsingSixPower = false;
}
else
{
Console.WriteLine("\nPlayer {0}, you will now use the Six Power ability level {1}.", players[playerNo].Name, SixPowerCount);
Console.WriteLine("Prepare for another turn!");
ShowStatus();
DrawBoard();
Console.WriteLine("Press return for next turns.");
Console.ReadLine();
PlayerTurn(playerNo);
}
}
}
/// <summary>
/// Checks if the square is occupied by another rocket.
/// </summary>
/// <param name="X">Position X of the square to check.</param>
/// <param name="Y">Position Y of the square to check.</param>
/// <returns>true if the square is occupied by another rocket.</returns>
static bool RocketInSquare(int X, int Y)
{
for (int i = 0; i < players.Length; i++)
{
if (players[i].X == X && players[i].Y == Y)
return true;
}
return false;
}
/// <summary>
/// Checks if player is on a cheese square and eventually asks the player what to do with the cheese power (throw dice again or attack an enemy player).
/// If the player decides to throw again, another playerTurn is called.
/// If the player decides to attack, chosen enemy can decide a free bottom board position.
/// </summary>
/// <param name="playerNo">Index of the player.</param>
static void CheeseInSquare(int playerNo)
{
if (!(CheeseBoard[players[playerNo].X, players[playerNo].Y])) // Player not on Cheese square
{
return;
}
string decision;
Console.WriteLine("Player {0} has landed on a Cheese Power Square.", players[playerNo].Name);
if (!UsingSixPower)
{
Console.WriteLine("Does {0} want to roll the dice again or explode the engines of another rocket?", players[playerNo].Name);
decision = ThisOrThat("Enter Throw or Explode [T or E]: ", "Invalid value. Enter T to Throw or E to Explode.", "T", "E");
if (decision == "T") // decision Throw dice
{
PlayerTurn(playerNo);
}
else // decision Explode
{
bool exploded = false;
do
{
for (int i = 0; i < players.Length; i++)
{
if (players[i].Name == players[playerNo].Name)
{
continue;
}
Console.WriteLine("Do you want to explode player {0}?", players[i].Name);
decision = ThisOrThat("Enter Yes or No [Y or N]: ", "Invalid value. Enter Y for Yes or N for No.", "Y", "N");
if (decision == "Y") // decision Yes
{
bool freeSquare = false;
int NewPlayerX;
Console.WriteLine("{0} engines has exploded.", players[i].Name);
Console.WriteLine("\nPlayer {0} decide the position on the bottom line of the board.", players[i].Name);
do
{
NewPlayerX = getNumber("Enter a square between 0 and 7: ", 0, 7);
if (RocketInSquare(NewPlayerX, 0))
{
Console.WriteLine("That square is already occupied. Choose another one.");
}
else
{
freeSquare = true;
players[i].X = NewPlayerX;
players[i].Y = 0;
}
} while (!freeSquare);
Console.WriteLine("New position: {0},{1}", players[i].X, players[i].Y);
exploded = true;
break;
}
else // decision No
{
continue;
}
}
} while (exploded == false);
}
}
else
{
Console.WriteLine("Since you are using the Six Power ability, you MUST explode an enemy rocket!");
bool exploded = false;
bool freeSquare = false;
int SquareNumber;
do
{
for (int i = 0; i < players.Length; i++)
{
if (players[i].Name == players[playerNo].Name)
{
continue;
}
Console.WriteLine("Do you want to explode player {0}?: ", players[i].Name);
decision = ThisOrThat("Enter Yes or No [Y or N]: ", "Invalid value. Enter Y for Yes or N for No.", "Y", "N");
if (decision == "Y") // decision Yes
{
Console.WriteLine("{0} engines has exploded.", players[i].Name);
while (freeSquare == false)
{
Console.WriteLine("\nPlayer {0} decide the position on the bottom line of the board.", players[i].Name);
SquareNumber = getNumber("Enter a square between 0 and 7: ", 0, 7);
if (RocketInSquare(SquareNumber, 0))
{
Console.WriteLine("That square is already occupied, choose another one.");
}
else
{
players[i].X = SquareNumber;
players[i].Y = 0;
Console.WriteLine("New position: {0},{1}", players[i].X, players[i].Y);
freeSquare = true;
exploded = true;
}
}
break;
}
else // decision No
{
continue;
}
}
} while (exploded == false);
}
}
/// <summary>
/// Gets a number in range from min to max after prompting a message.
/// </summary>
/// <param name="prompt">Message for the user to show.</param>
/// <param name="min">Minimum inclusive value.</param>
/// <param name="max">Maximum inclusive value.</param>
/// <returns>Integer number in the range.</returns>
static int getNumber(string prompt, int min, int max)
{
if (min >= max)
{
throw new Exception("Invalid range, min value must be smaller than max value.");
}
int number;
while (true)
{
Console.Write(prompt);
try
{
number = int.Parse(Console.ReadLine());
if (number < min || number > max)
{
Console.WriteLine("Number must be in the range between {0} and {1}.", min, max);
continue;
}
break;
}
catch
{
Console.WriteLine("Enter a numeric value in the range {0} to {1}", min, max);
continue;
}
}
return number;
}
/// <summary>
/// Gets a one digit answer to the prompt.
/// </summary>
/// <param name="prompt">Message for the user to show.</param>
/// <param name="errorMsg">Error message for invalid input.</param>
/// <param name="answerOne">First possible answer.</param>
/// <param name="answerTwo">Second possible answer.</param>
/// <returns>String containing one answer character.</returns>
static string ThisOrThat(string prompt, string errorMsg, string answerOne, string answerTwo)
{
if (answerOne == answerTwo)
{
throw new Exception("Invalid values, answers can not be the same.");
}
string answer;
while (true)
{
Console.Write(prompt);
answer = Console.ReadLine().ToUpper();
if (answer != answerOne && answer != answerTwo)
{
Console.WriteLine(errorMsg);
}
else
{
return answer;
}
}
}
/// <summary>
/// Variables to define arrow direction on the board squares.
/// </summary>
enum Direction
{
Up,
Down,
Left,
Right,
Win
};
static Direction[,] board = new Direction[,]
{
{Direction.Up,Direction.Right,Direction.Right,Direction.Right,Direction.Right,Direction.Right,Direction.Right,Direction.Down}, // column 0
{Direction.Up,Direction.Right,Direction.Right,Direction.Right,Direction.Right,Direction.Right,Direction.Right,Direction.Right}, // column 1
{Direction.Up,Direction.Up,Direction.Up,Direction.Up,Direction.Up,Direction.Right,Direction.Up,Direction.Right}, // column 2
{Direction.Up,Direction.Down,Direction.Left,Direction.Right,Direction.Right,Direction.Right,Direction.Down,Direction.Right}, // column 3
{Direction.Up,Direction.Up,Direction.Left,Direction.Up,Direction.Up,Direction.Up,Direction.Up,Direction.Right}, // column 4
{Direction.Up,Direction.Up,Direction.Left,Direction.Up,Direction.Up,Direction.Up,Direction.Left,Direction.Right}, // column 5
{Direction.Up,Direction.Left,Direction.Left,Direction.Left,Direction.Left,Direction.Left,Direction.Left,Direction.Down}, // column 6
{Direction.Up,Direction.Left,Direction.Left,Direction.Left,Direction.Left,Direction.Left,Direction.Left,Direction.Win}, // column 7
};
static bool[,] CheeseBoard = new bool[,]
{
{false,false,false,true,false,false,false,false}, // column 0
{false,false,false,false,false,false,false,false}, // column 1
{false,false,false,false,false,false,false,false}, // column 2
{false,false,false,false,false,true,false,false}, // column 3
{false,true,false,false,false,false,false,false}, // column 4
{false,false,false,false,false,false,false,false}, // column 5
{false,false,false,false,true,false,false,false}, // column 6
{false,false,false,false,false,false,false,false}, // column 7
};
/// <summary>
/// Variables container for Player type including player name, square position, font color.
/// </summary>
struct Player
{
public string Name;
public int X;
public int Y;
public ConsoleColor Color;
}
}
}