-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
119 lines (92 loc) · 2.99 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
/*
* Program.cs --
*
* Copyright (c) 2007-2024 by Joe Mistachkin. All rights reserved.
*
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* RCS: @(#) $Id: $
*/
using System;
using System.Diagnostics;
using System.Threading;
namespace TicTacToe
{
internal static class Program
{
#region Private Constants
private const int GameDelay = 1000; /* milliseconds */
#endregion
///////////////////////////////////////////////////////////////////////
#region Program Entry Point
private static int Main(
string[] args /* in: NOT USED */
)
{
int? playerCount = Helpers.GetIntegerFromUser(
"Please enter number of players (0 to 2): ", 0, 2);
if (playerCount == null)
{
Console.WriteLine("Invalid number of players.");
return 1;
}
int? player1Difficulty = null;
int? player2Difficulty = null;
if ((int)playerCount < 2)
{
player2Difficulty = Helpers.GetIntegerFromUser(
"Please enter player #2 difficulty (0 to 2): ",
0, 2);
if ((int)playerCount < 1)
{
player1Difficulty = Helpers.GetIntegerFromUser(
"Please enter player #1 difficulty (0 to 2): ",
0, 2);
}
}
int gameId = 0;
int[] wins = new int[(int)MarkType.Count];
IGame game = new Game(
(int)playerCount, player1Difficulty,
player2Difficulty);
again:
Trace.WriteLine(String.Format(
"New Game #{0}", ++gameId));
game.Reset();
do
{
/* IGNORED */
game.Draw();
MarkType? winner = game.GetWinner();
if (winner != null)
{
wins[(int)(MarkType)winner]++;
Console.WriteLine("The winner is {0}.", winner);
Console.WriteLine("X: {0}, O: {1}, Tie: {2}",
wins[(int)MarkType.X], wins[(int)MarkType.O],
wins[(int)MarkType.None]);
break;
}
int row;
int column;
if (!game.GetRowAndColumn(out row, out column))
continue;
/* IGNORED */
game.PlaceMark(row, column);
} while (true);
if (playerCount == 0)
{
Thread.Sleep(GameDelay);
#if DEBUG
// Console.WriteLine("Press any key to continue...");
// Console.ReadKey();
#endif
goto again;
}
Console.ReadKey();
return 0;
}
#endregion
}
}