Package jpotter

Source Code of jpotter.Harry

package jpotter;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.imageio.ImageIO;

import jpotter.spells.Accio;
import jpotter.spells.Aguamenti;
import jpotter.spells.Avis;
import jpotter.spells.Deprimo;
import jpotter.spells.Expelliarmus;
import jpotter.spells.Incendio;
import jpotter.spells.Spell;

/**
* Date: 27 Mar 2011 Time: 11:11:38
*
* @author Thomas Michel
*/
public class Harry implements Player{
  private int pv;
  private List<Spell> knownSpells;
  private BufferedImage img;
  private boolean ko;

  /**
   *
   * @author Thomas Michel
   */
  public Harry(int pv) throws IOException {
    knownSpells = Collections.synchronizedList(new ArrayList<Spell>(5));
    this.pv = pv;
    initImage();
    initSpells();
  }

  private void initSpells() {
    // add some random spells for now
    knownSpells.add(new Accio());
    knownSpells.add(new Aguamenti());
    knownSpells.add(new Avis());
    knownSpells.add(new Deprimo());
    knownSpells.add(new Expelliarmus());
    knownSpells.add(new Incendio());
  }

  /**
   * @return a defensive copy of the player's known spells
   */
  public List<Spell> getSpellList() {
    return new ArrayList<Spell>(knownSpells);
  }

  private void initImage() throws IOException {
    img = ImageIO.read(new File("img/harrypotter.jpg"));
  }

  public BufferedImage getImage() {
    if (img == null)
      try {
        initImage();
      } catch (IOException ex) {
        ex.printStackTrace();
      }
    return img;
  }

  public int getWidth() {
    return img.getWidth();
  }

  public int getHeight() {
    return img.getHeight();
  }

  public void setPv(int pv) {
    this.pv = pv;
  }

  public int getPv() {
    return pv;
  }

  public boolean updatePv(int damage) throws IOException {
    pv -= damage;
    if (pv > 0)
      return false;
    img = ImageIO.read(new File("img/knockout.jpg"));
    setKo(true);
    return true;
  }

  public void setKo(boolean ko) {
    this.ko = ko;
  }

  public boolean isKo() {
    return ko;
  }

  @Override
  public void play() {
    IHM.getInstance().displayText("It's your turn !!");
    FusionManager.getInstance().canCastSpell();
  }

}
TOP

Related Classes of jpotter.Harry

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.