-
Notifications
You must be signed in to change notification settings - Fork 44
/
TugasPacManMain.java
64 lines (63 loc) · 1.82 KB
/
TugasPacManMain.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
59
60
61
62
63
64
package TugasJobsheet2;
/**
*
* @author Faris Ikhlasul H
*/
import java.util.Scanner;
public class TugasPacManMain {
static Scanner faris = new Scanner(System.in);
static void salah() {
System.out.println("Koordinat Tidak Terbaca !!!");
input();
}
static void input() {
TugasPacMan P = new TugasPacMan();
P.width = 10;
P.height = 10;
System.out.println("Game PacMan : ");
System.out.println("W = bergerak ke atas");
System.out.println("S = bergerak ke bawah");
System.out.println("A = bergerak ke kiri");
System.out.println("D = bergerak ke kanan");
System.out.print("Masukkan Huruf Yang Telah Ditentukan : ");
P.select = faris.nextLine().toLowerCase();
switch (P.select) {
case "w":
if ((P.k - 1) < 0) {
salah();
} else {
P.moveUp();
}
break;
case "s":
if ((P.k + 1) >= P.width) {
salah();
} else {
P.moveDown();
}
break;
case "a":
if ((P.l - 1) < 0) {
salah();
} else {
P.moveLeft();
}
break;
case "d":
if ((P.l + 1) >= P.height) {
salah();
} else {
P.moveRight();
}
break;
default:
System.out.println("Masukkan Input Yang Tepat");
}
P.cetakPosisi();
System.out.println("Titik Koordinat adalah (" + P.l + " , " + P.k + ")");
input();
}
public static void main(String[] args) {
input();
}
}