Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CharAssault {
- private int arme;
- private int carburant;
- private String nomID;
- public static final int CARBURANT_INITIAL = 100;
- public static final int PUISSANCE_ARME = 10;
- public CharAssault(String nom) {
- arme = PUISSANCE_ARME;
- setCarburant(CARBURANT_INITIAL);
- setNomID(nom);
- }
- public int getArme() {
- return arme;
- }
- public void setArme(int arme) {
- this.arme = arme;
- }
- public String getNomID() {
- return nomID;
- }
- public void setNomID(String nomID) {
- this.nomID = nomID;
- }
- public int getCarburant() {
- return carburant;
- }
- public void setCarburant(int carburant) {
- this.carburant = carburant;
- }
- public void recevoirDegats(int degats) {
- this.carburant -= degats;
- }
- public void recevoirDegats(CharAssault leChar) {
- carburant -= leChar.getArme();
- }
- public void tirer(CharAssault leChar) {
- // leChar.recevoirDegats(this.getArme()); // premier recevoir
- leChar.recevoirDegats(this); // second recevoir
- }
- }
- import java.util.Random;
- public class CharAgile extends CharAssault{
- public CharAgile(String nom) {
- super(nom);
- super.setArme(PUISSANCE_ARME / 2);
- // setArme(PUISSANCE_ARME / 2); suffit
- }
- public void recevoirDegats(int degats) {
- if(!this.esquiver())
- {
- super.setCarburant(super.getCarburant() - degats); // Apparement setCarburant suffit
- } // car les setters et getters sont publics
- }
- public boolean esquiver() {
- Random rand = new Random();
- int n = rand.nextInt(100);
- return (n < 20 ? true : false);
- }
- }
- public class CharBouclier extends CharAssault {
- private int bouclier;
- public static final int BOUCLIER_INIT = 3;
- public CharBouclier(String nom) {
- super(nom);
- bouclier = 3;
- }
- public void setBouclier(int bouclier) {
- this.bouclier = bouclier;
- }
- public int getBouclier() {
- return bouclier;
- }
- public boolean proteger() {
- if(bouclier != 0)
- {
- bouclier--;
- return true;
- }
- else
- {
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement