Verified Commit e2904595 authored by Jonas Sulzer's avatar Jonas Sulzer 馃帗
Browse files

馃摝 NEW: add Magic.java



Signed-off-by: Jonas Sulzer's avatarJonas Sulzer <jonas@violoncello.ch>
parent 3fb03e90
package Ex_07;
import java.util.ArrayList;
class Magic {
public static void main(String[] args) {
Jeu maMain = new Jeu(10);
maMain.piocher(new Terrain('b'));
maMain.piocher(new Creature(6, "Golem", 4, 6));
maMain.piocher(new Sortilege(1, "Croissance Gigantesque",
"La cr茅ature cibl茅e gagne +3/+3 jusqu'脿 la fin du tour"));
System.out.println("L脿, j'ai en stock :");
maMain.afficher();
maMain.joue();
}
}
class Jeu {
ArrayList<Carte> cartes;
public Jeu(int nbOfCates) {
cartes = new ArrayList<>();
System.out.println("On change de main");
}
public void piocher(Carte carte) {
cartes.add(carte);
if (carte instanceof Terrain) {
System.out.println("Un nouveau terrain");
} else if (carte instanceof Creature) {
System.out.println("Une nouvelle cr茅ature");
} else if (carte instanceof Sortilege) {
System.out.println("Un sortil猫ge de plus.");
}
}
public void joue() {
System.out.println("Je joue une carte...");
Carte carte = cartes.remove(0);
System.out.println("La carte jou茅e est :");
carte.afficher();
}
public void afficher() {
for (Carte carte: cartes) {
carte.afficher();
}
}
}
abstract class Carte extends ArrayList {
private double cout;
public Carte(double cout) {
this.cout = cout;
}
public abstract void afficher();
}
class Terrain extends Carte {
private char colour;
public Terrain(char colour) {
super(0);
this.colour = colour;
}
public void afficher() {
System.out.println("Un terrain " + colour);
}
}
class Creature extends Carte {
private String nom;
private int degats;
private int vie;
public Creature(double cout, String nom, int degats, int vie) {
super(cout);
this.nom = nom;
this.degats = degats;
this.vie = vie;
}
public void afficher() {
System.out.println("Une cr茅ature " + nom + " " + degats + "/" + vie);
}
}
class Sortilege extends Carte {
private String nom;
private String explication;
public Sortilege(double cout, String nom, String explication) {
super(cout);
this.nom = nom;
this.explication = explication;
}
public void afficher() {
System.out.println("Un sortil猫ge " + nom);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment