CAMapange espace fond cercle et difficulté
This commit is contained in:
39
src/linea/FondEspace.java
Normal file
39
src/linea/FondEspace.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package linea;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.util.Random;
|
||||
|
||||
public class FondEspace extends ObjetGraphique {
|
||||
private int[] starX = new int[100];
|
||||
private int[] starY = new int[100];
|
||||
private Random rand = new Random();
|
||||
|
||||
public FondEspace() {
|
||||
for (int i = 0; i < 100; i++) {
|
||||
starX[i] = rand.nextInt(800);
|
||||
starY[i] = rand.nextInt(600);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
void Afficher(Graphics g) {
|
||||
// Espace profond
|
||||
g.setColor(Color.BLACK);
|
||||
g.fillRect(0, 0, 800, 600);
|
||||
|
||||
// Étoiles
|
||||
g.setColor(Color.WHITE);
|
||||
for (int i = 0; i < 100; i++) {
|
||||
g.fillOval(starX[i], starY[i], 2, 2);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
void Animer() {
|
||||
for (int i = 0; i < 100; i++) {
|
||||
starX[i] -= 2; // Défilement vers la gauche
|
||||
if (starX[i] < 0) starX[i] = 800;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user