-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmovementTest.java
58 lines (56 loc) · 2.05 KB
/
movementTest.java
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
package movement;
import javax.swing.JOptionPane;
class movementTest
{
public static void main(String[] args)
{
String input;
char direction;
int i, j, time,distance;
Move move=new Move();
for(time=0;time<50;time++)
{
for (i=0;i<=10;i++){
if(i==0 || i==10){
System.out.print(" ");
for(j=1;j<9;j++){
System.out.print("*");
}
System.out.println(" ");
}
else{
System.out.print("*");
for(j=1;j<9;j++){
if(i==move.getR() && j==move.getC()){
System.out.print(move.getPl());
}
else{
System.out.print(" ");
}
}
System.out.println("*");
}
}
input = "";// to avoid "The local variable input may not have been initialized"
try{
do{
input = JOptionPane.showInputDialog( "Make your move \nW : go up \nS : go down \nD : go right \nA : go left\nE: to exit");
}while((!input.equalsIgnoreCase("W")) && (!input.equalsIgnoreCase("S")) && (!input.equalsIgnoreCase("D")) && (!input.equalsIgnoreCase("A")) && (!input.equalsIgnoreCase("E")));
}catch(NullPointerException e){
System.exit(0);//quit the program
}
if(input.equalsIgnoreCase("E")){
break;
}
direction=input.charAt(0);
do{
input =JOptionPane.showInputDialog( "How far do you want to go (number of tiles ) : ");
}while(Integer.parseInt(input)<=0 || input==null);
distance=Integer.parseInt(input);
move.mov(direction,distance);
System.out.print("\033[H\033[2J");
System.out.flush();
}
System.exit(0);
}
}