-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextGame.java
More file actions
77 lines (66 loc) · 1.67 KB
/
Copy pathTextGame.java
File metadata and controls
77 lines (66 loc) · 1.67 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
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
import java.util.*;
public class TextGame
{
static int blength;
public static void main ( String[] args )
{
Scanner sc = new Scanner(System.in);
blength = sc.nextInt();
int nump = sc.nextInt();
Board b = new Board(blength*blength,nump);
while ( !b.gameOver() )
{
printBoard(b);
//System.out.println(CountGameTree.getCount(4));
if ( true )
{
System.out.println("Enter your move: ");
if ( b.addPiece(sc.nextInt()-1) ) System.out.println("Move added!\n");
else System.out.println("Invalid move. Please try again!\n");
}
else
{
System.out.println("Enter collapse square: ");
b.collapse(sc.nextInt()-1);
}
}
printBoard(b);
System.out.println("Winner: " + b.getWinner());
}
public static void printBoard ( Board b )
{
int i, j, k, l;
int tmppiece;
int tmpchar;
System.out.println("Board at turn " + b.getTurn() + ":");
for ( i = 0; i < blength; i++ )
{
for ( j = 0; j < blength; j++ )
{
for ( k = 0; k < blength; k++ )
{
for ( l = 0; l < blength; l++ )
{
tmppiece = b.pieceAt( blength*i+k, blength*j+l ) + 1;
if ( tmppiece != 0 )
{
if ( tmppiece % 2 == 0 ) System.out.print("O");
else if ( tmppiece % 2 == 1 ) System.out.print("X");
if ( tmppiece >= 10 ) System.out.print( tmppiece + " " );
else System.out.print( tmppiece + " " );
}
else System.out.print(" ");
}
if ( k != blength-1 ) System.out.print("|");
}
System.out.println();
}
if ( i != blength-1 )
{
for ( j = 0; j < 4*blength*blength + blength - 1; j++ )
System.out.print("-");
System.out.println();
}
}
}
}