CAMapange espace fond cercle et difficulté

This commit is contained in:
2026-02-23 12:40:31 +01:00
parent 5ad0874d53
commit 263711cff3
4 changed files with 131 additions and 0 deletions

39
src/linea/FondEspace.java Normal file
View 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;
}
}
}