Advertisement
Guest User

StanzaMagica.java

a guest
May 23rd, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.02 KB | None | 0 0
  1. package it.uniroma3.diadia.ambienti;
  2.  
  3. import it.uniroma3.diadia.attrezzi.Attrezzo;
  4.  
  5. public class StanzaMagica extends Stanza {
  6.     final static private int SOGLIA_MAGICA_DEFAULT = 3;
  7.     private int contatoreAttrezziPosati;
  8.     private int sogliaMagica;
  9.  
  10.     public StanzaMagica(String nome) {
  11.         this(nome, SOGLIA_MAGICA_DEFAULT);
  12.     }
  13.  
  14.     public StanzaMagica(String nome, int soglia) {
  15.         super(nome);
  16.         this.contatoreAttrezziPosati = 0;
  17.         this.sogliaMagica = soglia;
  18.     }
  19.  
  20.     @Override
  21.     public boolean addAttrezzo(Attrezzo attrezzo) {
  22.         this.contatoreAttrezziPosati++;
  23.         if (this.contatoreAttrezziPosati > this.sogliaMagica)
  24.             attrezzo = this.modificaAttrezzo(attrezzo);
  25.         return super.addAttrezzo(attrezzo);
  26.     }
  27.  
  28.     private Attrezzo modificaAttrezzo(Attrezzo attrezzo) {
  29.         StringBuilder nomeInvertito;
  30.         int pesoX2 = attrezzo.getPeso() * 2;
  31.         nomeInvertito = new StringBuilder(attrezzo.getNome());
  32.         nomeInvertito = nomeInvertito.reverse();
  33.         attrezzo = new Attrezzo(nomeInvertito.toString(), pesoX2);
  34.         return attrezzo;
  35.     }
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement