-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParcours.java
More file actions
76 lines (64 loc) · 2.18 KB
/
Parcours.java
File metadata and controls
76 lines (64 loc) · 2.18 KB
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
66
67
68
69
70
71
72
73
74
75
76
import java.awt.Point;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Random;
public class Parcours {
public static ArrayList<Point> points = new ArrayList<>();
public static Affichage affichage;
public static Etat etat;
public static final Random rand = new Random();
public static final Random rand2 = new Random();
public Parcours(Etat e){
etat = e;
affichage = this.etat.getAffichage();
createParcours();
}
public void createParcours(){
Point debut = new Point();
int x = this.affichage.getBordX() + this.affichage.getOvalWidth()/2;
int y = this.affichage.hauteur - this.affichage.getOvalHeight()/2;
debut.setLocation(x, y);
this.points.add(debut);
Random rand = new Random();
while(x < affichage.getLargeur() + 50){
int r = rand.nextInt(100);
if (r<50) r += 50;
x = x + r;
y = rand.nextInt(200) + this.etat.getTaille();
Point p = new Point(x, y);
this.points.add(p);
}
}
public void retirerPoints() {
if (this.points.get(0).getX() < 0 && this.points.get(1).getX() < 0) {
this.points.remove(0);
}
}
public ArrayList<Point> updateParcours(){
ArrayList<Point> upt = this.points;
Iterator<Point> iter = upt.iterator();
while(iter.hasNext()) {
Point p = iter.next();
p.move(p.x - 5, p.y);
if(p.x < - 200) iter.remove();
}
//upt.removeIf()
Random rand = new Random();
int x = upt.get(upt.size() - 1).x;
while(x < affichage.getLargeur() + 50){
x = x + 50 + rand.nextInt(100);
Point p = new Point(x, rand.nextInt(200) + this.etat.getTaille());
upt.add(p);
}
return upt;
}
public void testParcours(){
for (Point p : points
) {
System.out.print("Abscisse " + p.getX() + " Ordonnée " + p.getY() + "\n");
}
}
public static ArrayList<Point> getPoints() {
return points;
}
}