-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInteractiveGamePlayer.cs
55 lines (44 loc) · 1.44 KB
/
InteractiveGamePlayer.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
/*
* InteractiveGamePlayer.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;
namespace TicTacToe
{
internal sealed class InteractiveGamePlayer : IGamePlayer
{
#region IGamePlayer Members
public bool GetRowAndColumn(
IGameBoard gameBoard, /* in */
MarkType turn, /* in */
ref int row, /* out */
ref int column /* out */
)
{
if (gameBoard == null)
return false;
int rows = gameBoard.Rows;
int? localRow = Helpers.GetIntegerFromUser(String.Format(
"Please enter row to mark for \"{0}\" (1 to {1}): ",
turn, rows), 1, rows);
if (localRow == null)
return false;
row = (int)localRow - 1; /* ZERO BASED */
int columns = gameBoard.Columns;
int? localColumn = Helpers.GetIntegerFromUser(String.Format(
"Please enter column to mark for \"{0}\" (1 to {1}): ",
turn, columns), 1, columns);
if (localColumn == null)
return false;
column = (int)localColumn - 1; /* ZERO BASED */
return true;
}
#endregion
}
}