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

📄 building.java

📁 MegaMek is a networked Java clone of BattleTech, a turn-based sci-fi boardgame for 2+ players. Fight
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * will be based on the type.     *     * @param type      The <code>int</code> type of the building.     * @param id        The <code>int</code> ID of this building.     * @param name      The <code>String</code> name of this building.     * @param coords    The <code>Vector</code> of <code>Coords<code>     *                  for this building.  This object is used directly     *                  without being copied.     * @exception an <code>IllegalArgumentException</code> will be thrown if     *          the given coordinates do not contain a building, or if the     *          building covers multiple hexes with different CFs.     */    public Building( int type, int id, String name, Vector coords ) {        this.type = type;        this.id = id;        this.name = name;        this.coordinates = coords;        // Insure that we've got a good type (and initialize our CF).        this.currentCF = getDefaultCF( this.type );        this.phaseCF = this.currentCF;        if ( this.currentCF == Building.UNKNOWN ) {            throw new IllegalArgumentException( "Invalid construction type: " +                                                this.type + "." );        }    }    /**     * Get the ID of this building.  The same ID applies to all hexes.     *     * @return  the <code>int</code> ID of the building.     */    public int getId() {        return this.id;    }    /**     * Determine if the building occupies given coordinates.  Multi-hex     * buildings will occupy multiple coordinates.  Only one building per     * hex.     *     * @param   coords - the <code>Coords</code> being examined.     * @return  <code>true</code> if the building occupies the coordinates.     *          <code>false</code> otherwise.     */    public boolean isIn( Coords coords ) {        return this.coordinates.contains( coords );    }    /**     * Get the coordinates that the building occupies.     *     * @return  an <code>Enumeration</code> of the <code>Coord</code> objects.     */    public Enumeration getCoords() {        return this.coordinates.elements();    }    /**     * Get the construction type of the building.  This value will be one     * of the constants, LIGHT, MEDIUM, HEAVY, or HARDENED.     *     * @return  the <code>int</code> code of the building's construction type.     */    public int getType() {        return this.type;    }    /**     * Get the current construction factor of the building.     * Any damage immediately updates this value.     *     * @return  the <code>int</code> value of the building's current     *          construction factor.  This value will be greater than     *          or equal to zero.     */    public int getCurrentCF() {        return this.currentCF;    }    /**     * Get the construction factor of the building at the start of the     * current phase.  Damage that is received during the phase is     * applied at the end of the phase.     *     * @return  the <code>int</code> value of the building's construction     *          factor at the start of this phase.  This value will be     *          greater than or equal to zero.     */    public int getPhaseCF() {        return this.phaseCF;    }    /**     * Set the current construction factor of the building.     * Call this method immediately when the building sustains any damage.     *     * @param   cf - the <code>int</code> value of the building's current     *          construction factor.  This value must be greater than     *          or equal to zero.     * @exception If the passed value is less than zero, an     *          <code>IllegalArgumentException</code> is thrown.     */    public void setCurrentCF( int cf ) {        if (cf < 0) {            throw new IllegalArgumentException                ("Invalid value for Construction Factor: " + cf);        }        this.currentCF = cf;    }    /**     * Set the construction factor of the building for the start of the     * next phase.  Call this method at the end of the phase to apply     * damage sustained by the building during the phase.     *     * @param   cf - the <code>int</code> value of the building's current     *          construction factor.  This value must be greater than     *          or equal to zero.     * @exception If the passed value is less than zero, an     *          <code>IllegalArgumentException</code> is thrown.     */    public void setPhaseCF( int cf ) {        if ( cf < 0 ) {            throw new IllegalArgumentException                ( "Invalid value for Construction Factor: " + cf );        }        this.phaseCF = cf;    }    /**     * Get the name of this building.     *     * @return  the <code>String</code> name of this building.     */    public String getName() {        return this.name;    }    /**     * Get the default construction factor for the given type of building.     *     * @param   type - the <code>int</code> construction type of the building.     * @return  the <code>int</code> default construction factor for that type     *          of building.  If a bad type value is passed, the constant     *          <code>Building.UNKNOWN</code> will be returned instead.     */    public static int getDefaultCF( int type ) {        int retval = Building.UNKNOWN;        switch ( type ) {        case Building.LIGHT    :            retval = 15;            break;        case Building.MEDIUM   :            retval = 40;            break;        case Building.HEAVY    :            retval = 90;            break;        case Building.HARDENED :            retval = 120;            break;        }        return retval;    }    /**     * Override <code>Object#equals(Object)</code>.     *     * @param   other - the other <code>Object</code> to compare to this     *          <code>Building</code>.     * @return  <code>true</code> if the other object is the same as this     *          <code>Building</code>.  The value <code>false</code> will be     *          returned if the other object is <code>null</code>, is not a     *          <code>Buildig</code>, or if it is not the same as this     *          <code>Building</code>.     */    public boolean equals( Object other ) {        if ( other == null ||             !(other instanceof Building) ) {            return false;        }        // True until we're talking about more than one Board per Game.        Building bldg = (Building) other;        return ( this.id == bldg.id );    }    /**     * Get a String for this building.     */    public String toString() {        // Assemble the string in pieces.        StringBuffer buf = new StringBuffer();        // Add the building type to the buffer.        switch ( this.getType() ) {        case Building.LIGHT   : buf.append( "Light " ); break;        case Building.MEDIUM  : buf.append( "Medium " ); break;        case Building.HEAVY   : buf.append( "Heavy " ); break;        case Building.HARDENED: buf.append( "Hardened " ); break;        }        // Add the building's name.        buf.append( this.name );        // Return the string.        return buf.toString();    }    /**     * Determine if this building is on fire.     *     * @return  <code>true</code> if the building is on fire.     */    public boolean isBurning() {        return burning;    }    /**     * Set the flag that indicates that this building is on fire.     *     * @param   onFire - a <code>boolean</code> value that indicates whether     *          this building is on fire.     */    public void setBurning( boolean onFire ) {        this.burning = onFire;    }    public void addDemolitionCharge( int playerId, int damage ) {        DemolitionCharge charge = new DemolitionCharge(playerId, damage);        demolitionCharges.add(charge);    }} // End public class Building implements Serializable

⌨️ 快捷键说明

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