-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTextDisplay.java
More file actions
executable file
·50 lines (47 loc) · 1.35 KB
/
Copy pathTextDisplay.java
File metadata and controls
executable file
·50 lines (47 loc) · 1.35 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
import java.io.*;
/// Simplified IO system that uses the console.
/**
* An IO module that uses the console for input and output. You will not need to
* modify the contents of this class. You can use this IO module by running the
* Connect Four program with the -t command-line switch.
*
* @author Leonid Shamis
*/
public class TextDisplay implements IOModule
{
/// Request a move from a human player.
public int getHumanMove()
{
try
{
System.out.print("Enter Column #: ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
return Integer.parseInt(br.readLine());
}
catch(Exception e)
{
return -1;
}
}
/// Call to update the graphics.
/**
* @param game State of the game to draw.
*/
public void drawBoard(final GameStateModule game)
{
System.out.println();
for(int y = game.getHeight() - 1; y >= 0; y--)
{
for(int x = 0; x < game.getWidth(); x++)
{
switch(game.getAt(x, y))
{
case 0: System.out.print("."); break;
case 1: System.out.print("x"); break;
case 2: System.out.print("o"); break;
}
}
System.out.println();
}
}
}