Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.02 KB | None | 0 0
  1. public class CharAssault {
  2.     private int arme;
  3.     private int carburant;
  4.     private String nomID;
  5.    
  6.     public static final int CARBURANT_INITIAL = 100;
  7.     public static final int PUISSANCE_ARME = 10;
  8.  
  9.    
  10.     public CharAssault(String nom) {
  11.         arme = PUISSANCE_ARME;
  12.         setCarburant(CARBURANT_INITIAL);
  13.         setNomID(nom);
  14.     }
  15.    
  16.     public int getArme() {
  17.         return arme;
  18.     }
  19.  
  20.     public void setArme(int arme) {
  21.         this.arme = arme;
  22.     }
  23.     public String getNomID() {
  24.         return nomID;
  25.     }
  26.  
  27.     public void setNomID(String nomID) {
  28.         this.nomID = nomID;
  29.     }
  30.  
  31.     public int getCarburant() {
  32.         return carburant;
  33.     }
  34.  
  35.     public void setCarburant(int carburant) {
  36.         this.carburant = carburant;
  37.     }
  38.    
  39.     public void recevoirDegats(int degats) {
  40.         this.carburant -= degats;
  41.     }
  42.    
  43.     public void recevoirDegats(CharAssault leChar) {
  44.         carburant -= leChar.getArme();
  45.     }
  46.    
  47.     public void tirer(CharAssault leChar) {
  48.         // leChar.recevoirDegats(this.getArme()); // premier recevoir
  49.         leChar.recevoirDegats(this); // second recevoir
  50.     }
  51. }
  52. import java.util.Random;
  53.  
  54. public class CharAgile extends CharAssault{
  55.     public CharAgile(String nom) {
  56.         super(nom);
  57.         super.setArme(PUISSANCE_ARME / 2);
  58.         // setArme(PUISSANCE_ARME / 2); suffit
  59.     }
  60.    
  61.     public void recevoirDegats(int degats) {
  62.         if(!this.esquiver())
  63.         {
  64.             super.setCarburant(super.getCarburant() - degats); // Apparement setCarburant suffit
  65.         }                                             // car les setters et getters sont publics
  66.     }
  67.    
  68.     public boolean esquiver() {
  69.         Random rand = new Random();
  70.         int n = rand.nextInt(100);
  71.         return (n < 20 ? true : false);
  72.     }
  73. }
  74. public class CharBouclier extends CharAssault {
  75.    
  76.     private int bouclier;
  77.     public static final int BOUCLIER_INIT = 3;
  78.    
  79.     public CharBouclier(String nom) {
  80.         super(nom);
  81.         bouclier = 3;
  82.     }
  83.    
  84.     public void setBouclier(int bouclier) {
  85.         this.bouclier = bouclier;
  86.     }
  87.    
  88.     public int getBouclier() {
  89.         return bouclier;
  90.     }
  91.    
  92.     public boolean proteger() {
  93.         if(bouclier != 0)
  94.         {
  95.             bouclier--;
  96.             return true;
  97.         }
  98.         else
  99.         {
  100.             return false;
  101.         }
  102.     }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement