001import java.util.Stack;
002public class Beamer extends Item {
003    private Room aRoom;
004    private boolean aCharged;
005    private Player aPlayer;
006    private GameEngine aGameEngine;
007
008    public Beamer(final String pName, final String pDescription, final double pPrice, final Player pPlayer,
009            final GameEngine pGameEngine) {
010        super(pName, pDescription, pPrice);
011        this.aCharged = false;
012        this.aRoom = null;
013        this.aPlayer = pPlayer;
014        this.aGameEngine = pGameEngine;
015    }
016
017    public boolean getCharged() {
018        return this.aCharged;
019    }
020    /**
021     * Charge le beamer
022     * @param pRoom salle ou le beamer nous téléportera
023     * @return String
024     */
025    public String charge(final Room pRoom) {
026        this.aRoom = pRoom;
027        this.aCharged = true;
028        return "You've just charged your beamer.";
029    }
030    /**
031     * Utilises le beamer pour nous téléporter.
032     * @return String
033     */
034    public String fire() {
035        if (!this.aCharged) {
036            return "Your beamer is not charged. You can't use it.";
037        } else {
038            this.aPlayer.changeRoom(this.aRoom);
039            this.aPlayer.setPrevRooms(new Stack<Room>());
040            if (this.aPlayer.getCurrentRoom().getImageName() != null) {
041                this.aGameEngine.getGui().showImage(this.aPlayer.getCurrentRoom().getImageName());
042            }
043            this.aRoom = null;
044            this.aCharged = false;
045            return "Your beamer is charged. You've been teleporting."
046                    + this.aPlayer.getCurrentRoom().getLongDescription();
047        }
048    }
049
050    public Room getRoom() {
051        return this.aRoom;
052    }
053}