atanasovetr

Battleship

Apr 1st, 2021
1,069
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.86 KB | None | 0 0
  1. public abstract class Battleship {
  2.     protected long id;
  3.     protected String name;
  4.     protected Color color;
  5.     protected int attackDamage;
  6.     protected int life;
  7.     protected int shield;
  8.     protected int capacity;
  9.  
  10.     public Battleship(long id, String name, Color color, int attackDamage, int life, int shield, int capacity) {
  11.         this.id = id;
  12.         this.name = name;
  13.         this.color = color;
  14.         this.attackDamage = attackDamage;
  15.         this.life = life;
  16.         this.shield = shield;
  17.         this.capacity = capacity;
  18.     }
  19.  
  20.     abstract void attack(Battleship battleship);
  21.     abstract void takeDamage(int damage);
  22.  
  23.     public boolean isDestroyed(){
  24.         if(this.life <= 0){
  25.             return true;
  26.         }
  27.         return false;
  28.  
  29.     }
  30.  
  31.     public long getId() {
  32.         return id;
  33.     }
  34.  
  35.     public void setId(long id) {
  36.         this.id = id;
  37.     }
  38.  
  39.     public String getName() {
  40.         return name;
  41.     }
  42.  
  43.     public void setName(String name) {
  44.         this.name = name;
  45.     }
  46.  
  47.     public Color getColor() {
  48.         return color;
  49.     }
  50.  
  51.     public void setColor(Color color) {
  52.         this.color = color;
  53.     }
  54.  
  55.     public int getAttackDamage() {
  56.         return attackDamage;
  57.     }
  58.  
  59.     public void setAttackDamage(int attackDamage) {
  60.         this.attackDamage = attackDamage;
  61.     }
  62.  
  63.     public int getLife() {
  64.         return life;
  65.     }
  66.  
  67.     public void setLife(int life) {
  68.         this.life = life;
  69.     }
  70.  
  71.     public int getShield() {
  72.         return shield;
  73.     }
  74.  
  75.     public void setShield(int shield) {
  76.         this.shield = shield;
  77.     }
  78.  
  79.     public int getCapacity() {
  80.         return capacity;
  81.     }
  82.  
  83.     public void setCapacity(int capacity) {
  84.         this.capacity = capacity;
  85.     }
  86. }
  87.  
  88.  
  89. -----------------------
  90.  
  91. public enum Color {
  92.     BLACK, WHITE
  93. }
  94.  
  95.  
  96. -----------------------
  97.  
  98.  
  99. public class MillenniumFalcon extends Battleship {
  100.     private int dodge;
  101.  
  102.     public MillenniumFalcon(long id, String name, Color color, int attackDamage, int life, int shield, int capacity, int dodge) {
  103.         super(id, name, color, attackDamage, life, shield, capacity);
  104.         this.dodge = dodge;
  105.     }
  106.  
  107.  
  108.     @Override
  109.     void attack(Battleship battleship){
  110.         battleship.takeDamage(attackDamage);
  111.         this.attackDamage *= 2;
  112.     }
  113.  
  114.     @Override
  115.     void takeDamage(int damage){
  116.         this.life -= damage + 50;
  117.     }
  118.  
  119.     public int getDodge() {
  120.         return dodge;
  121.     }
  122.  
  123.     public void setDodge(int dodge) {
  124.         this.dodge = dodge;
  125.     }
  126. }
  127.  
  128.  
  129. -----------------------
  130.  
  131.  
  132. public class EbonHawk extends Battleship{
  133.  
  134.     public EbonHawk(long id, String name, Color color, int attackDamage, int life, int shield, int capacity) {
  135.         super(id, name, color, attackDamage, life, shield, capacity);
  136.     }
  137.  
  138.     @Override
  139.     void attack(Battleship battleship) {
  140.         battleship.takeDamage(attackDamage);
  141.     }
  142.  
  143.     @Override
  144.     void takeDamage(int damage) {
  145.         this.life -= damage;
  146.     }
  147.  
  148.     public void heal(int bonusLife){
  149.         this.life += bonusLife;
  150.     }
  151. }
  152.  
  153.  
  154. -----------------------
  155.  
  156.  
  157. public class Outrider extends Battleship{
  158.     private int plasmaDefense;
  159.  
  160.     public Outrider(long id, String name, Color color, int attackDamage, int life, int shield, int capacity, int plasmaDefense) {
  161.         super(id, name, color, attackDamage, life, shield, capacity);
  162.         this.plasmaDefense = plasmaDefense;
  163.         super.life += 100;
  164.     }
  165.  
  166.     @Override
  167.     void attack(Battleship battleship) {
  168.         battleship.takeDamage(attackDamage);
  169.     }
  170.  
  171.     @Override
  172.     void takeDamage(int damage) {
  173.         this.life -= damage - 50;
  174.     }
  175.  
  176.     public int getPlasmaDefense() {
  177.         return plasmaDefense;
  178.     }
  179.  
  180.     public void setPlasmaDefense(int plasmaDefense) {
  181.         this.plasmaDefense = plasmaDefense;
  182.     }
  183. }
  184.  
Advertisement
Add Comment
Please, Sign In to add comment