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

📄 game.java

📁 MegaMek is a networked Java clone of BattleTech, a turn-based sci-fi boardgame for 2+ players. Fight
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                }            }            stringWindStrength = strNames[windStrength];        }        stringWindDirection = dirNames[windDirection];    }    public int getWindDirection() {        return windDirection;    }    public String getStringWindDirection() {        return stringWindDirection;    }    public int getWindStrength() {        return windStrength;    }    public String getStringWindStrength() {        return stringWindStrength;    }    /**     * Get the entities for the player.     *     * @param   player - the <code>Player</code> whose entities are required.     * @return  a <code>Vector</code> of <code>Entity</code>s.     */    public Vector getPlayerEntities( Player player ) {        Vector output = new Vector();        for (Enumeration i = entities.elements(); i.hasMoreElements();) {            final Entity entity = (Entity)i.nextElement();            if ( player.equals(entity.getOwner()) ) {                output.addElement( entity );            }        }        return output;    }    /**     * Determines if the indicated entity is stranded on a transport that     * can't move.     * <p/>     * According to <a href="http://www.classicbattletech.com/w3t/showflat.php?Cat=&Board=ask&Number=555466&page=2&view=collapsed&sb=5&o=0&fpart=">     * Randall Bills</a>, the "minimum move" rule allow stranded units to     * dismount at the start of the turn.     *     * @param   entity the <code>Entity</code> that may be stranded     * @return  <code>true</code> if the entity is stranded     *          <code>false</code> otherwise.     */    public boolean isEntityStranded( Entity entity ) {        // Is the entity being transported?        final int transportId = entity.getTransportId();        Entity transport = getEntity( transportId );        if ( Entity.NONE != transportId && null != transport ) {            // Can that transport unload the unit?            if ( transport.isImmobile() || 0 == transport.getWalkMP() ) {                return true;            }        }        return false;    }    /**     * Returns the number of remaining selectable infantry owned by a player.     */    public int getInfantryLeft(int playerId) {        Player player = this.getPlayer( playerId );        int remaining = 0;        for (Enumeration i = entities.elements(); i.hasMoreElements();) {            final Entity entity = (Entity)i.nextElement();            if ( player.equals(entity.getOwner()) &&                 entity.isSelectableThisTurn() &&                 entity instanceof Infantry ) {                remaining++;            }        }        return remaining;    }    /**     * Returns the number of remaining selectable Protomechs owned by a player.     */    public int getProtomechsLeft(int playerId) {        Player player = this.getPlayer( playerId );        int remaining = 0;        for (Enumeration i = entities.elements(); i.hasMoreElements();) {            final Entity entity = (Entity)i.nextElement();            if ( player.equals(entity.getOwner()) &&                 entity.isSelectableThisTurn() &&                 entity instanceof Protomech ) {                remaining++;            }        }        return remaining;    }    /**     * Removes the last, next turn found that the specified entity can move in.     * Used when, say, an entity dies mid-phase.     */    public void removeTurnFor(Entity entity) {        //If the game option "move multiple infantry per mech" is selected,        //then we might not need to remove a turn at all.        //A turn only needs to be removed when going from 4 inf (2 turns) to        //3 inf (1 turn)        if(getOptions().booleanOption("inf_move_multi")                && entity instanceof Infantry                && phase == PHASE_MOVEMENT) {            if((getInfantryLeft(entity.getOwnerId())                     % getOptions().intOption("inf_proto_move_multi"))                    != 1) {                //exception, if the _next_ turn is an infantry turn, remove that                //contrived, but may come up e.g. one inf accidently kills another                if(hasMoreTurns()) {                    GameTurn nextTurn = (GameTurn)turnVector.elementAt(turnIndex + 1);                    if(nextTurn instanceof GameTurn.EntityClassTurn) {                        GameTurn.EntityClassTurn ect = (GameTurn.EntityClassTurn)nextTurn;                        if(ect.isValidClass(GameTurn.CLASS_INFANTRY) &&                                 !ect.isValidClass(~GameTurn.CLASS_INFANTRY)) {                            turnVector.removeElementAt(turnIndex + 1);                        }                    }                }                return;            }        }        //Same thing but for protos        if(getOptions().booleanOption("protos_move_multi")                && entity instanceof Protomech                && phase == PHASE_MOVEMENT) {            if((getProtomechsLeft(entity.getOwnerId())                     % getOptions().intOption("inf_proto_move_multi"))                    != 1) {                //exception, if the _next_ turn is an protomek turn, remove that                //contrived, but may come up e.g. one inf accidently kills another                if(hasMoreTurns()) {                    GameTurn nextTurn = (GameTurn)turnVector.elementAt(turnIndex + 1);                    if(nextTurn instanceof GameTurn.EntityClassTurn) {                        GameTurn.EntityClassTurn ect = (GameTurn.EntityClassTurn)nextTurn;                        if(ect.isValidClass(GameTurn.CLASS_PROTOMECH) &&                                 !ect.isValidClass(~GameTurn.CLASS_PROTOMECH)) {                            turnVector.removeElementAt(turnIndex + 1);                        }                    }                }                return;            }        }        for (int i = turnVector.size() - 1; i >= turnIndex; i--) {            GameTurn turn = (GameTurn)turnVector.elementAt(i);            if (turn.isValidEntity(entity, this)) {                turnVector.removeElementAt(i);                break;            }        }    }    /**     * Check each player for the presence of a Battle Armor squad equipped     * with a Magnetic Clamp.  If one unit is found, update that player's     * units to allow the squad to be transported.     * <p/>     * This method should be called </b>*ONCE*</b> per game, after all units     * for all players have been loaded.     *     * @return  <code>true</code> if a unit was updated, <code>false</code>     *          if no player has a Battle Armor squad equipped with a     *          Magnetic Clamp.     */    public boolean checkForMagneticClamp() {        // Declare local variables.        Player          player = null;        Entity          unit = null;        boolean         result;        Hashtable       playerFlags = null;        String          name = null;        // Assume that we don't need new transporters.        result = false;        // Create a map of flags for the players.        playerFlags = new Hashtable( this.getNoOfPlayers() );        // Walk through the game's entities.        for (Enumeration i = entities.elements(); i.hasMoreElements();) {            // Is the next unit a Battle Armor squad?            unit = (Entity)i.nextElement();            if ( unit instanceof BattleArmor ) {                // Does the unit have a Magnetic Clamp?                for (Mounted equip : unit.getMisc()) {                    name = equip.getType().getInternalName();                    if ( BattleArmor.MAGNETIC_CLAMP.equals( name ) ){                        // The unit's player needs new transporters.                        result = true;                        playerFlags.put( unit.getOwner(), Boolean.TRUE );                        // Stop looking.                        break;                    }                }            } // End unit-is-BattleArmor        } // Handle the next entity.        // Do we need to add any Magnetic Clamp transporters?        if ( result ) {            // Walk through the game's entities again.            for (Enumeration i = entities.elements(); i.hasMoreElements();) {                // Get this unit's player.                unit = (Entity)i.nextElement();                player = unit.getOwner();                // Does this player need updated transporters?                if ( Boolean.TRUE.equals( playerFlags.get(player) ) ) {                    // Add the appropriate transporter to the unit.                    if ( !unit.isOmni() && unit instanceof Mech ) {                        unit.addTransporter( new ClampMountMech() );                    }                    else if ( unit instanceof Tank ) {                        unit.addTransporter( new ClampMountTank() );                    }                }            } // End player-needs-transports        } // Handle the next unit.        // Return the result.        return result;    } // End private boolean checkForMagneticClamp()    /**      * Adds the specified action to the actions list for this phase.      */    public void addAction(EntityAction ea) {        actions.addElement(ea);        processGameEvent(new GameNewActionEvent(this,ea));            }    public void addArtilleryAttack(ArtilleryAttackAction aaa) {        offboardArtilleryAttacks.addElement(aaa);    }    public void removeArtilleryAttack(ArtilleryAttackAction aaa) {        offboardArtilleryAttacks.removeElement(aaa);    }    public Vector getArtilleryVector() {        return offboardArtilleryAttacks;    }    public void setArtilleryVector(Vector v) {        offboardArtilleryAttacks = v;        processGameEvent(new GameBoardChangeEvent(this));    }    public void resetArtilleryAttacks() {        offboardArtilleryAttacks.removeAllElements();    }    public Enumeration getArtilleryAttacks() {        return offboardArtilleryAttacks.elements(); //Fix?    }    public int getArtillerySize() {        return offboardArtilleryAttacks.size();    }    /** Returns an Enumeration of actions scheduled for this phase. */    public Enumeration getActions() {        return actions.elements();    }    /** Resets the actions list. */    public void resetActions() {        actions.removeAllElements();    }    /** Removes all actions by the specified entity */    public void removeActionsFor(int entityId) {        // or rather, only keeps actions NOT by that entity        Vector toKeep = new Vector(actions.size());        for (Enumeration i = actions.elements(); i.hasMoreElements();) {            EntityAction ea = (EntityAction)i.nextElement();            if (ea.getEntityId() != entityId) {                toKeep.addElement(ea);            }        }        this.actions = toKeep;    }        /**     * Remove a specified action     * @param o The action to remove.     */    public void removeAction(Object o) {        actions.removeElement(o);    }    public int actionsSize() {        return actions.size();    }    /** Returns the actions vector.  Do not use to modify the actions;     * I will be angry. >:[  Used for sending all actions to the client.     */    public Vector getActionsVector() {        return actions;    }    public void addInitiativeRerollRequest(Team t) {        initiativeRerollRequests.addElement(t);    }    public void rollInitAndResolveTies() {        if(getOptions().booleanOption("individual_initiative")) {            Vector<TurnOrdered> vRerolls = new Vector<TurnOrdered>();            for(int i=0;i<entities.size();i++) {                Entity e = (Entity)entities.elementAt(i);                if(initiativeRerollRequests.contains(getTeamForPlayer(e.getOwner()))) {                    vRerolls.add(e);                }            }            TurnOrdered.rollInitAndResolveTies(entities, vRerolls);        } else {            TurnOrdered.rollInitAndResolveTies(teams, initiativeRerollRequests);        }        initiativeRerollRequests.removeAllElements();            }    public int getNoOfInitiativeRerollRequests() {        return initiativeRerollRequests.size();    }    /**     * Adds a pending displacement attack to the list for this phase.     */    public void addCharge(AttackAction ea) {        pendingCharges.addElement(ea);        processGameEvent(new GameNewActionEvent(this,ea));                    }    /**     * Returns an Enumeration of displacement attacks scheduled for the end     * of the physical phase.     */    public Enumeration getCharges() {        return pendingCharges.elements();    }    /** Resets the pending charges list. */    public void resetCharges() {        pendingCharges.removeAllElements();    }    /** Returns the charges vector.  Do not modify. >:[ Used for sending all     * charges to the client.     */    public Vector getChargesVector() {        return pendingCharges;    }        /**     * Adds a pending lay minefield action to the list for this phase.     */    public void addLayMinefieldAction(LayMinefieldAction lma) {        pendingLayMinefieldActions.addElement(lma);        processGameEvent(new GameNewActionEvent(this,lma));    }    /**     * Returns an Enumeration of LayMinefieldActions     */    public Enumeration getLayMinefieldActions() {        return pendingLayMinefieldActions.elements();    }    /** Resets t

⌨️ 快捷键说明

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