-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTerminal2048.java
More file actions
34 lines (31 loc) · 967 Bytes
/
Copy pathTerminal2048.java
File metadata and controls
34 lines (31 loc) · 967 Bytes
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
import java.util.Scanner;
public class Terminal2048
{
public static void main(String[] args){
Board b = new Board();
b.addRandomValue();
b.addRandomValue();
Scanner con = new Scanner(System.in);
do{
if (b.wasChanged()){
b.addRandomValue();
}
System.out.println(b);
System.out.print("\nNext Move: ");
String command = con.nextLine();
if (command.equals("u")){
b.pushUp();
} else if (command.equals("d")){
b.pushDown();
} else if (command.equals("l")){
b.pushLeft();
} else if (command.equals("r")){
b.pushRight();
} else {
b.noChange();
}
} while (!b.isGameOver());
System.out.println(b);
System.out.println("GAME OVER");
}
}