有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java冒险类的基于文本的冒险游戏

在我的游戏中,我编写了几个类,包括房间、灯、箱子、java、玩家、钥匙和地图。这些都已经过测试,都是正确的,所以现在我正在编写我的冒险类,它是该程序的驱动程序。我需要将玩家房间的位置设置为[0][0],但我不知道如何设置。以下是我到目前为止在我的房间和冒险课上学到的东西

public class Adventure {

    Scanner in = new Scanner(System.in);
    private Room room;

    public Adventure() {
        Player player = new Player();
        Map map = new Map();
        player.setX(0);
        player.setY(0);
        int x = 0;
        int y = 0;
        map.getRoom(x, y).getDescription(); 
    }
}

public class Room {

    private String description;
    private boolean north;
    private boolean south;
    private boolean east;
    private boolean west;
    private boolean isDark;

    private Lamp theLamp;
    private Key theKey;
    private Chest theChest;

    /**
     * Returns the text description of this room
     */
    public String getDescription() {
        return description;
    }

    /**
     * Returns true if the player can go north from this room
     */
    public boolean canGoNorth() {
        return north;
    }

    /**
     * Returns true if the player can go south from this room
     */
    public boolean canGoSouth() {
        return south;
    }

    /**
     * Returns true if the player can go east from this room
     */
    public boolean canGoEast() {
        return east;
    }

    /**
     * Returns true if the player can go west from this room
     */
    public boolean canGoWest() {
        return west;
    }

    /**
     * Returns the lamp object in this room.
     * If no lamp is present, returns null
     */
    public Lamp getLamp() {
        return theLamp;
    }

    /**
     * Sets the lamp variable in this room to null
     */
    public void clearLamp() {
        theLamp = null;
    }

    /**
     * Returns the key object in this room. 
     * If no key is present, returns null
     */
    public Key getKey() {
        return theKey;
    }

    /**
     * Sets the key variable in this room to null
     */
    public void clearKey() {
        theKey = null;
    }

    /**
     * Returns the chest object in this room.
     * If no chest is present, returns null
     */
    public Chest getChest() {
        return theChest;
    }

    /**
     * Returns true if there is no light in this room,
     * veeeeeeeery dangerous!
     */
    public boolean isDark() {
        return isDark;
    }


    /**
     * Hey wassup dawg?  I'ma constructor.  I make the objects round these parts, 
     * sometimes without even trying, knowwhatimssayin?
     * Yall don't haveta worry 'bout me for this'ere game, but look me up in 
     * Chapter 6 sometime. Kay?
     *   
     */
    public Room(String description, boolean north, boolean south, boolean east,
            boolean west, boolean isDark, Lamp theLamp, Key theKey,
            Chest theChest) {
        super();
        this.description = description;
        this.north = north;
        this.south = south;
        this.east = east;
        this.west = west;
        this.isDark = isDark;
        this.theLamp = theLamp;
        this.theKey = theKey;
        this.theChest = theChest;
    }
}

我必须将房间位置设置为0,0,这样map类中的描述就会打印出来


共 (0) 个答案