From 16787a4113c78135ff95c3be4b438d30aee85513 Mon Sep 17 00:00:00 2001 From: Marc Date: Fri, 27 Mar 2026 19:17:03 +0100 Subject: [PATCH] =?UTF-8?q?change:=20bonus=20regroup=C3=A9=20en=20=20une?= =?UTF-8?q?=20seule=20classe=20mere?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit classe objetcolldectile qui regroupe tout --- linea_bdd.db | Bin 20480 -> 20480 bytes src/Bonus.java | 82 +++++++++----------------------------- src/BonusTaille.java | 81 +++++++++---------------------------- src/Malus.java | 77 ++++++++--------------------------- src/ObjetCollectible.java | 75 ++++++++++++++++++++++++++++++++++ 5 files changed, 128 insertions(+), 187 deletions(-) create mode 100644 src/ObjetCollectible.java diff --git a/linea_bdd.db b/linea_bdd.db index 45affec80141a9f01c644ddd2ab637ac2bd093d2..6f83958bddc4c3869481a7927537a7f3c303da94 100644 GIT binary patch delta 236 zcmZozz}T>Wae_3X>O>i5M%9f8OZde&`70RsKk+}|zskRs|1kez{(k;u{))|t0&)D@ zoSZBSqKv+YMakBio8=1xc-goZnI##ElkWae_3X!bBNoMum+DOZY`N_?sE{Kk+}|zskRs|1kez{(k=E&4LQq{F|HQ q3j}zXxEPrw8H&{A{@MU(KN>^; diff --git a/src/Bonus.java b/src/Bonus.java index a85ac2c..3382b00 100644 --- a/src/Bonus.java +++ b/src/Bonus.java @@ -4,77 +4,33 @@ import java.awt.Color; import java.awt.Graphics; import java.util.List; -public class Bonus extends ObjetGraphique { - - protected double taille = 10; - protected boolean actif = false; - protected int compteurFrames = 0; - protected boolean dejaCapture = false; - - protected Ligne maLigne; - protected List joueurs; - protected Jeu monJeu; +public class Bonus extends ObjetCollectible { public Bonus(Ligne l, List joueurs, Jeu j) { - this.maLigne = l; - this.joueurs = joueurs; - this.monJeu = j; + super(l, joueurs, j); + this.taille = 10; this.couleur = Color.GREEN; } + @Override protected int getSeuilActivation() { return 220; } + + @Override protected Color getCouleurCapture() { return Color.BLUE; } + @Override - void Afficher(Graphics g) { - if (actif) { - g.setColor(dejaCapture ? Color.BLUE : this.couleur); - g.fillRect((int)Math.round(x), (int)Math.round(y), (int)taille, (int)taille); - } + protected double calculerY(double hauteurLigne) { + if (Math.random() > 0.5) return hauteurLigne - 10 - (Math.random() * 50); + else return hauteurLigne + 10 + (Math.random() * 50); } @Override - void Animer() { - if (!actif) { - compteurFrames++; - } - - if (compteurFrames >= 220 && !actif) { - actif = true; - dejaCapture = false; - x = 800; - - double hauteurLigne = 300; - if (maLigne.dernierSegment != null) { - hauteurLigne = maLigne.dernierSegment.y; - } - - if (Math.random() > 0.5) { - y = hauteurLigne - 10 - (Math.random() * 50); - } else { - y = hauteurLigne + 10 + (Math.random() * 50); - } - - if (y < 20) y = 20; - if (y > 550) y = 550; - - compteurFrames = 0; - } - - if (actif) { - double vitesseLigne = monJeu.gestionnaireNiveau.getVitesseScroll(); - x -= vitesseLigne; - - if (!dejaCapture) { - for (Joueur joueur : joueurs) { - if (joueur.verifierCollisionCollectible(x, y, taille, vitesseLigne)) { - if (!monJeu.cheatMode) joueur.ajouterVie(); - dejaCapture = true; - break; - } - } - } - - if (x + taille < 0) { - actif = false; - } - } + protected void appliquerEffet(Joueur joueur) { + if (!monJeu.cheatMode) joueur.ajouterVie(); } + + @Override + protected void dessiner(Graphics g) { + g.fillRect((int)Math.round(x), (int)Math.round(y), (int)taille, (int)taille); + } + + } diff --git a/src/BonusTaille.java b/src/BonusTaille.java index 5d48e99..2e875b2 100644 --- a/src/BonusTaille.java +++ b/src/BonusTaille.java @@ -4,77 +4,32 @@ import java.awt.Color; import java.awt.Graphics; import java.util.List; -public class BonusTaille extends ObjetGraphique { - - protected double taille = 12; - protected boolean actif = false; - protected int compteurFrames = 200; - protected boolean dejaCapture = false; - - protected Ligne maLigne; - protected List joueurs; - protected Jeu monJeu; +public class BonusTaille extends ObjetCollectible { public BonusTaille(Ligne l, List joueurs, Jeu j) { - this.maLigne = l; - this.joueurs = joueurs; - this.monJeu = j; + super(l, joueurs, j); + this.taille = 12; this.couleur = Color.CYAN; + this.compteurFrames = 200; // démarre déjà à 200 pour apparaître plus tôt + } + + @Override protected int getSeuilActivation() { return 320; } + + @Override protected Color getCouleurCapture() { return new Color(255, 255, 255, 100); } + + @Override + protected double calculerY(double hauteurLigne) { + if (Math.random() > 0.5) return hauteurLigne - 8 - (Math.random() * 45); + else return hauteurLigne + 8 + (Math.random() * 45); } @Override - void Afficher(Graphics g) { - if (actif) { - g.setColor(dejaCapture ? new Color(255, 255, 255, 100) : this.couleur); - g.fillOval((int)Math.round(x), (int)Math.round(y), (int)taille, (int)taille); - } + protected void appliquerEffet(Joueur joueur) { + joueur.activerBonusTaille(); } @Override - void Animer() { - if (!actif) { - compteurFrames++; - } - - if (compteurFrames >= 320 && !actif) { - actif = true; - dejaCapture = false; - x = 800; - - double hauteurLigne = 300; - if (maLigne.dernierSegment != null) { - hauteurLigne = maLigne.dernierSegment.y; - } - - if (Math.random() > 0.5) { - y = hauteurLigne - 8 - (Math.random() * 45); - } else { - y = hauteurLigne + 8 + (Math.random() * 45); - } - - if (y < 20) y = 20; - if (y > 550) y = 550; - - compteurFrames = 0; - } - - if (actif) { - double vitesseLigne = monJeu.gestionnaireNiveau.getVitesseScroll(); - x -= vitesseLigne; - - if (!dejaCapture) { - for (Joueur joueur : joueurs) { - if (joueur.verifierCollisionCollectible(x, y, taille, vitesseLigne)) { - joueur.activerBonusTaille(); - dejaCapture = true; - break; - } - } - } - - if (x + taille < 0) { - actif = false; - } - } + protected void dessiner(Graphics g) { + g.fillOval((int)Math.round(x), (int)Math.round(y), (int)taille, (int)taille); } } diff --git a/src/Malus.java b/src/Malus.java index 97e6a52..97fad76 100644 --- a/src/Malus.java +++ b/src/Malus.java @@ -4,77 +4,32 @@ import java.awt.Color; import java.awt.Graphics; import java.util.List; -public class Malus extends ObjetGraphique { +public class Malus extends ObjetCollectible { - protected double taille = 10; - protected boolean actif = false; - protected int compteurFrames = 0; - protected boolean dejaCapture = false; - - protected Ligne maLigne; - protected List joueurs; - protected Jeu monJeu; public Malus(Ligne l, List joueurs, Jeu j) { - this.maLigne = l; - this.joueurs = joueurs; - this.monJeu = j; + super(l, joueurs, j); + this.taille = 10; this.couleur = Color.RED; } + @Override protected int getSeuilActivation() { return 250; } + + @Override protected Color getCouleurCapture() { return Color.BLACK; } + @Override - void Afficher(Graphics g) { - if (actif) { - g.setColor(dejaCapture ? Color.BLACK : this.couleur); - g.fillRect((int)Math.round(x), (int)Math.round(y), (int)taille, (int)taille); - } + protected double calculerY(double hauteurLigne) { + if (Math.random() > 0.5) return hauteurLigne - 75 - (Math.random() * 30); + else return hauteurLigne + 75 + (Math.random() * 30); } @Override - void Animer() { - if (!actif) { - compteurFrames++; - } + protected void appliquerEffet(Joueur joueur) { + if (!monJeu.cheatMode && !joueur.estInvincible()) joueur.retirerVie(); + } - if (compteurFrames >= 250 && !actif) { - actif = true; - dejaCapture = false; - x = 800; - - double hauteurLigne = 300; - if (maLigne.dernierSegment != null) { - hauteurLigne = maLigne.dernierSegment.y; - } - - if (Math.random() > 0.5) { - y = hauteurLigne - 75 - (Math.random() * 30); - } else { - y = hauteurLigne + 75 + (Math.random() * 30); - } - - if (y < 20) y = 20; - if (y > 550) y = 550; - - compteurFrames = 0; - } - - if (actif) { - double vitesseLigne = monJeu.gestionnaireNiveau.getVitesseScroll(); - x -= vitesseLigne; - - if (!dejaCapture) { - for (Joueur joueur : joueurs) { - if (joueur.verifierCollisionCollectible(x, y, taille, vitesseLigne)) { - if (!monJeu.cheatMode && !joueur.estInvincible()) joueur.retirerVie(); - dejaCapture = true; - break; - } - } - } - - if (x + taille < 0) { - actif = false; - } - } + @Override + protected void dessiner(Graphics g) { + g.fillRect((int)Math.round(x), (int)Math.round(y), (int)taille, (int)taille); } } diff --git a/src/ObjetCollectible.java b/src/ObjetCollectible.java new file mode 100644 index 0000000..d18d6bb --- /dev/null +++ b/src/ObjetCollectible.java @@ -0,0 +1,75 @@ +package linea; + +import java.awt.Color; +import java.awt.Graphics; +import java.util.List; + +public abstract class ObjetCollectible extends ObjetGraphique { + + + protected double taille; + protected boolean actif = false; + protected int compteurFrames = 0; + protected boolean dejaCapture = false; + + protected Ligne maLigne; + protected List joueurs; + protected Jeu monJeu; + + public ObjetCollectible(Ligne l, List joueurs, Jeu j) { + this.maLigne = l; + this.joueurs = joueurs; + this.monJeu = j; + } + + protected abstract int getSeuilActivation(); + protected abstract double calculerY(double hauteurLigne); + + protected abstract void appliquerEffet(Joueur joueur); + + protected abstract Color getCouleurCapture(); + + protected abstract void dessiner(Graphics g); + + @Override + void Afficher(Graphics g) { + if (actif) { + g.setColor(dejaCapture ? getCouleurCapture() : this.couleur); + dessiner(g); + } + } + + @Override + void Animer() { + if (!actif) compteurFrames++; + + if (compteurFrames >= getSeuilActivation() && !actif) { + actif = true; + dejaCapture = false; + x = 800; + double hauteurLigne = 300; + if (maLigne.dernierSegment != null) + hauteurLigne = maLigne.dernierSegment.y; + y = calculerY(hauteurLigne); + if (y < 20) y = 20; + if (y > 550) y = 550; + compteurFrames = 0; + } + + if (actif) { + double vitesseLigne = monJeu.gestionnaireNiveau.getVitesseScroll(); + x -= vitesseLigne; + if (!dejaCapture) { + for (Joueur joueur : joueurs) { + if (joueur.verifierCollisionCollectible(x, y, taille, vitesseLigne)) { + appliquerEffet(joueur); + dejaCapture = true; + break; + } + } + } + if (x + taille < 0) actif = false; + } + } + +}