-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGhost.java
32 lines (29 loc) · 844 Bytes
/
Ghost.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
import java.awt.*;
public class Ghost implements Drawable{
private int positionX = 400;
private int positionY = 400;
@Override
public void draw(Graphics g) {
g.setColor(Color.RED);
if (Math.random()>0.5) {
if (Math.random()>0.5) {
positionX += 20;
}
else {
positionX -= 20;
}
}
else {
if (Math.random()>0.5) {
positionY += 20;
}
else {
positionY -= 20;
}
}
if (positionX > 400) { positionX = 400; }
if (positionY > 400) { positionY = 400; }
if (positionX < 0) { positionX = 0; }
if (positionY < 0) { positionY = 0; }
}
}