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

📄 game.java

📁 MegaMek is a networked Java clone of BattleTech, a turn-based sci-fi boardgame for 2+ players. Fight
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        resetActions();        resetCharges();        resetPSRs();        resetArtilleryAttacks();        removeMinefields();        removeArtyAutoHitHexes();        resetLayMinefieldActions();        flares.removeAllElements();        clearAllReports();        forceVictory = false;        victoryPlayerId = Player.PLAYER_NONE;        victoryTeam = Player.TEAM_NONE;    }    private void removeArtyAutoHitHexes() {        Enumeration iter = getPlayers();        while (iter.hasMoreElements()) {            Player player = (Player) iter.nextElement();            player.removeArtyAutoHitHexes();        }    }            private void removeMinefields() {        minefields.clear();        vibrabombs.removeAllElements();        Enumeration iter = getPlayers();        while (iter.hasMoreElements()) {            Player player = (Player) iter.nextElement();            player.removeMinefields();        }    }    /**     * Regenerates the entities by id hashtable by going thru all entities     * in the Vector     */    private void reindexEntities() {        entityIds.clear();        lastEntityId = 0;        if ( entities != null ) {            // Add these entities to the game.            for (Enumeration i = entities.elements(); i.hasMoreElements();) {                final Entity entity = (Entity)i.nextElement();                final int id = entity.getId();                entityIds.put(new Integer(id), entity);                entity.setGame(this);                                                if(id > lastEntityId) lastEntityId = id;            }        }    }    /**     * Returns the first entity at the given coordinate, if any.  Only returns     * targetable (non-dead) entities.     *     * @param c the coordinates to search at     */    public Entity getFirstEntity(Coords c) {        for (Enumeration i = entities.elements(); i.hasMoreElements();) {            final Entity entity = (Entity)i.nextElement();            if (c.equals(entity.getPosition()) && entity.isTargetable()) {                return entity;            }        }        return null;    }    /**     * Returns the first enemy entity at the given coordinate, if any.     * Only returns targetable (non-dead) entities.     *     * @param c the coordinates to search at     * @param currentEntity the entity that is firing     */    public Entity getFirstEnemyEntity(Coords c, Entity currentEntity) {        for (Enumeration i = entities.elements(); i.hasMoreElements();) {            final Entity entity = (Entity)i.nextElement();            if (c.equals(entity.getPosition()) && entity.isTargetable() && entity.isEnemyOf(currentEntity)) {                return entity;            }        }        return null;    }    /**     * Returns an Enumeration of the active entities at the given coordinates.     */    public Enumeration getEntities(Coords c) {        Vector vector = new Vector();        // Only build the list if the coords are on the board.        if ( this.board.contains(c) ) {            for (Enumeration i = entities.elements(); i.hasMoreElements();) {                final Entity entity = (Entity)i.nextElement();                if (c.equals(entity.getPosition()) && entity.isTargetable()) {                    vector.addElement(entity);                }            }        }        return vector.elements();    }        /**     * Returns a Target for an Accidental Fall From above, or null if no     * possible target is there     * @param c The <code>Coords</code> of the hex in which the accidental fall     *          from above happens     * @param ignore The entity who is falling     * @return  The <code>Entity</code> that should be an AFFA target.     */    public Entity getAffaTarget(Coords c, Entity ignore) {        Vector vector = new Vector();        if ( this.board.contains(c) ) {            for (Enumeration i = entities.elements(); i.hasMoreElements();) {                final Entity entity = (Entity)i.nextElement();                if (c.equals(entity.getPosition()) && entity.isTargetable() &&                    !(entity instanceof Infantry) && entity != ignore) {                    vector.addElement(entity);                }            }        }        if (!vector.isEmpty()) {            int count = vector.size();            int random = Compute.randomInt(count);            return (Entity)vector.elementAt(random);        }        return null;    }        /**     * Returns an <code>Enumeration</code> of the enemy's active     * entities at the given coordinates.     *     * @param   c the <code>Coords</code> of the hex being examined.     * @param   currentEntity the <code>Entity</code> whose enemies are needed.     * @return  an <code>Enumeration</code> of <code>Entity</code>s at the     *          given coordinates who are enemies of the given unit.     */    public Enumeration getEnemyEntities( final Coords c,                                         final Entity currentEntity ) {        // Use an EntitySelector to avoid walking the entities vector twice.        return this.getSelectedEntities            (new EntitySelector() {                    private Coords coords = c;                    private Entity friendly = currentEntity;                    public boolean accept (Entity entity) {                        if ( coords.equals(entity.getPosition())                             && entity.isTargetable()                             && entity.isEnemyOf(friendly) )                            return true;                        return false;                    }                });    }        /**     * Returns an <code>Enumeration</code> of friendly active     * entities at the given coordinates.     *     * @param   c the <code>Coords</code> of the hex being examined.     * @param   currentEntity the <code>Entity</code> whose friends are needed.     * @return  an <code>Enumeration</code> of <code>Entity</code>s at the     *          given coordinates who are friends of the given unit.     */    public Enumeration getFriendlyEntities( final Coords c,                                         final Entity currentEntity ) {        // Use an EntitySelector to avoid walking the entities vector twice.        return this.getSelectedEntities            (new EntitySelector() {                    private Coords coords = c;                    private Entity friendly = currentEntity;                    public boolean accept (Entity entity) {                        if ( coords.equals(entity.getPosition())                             && entity.isTargetable()                             && !entity.isEnemyOf(friendly) )                            return true;                        return false;                    }                });    }    /**     * Moves an entity into the graveyard so it stops getting sent     * out every phase.     */    public void moveToGraveyard(int id) {        this.removeEntity( id, IEntityRemovalConditions.REMOVE_SALVAGEABLE );    }    /**     * See if the <code>Entity</code> with the given ID is out of the game.     *     * @param id - the ID of the <code>Entity</code> to be checked.     * @return  <code>true</code> if the <code>Entity</code> is in the     *    graveyard, <code>false</code> otherwise.     */    public boolean isOutOfGame( int id ) {        for (Enumeration i = vOutOfGame.elements(); i.hasMoreElements();) {            Entity entity = (Entity)i.nextElement();            if (entity.getId() == id) {                return true;            }        }        return false;    }    /**     * See if the <code>Entity</code> is out of the game.     *     * @param entity - the <code>Entity</code> to be checked.     * @return  <code>true</code> if the <code>Entity</code> is in the     *    graveyard, <code>false</code> otherwise.     */    public boolean isOutOfGame( Entity entity ) {        return isOutOfGame(entity.getId());    }    /**     * Returns the first entity that can act in the present turn, or null if     * none can.     */    public Entity getFirstEntity() {        return getFirstEntity(getTurn());    }    /**     * Returns the first entity that can act in the specified turn, or null if     * none can.33     */    public Entity getFirstEntity(GameTurn turn) {        return getEntity(getFirstEntityNum(getTurn()));    }    /**     * Returns the id of the first entity that can act in the current turn,     * or -1 if none can.     */    public int getFirstEntityNum() {        return getFirstEntityNum(getTurn());    }    /**     * Returns the id of the first entity that can act in the specified turn,     * or -1 if none can.     */    public int getFirstEntityNum(GameTurn turn) {        if (turn == null) {            return -1;        }        for (Enumeration i = entities.elements(); i.hasMoreElements();) {            final Entity entity = (Entity)i.nextElement();            if (turn.isValidEntity(entity, this)) {                return entity.getId();            }        }        return -1;    }    /**     * Returns the next selectable entity that can act this turn,     * or null if none can.     *     * @param start the index number to start at     */    public Entity getNextEntity(int start) {        return getEntity(getNextEntityNum(getTurn(), start));    }    public int getNextEntityNum(int start) {        return getNextEntityNum(getTurn(), start);    }    /**     * Returns the entity id of the next entity that can move during the     * specified     *     * @param turn the turn to use     * @param start the entity id to start at     */    public int getNextEntityNum(GameTurn turn, int start) {        boolean startPassed = false;        for (Enumeration i = entities.elements(); i.hasMoreElements();) {            final Entity entity = (Entity)i.nextElement();            if (entity.getId() == start) {                startPassed = true;            } else if (startPassed && turn.isValidEntity(entity, this)) {                return entity.getId();            }        }        return getFirstEntityNum(turn);    }    /**     * Returns the number of the first deployable entity     */    public int getFirstDeployableEntityNum() {      return getFirstDeployableEntityNum(getTurn());    }    public int getFirstDeployableEntityNum(GameTurn turn) {        // Repeat the logic from getFirstEntityNum.        if (turn == null) {            return -1;        }        for (Enumeration i = entities.elements(); i.hasMoreElements();) {            final Entity entity = (Entity)i.nextElement();            if ( turn.isValidEntity(entity, this) &&                 entity.shouldDeploy(getRoundCount()) ) {                return entity.getId();            }        }        return -1;    }    /**     * Returns the number of the next deployable entity     */    public int getNextDeployableEntityNum(int entityId) {      return getNextDeployableEntityNum(getTurn(), entityId);    }    public int getNextDeployableEntityNum(GameTurn turn, int start) {        // Repeat the logic from getNextEntityNum.        boolean startPassed = false;        for (Enumeration i = entities.elements(); i.hasMoreElements();) {            final Entity entity = (Entity)i.nextElement();            if (entity.getId() == start) {                startPassed = true;            } else if ( startPassed && turn.isValidEntity(entity, this) &&                        entity.shouldDeploy(getRoundCount()) ) {                return entity.getId();            }        }        return getFirstDeployableEntityNum(turn);    }    public void determineWind() {        String[] dirNames = {"North", "Northeast", "Southeast", "South", "Southwest", "Northwest"};        String[] strNames = {"Calm", "Light", "Moderate", "High"};        if (windDirection == -1) {            // Initial wind direction.  If using level 2 rules, this            //  will be the wind direction for the whole battle.            windDirection = Compute.d6(1)-1;        } else if (getOptions().booleanOption("maxtech_fire")) {            // Wind direction changes on a roll of 1 or 6            switch (Compute.d6()) {            case 1: //rotate clockwise                windDirection = (windDirection + 1) % 6;                break;            case 6: //rotate counter-clockwise                windDirection = (windDirection + 5) % 6;            }        }        if (getOptions().booleanOption("maxtech_fire")) {            if (windStrength == -1) {                // Initial wind strength                switch (Compute.d6()) {                case 1:                    windStrength = 0;                    break;                case 2:                case 3:                    windStrength = 1;                    break;                case 4:                case 5:                    windStrength = 2;                    break;                case 6:                    windStrength = 3;                }            } else {                // Wind strength changes on a roll of 1 or 6                switch (Compute.d6()) {                case 1: //weaker                    if (windStrength > 0)                        windStrength--;                    break;                case 6: //stronger                    if (windStrength < 3)                        windStrength++;

⌨️ 快捷键说明

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