-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.java
65 lines (59 loc) · 1.5 KB
/
Program.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
65
import KTU.ScreenKTU;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.List;
public class Program extends ScreenKTU {
static final private int cHeight = 20, cWidth = 20;
Player p = new Player();
boolean lost = false;
Program()
{
super(cHeight, cWidth, 31, 31);
clearAll(Color.black);
p.show(this);
refresh();
}
public static void main(String[] args) {
new Program();
}
void gameOver()
{
if(!p.canMove())
{
clearAll(Color.black);
setColors(Color.black, Color.red);
print(16, 11, "GAME OVER");
lost = true;
refresh();
}
}
@Override
public void keyPressed(KeyEvent ke)
{
if(lost == false) {
switch (ke.getKeyChar()) {
case 'w':
p.moveDir = new Point(0, -1);
p.move();
break;
case 'a':
p.moveDir = new Point(-1, 0);
p.move();
break;
case 's':
p.moveDir = new Point(0, 1);
p.move();
break;
case 'd':
p.moveDir = new Point(1, 0);
p.move();
break;
}
clearAll(Color.black);
p.show(this);
refresh();
gameOver();
}
}
}