⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 room.java

📁 龙与地下城游戏(小型)的设计与实现。主要是随机产生地牢
💻 JAVA
字号:
package dungeonsanddragons.model;/** * Class representing a Room * @author Sandra Nilsson */public class Room {    /** x coordinte (pixles) where this room is drawed*/    private int x;    /** y coordinte (pixles) where this room is drawed*/    private int y;        /** row index of this room */    private int row;    /** column index of this room */    private int col;            private Door north;    private Door south;    private Door east;    private Door west;        /** The item placed in this room (null if an empty room)*/    private Showable item;   /**    * Creates a new room that is llocated in the given positions of the castle    * @param x the x coordinate of the upper left corner of this room in the image of the castle    * @param y the y coordinate of the upper left corner of this room in the image of the castle    * @param row the row index where this room is stored in the multi dimensional array representing the castle    * @param col the col index where this room is stored in the multi dimensional array representing the castle    */    public Room (int x, int y, int row, int col) {        this.x = x;        this.y = y;                this.col = col;        this.row = row;    }    /**     *      * @return the item of this room, null if the room is empty     */    public Showable getItem() {        return item;    }    /**     * Place a item in this room (can be a monster, a weapon, a treasure or an aid kit)     * @param item     */    public void setItem(Showable item) {        this.item = item;    }        /**      * @return the row index where this room is stored in the multi dimensional array representing the castle     */    public int getCol() {        return col;    }    /**     *      * @return the row index where this room is stored in the multi dimensional array representing the castle     */    public int getRow() {        return row;    }    /**     *      * @return the x coordinate of the upper left corner of this room in the image of the castle     */    public int getX() {        return x;    }    /**     *      * @return the y coordinate of the upper left corner of this room in the image of the castle     */    public int getY() {        return y;    }        /**     *      * @return the number of doors to this room     */    public int getNumberOfDoors(){        int res = 0;        if(north != null){            res++;        }        if(east != null){            res++;        }        if(south != null){            res++;        }        if(west != null){            res++;        }        return res;    }    /**     *      * @return the east door object of the room     */    public Door getEast() {        return east;    }    /**     *      * @return the north door object of the room     */    public Door getNorth() {        return north;    }    /**     *      * @return the south door object of the room     */    public Door getSouth() {        return south;    }    /**     *      * @return the west door object of the room     */    public Door getWest() {        return west;    }    /**     * Set the east door object of the room     * @param east the door to set as east door     */    public void setEast(Door east) {        this.east = east;    }/** * Set the north door object of the room * @param north the door to set as north door */    public void setNorth(Door north) {        this.north = north;    }    /**     * Set the south door object of the room     * @param south the south door object of this room     */    public void setSouth(Door south) {        this.south = south;    }    /**     * Set the west door object of the room     * @param west the west door object to set     */    public void setWest(Door west) {        this.west = west;    }        /**     * Return a string representing this room     * The string representation is a representaiton of the doors of the rooms     * The doors starts at north and rotates clockwise.      * If the room has a door to the north the string will start with an 'n', next is 'e' then 's' and last 'w'     * That means that a room with doors in all four directions will be represented by the string 'nesw'     * A room with a door only to the south and west will be represented by the string 'sw'     * @return  the string representing the room     */    public String roomString(){        String res = "";        if(north != null){            res += "n";        }        if(east != null){            res += "e";        }        if(south != null){            res += "s";        }        if(west != null){            res += "w";        }        return res;    }        /**     *      * @return a string with a complete description if this room     */    public String toString(){        return "Room with " + getNumberOfDoors() + " doors. Represented by " + roomString() + " on index " + row + "/" + col;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -