|
@@ -29,7 +29,6 @@ public class Game extends JPanel implements MouseListener, ActionListener
|
29
|
29
|
p.start();
|
30
|
30
|
}
|
31
|
31
|
this.createTimer();
|
32
|
|
- this.setDoubleBuffered(false);
|
33
|
32
|
}
|
34
|
33
|
|
35
|
34
|
/**
|
|
@@ -46,8 +45,10 @@ public class Game extends JPanel implements MouseListener, ActionListener
|
46
|
45
|
}
|
47
|
46
|
g2d.setColor(Color.BLUE);
|
48
|
47
|
// Draw foods
|
49
|
|
- for (Food food : this.foods) {
|
50
|
|
- g2d.fillRect(food.getX(), food.getY(), 15, 15);
|
|
48
|
+ synchronized (this) {
|
|
49
|
+ for (Food food : this.foods) {
|
|
50
|
+ g2d.fillRect(food.getX(), food.getY(), 15, 15);
|
|
51
|
+ }
|
51
|
52
|
}
|
52
|
53
|
}
|
53
|
54
|
|
|
@@ -57,7 +58,7 @@ public class Game extends JPanel implements MouseListener, ActionListener
|
57
|
58
|
}
|
58
|
59
|
|
59
|
60
|
@Override
|
60
|
|
- public void mousePressed(MouseEvent e) {
|
|
61
|
+ public synchronized void mousePressed(MouseEvent e) {
|
61
|
62
|
this.foods.add(new Food(e.getX(), e.getY()));
|
62
|
63
|
}
|
63
|
64
|
|
|
@@ -80,8 +81,8 @@ public class Game extends JPanel implements MouseListener, ActionListener
|
80
|
81
|
return this.foods;
|
81
|
82
|
}
|
82
|
83
|
|
83
|
|
- public void setFoods(List<Food> foods){
|
84
|
|
- this.foods = foods;
|
|
84
|
+ public synchronized void removeFood(Food food){
|
|
85
|
+ this.foods.remove(food);
|
85
|
86
|
}
|
86
|
87
|
|
87
|
88
|
private void createTimer(){
|