-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWCanvas.java~
48 lines (34 loc) · 992 Bytes
/
WCanvas.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
// parts of GUI that displays map
import java.awt.*;
import javax.swing.*;
public class WCanvas extends JComponent {
private int w;
private int h;
private ClientData data;
private static final int POINT_SIZE = 5;
public WCanvas(int w,int h) {
this.w=w;
this.h=h;
setPreferredSize(new Dimension(w,h));
setBackground(Color.WHITE);
data=new ClientData(); //with default info
} //constructor
public void update() {
//fetch latest version of data
data=Client.getData();
} //update
public void paintComponent(Graphics g) {
for (int y = 0; y < GameData.CLIENT_VISION_DIAMETER; y++) {
for (int x = 0; x < GameData.CLIENT_VISION_DIAMETER; x++) {
if (data.getPoint(x, y) == 'p') {
g.setColor(Color.GRAY);
} else if (data.getPoint(x, y) == 'b') {
g.setColor(Color.BLACK);
} else {
g.setColor(Color.RED);
}
g.fillRect(x*POINT_SIZE, y*POINT_SIZE, POINT_SIZE, POINT_SIZE);
}
}
} //paintComponent
} //class