-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainProgram.cs
67 lines (57 loc) · 1.73 KB
/
MainProgram.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Humanizer;
namespace ClassWork
{
class MainProgram
{
private static bool _gameOver = false,turn = false;
private static int _turnCount = 0;
private static BoardModel bm;
static void Main(string[] args)
{
bm = new BoardModel();
while (!_gameOver&&_turnCount<42)
{
TakeTurn();
}
bm.DisplayBoard();
Console.WriteLine(_turnCount > 42 ? "The game tied!" : "Congratulations! You Won!");
Console.ReadLine();
}
private static void TakeTurn()
{
bm.DisplayBoard();
Console.WriteLine("In which column would you like to drop a piece?");
string input = Console.ReadLine().ToUpper();
int colChoice = -1;
try
{
char c = Char.Parse(input);
colChoice = c - 'A';
if (colChoice > 6 || colChoice < 0)
{
throw new Exception();
}
}
catch (Exception)
{
Console.WriteLine("Input invalid");
return;
}
bool valid = bm.DropPiece(colChoice,turn, out int row);
if (!valid)
{
Console.WriteLine("Column is full");
return;
}
_gameOver = bm.CheckWinner(row, colChoice);
turn = !turn;
_turnCount++;
Console.WriteLine(_turnCount);
}
}
}