Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as Java by Lubos ( 15 years ago )
package commands;

import TextGame.Game;
import TextGame.GameState;
import TextGame.Item;
import TextGame.Room;
import interfaces.Parametric;
import interfaces.Useable;

/**
 * Trieda reprezentujúca príkaz Pouzi.
 * @author Lubos
 */
public class Use extends AbstractCommand implements Parametric {

    /**
     * Konštruktor. Nastavuje meno a opis triedy.
     */
    public Use() {
        super("POUZI", "Použije vec, ktorá sa nachádza v inventári alebo v miestnosti. Príkaz má jeden povinný parameter, ktorým je názov predmetu.");
    }

    /**
     * Vykoná daný príkaz.
     * @param game referencia na hru
     * @return state stav hry
     */
    public GameState execute(Game game) {
        Room aCurrentRoom = game.getCurrentRoom();

        if (getParams().length() == 0) {
            System.out.println("Co mam pouzit???");
            return GameState.PLAYING;
        }
        Item aRoomItem = aCurrentRoom.getItem(getParams());
        if (aRoomItem instanceof Useable) {
            return ((Useable) aRoomItem).use(game);
        
          
        }
        Item aInvetoryItem = game.getBackpack().getItem(getParams());
        if (aInvetoryItem instanceof Useable) {
            return ((Useable) aInvetoryItem).use(game);
        }
        System.out.println("Tento predmet sa neda pouzit");

        return GameState.PLAYING;
    }
}

 

Revise this Paste

Parent: 27024
Children: 27046
Your Name: Code Language: