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

📄 gameturn.java

📁 MegaMek is a networked Java clone of BattleTech, a turn-based sci-fi boardgame for 2+ players. Fight
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * MegaMek - * Copyright (C) 2000,2001,2002,2003,2004,2005 Ben Mazur (bmazur@sev.org) * *  This program is free software; you can redistribute it and/or modify it *  under the terms of the GNU General Public License as published by the Free *  Software Foundation; either version 2 of the License, or (at your option) *  any later version. * *  This program is distributed in the hope that it will be useful, but *  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *  for more details. *//* * GameTurn.java * * Created on September 6, 2002, 11:52 AM */package megamek.common;import java.io.Serializable;import java.util.Enumeration;/** * Represents a single turn within a phase of the game, where a specific player * has to declare his/her action.  The default game turn allows a player to * move any entity. * * @author  Ben */public class GameTurn implements Serializable {    private int playerId;        /** Creates a new instance of GameTurn */    public GameTurn(int playerId) {        this.playerId = playerId;    }    public int getPlayerNum() {        return playerId;    }        public void setPlayerNum(int playerId) {        this.playerId = playerId;    }    /**     * Determine if the specified entity is a valid one to use for this turn.     *     * @param   entity the <code>Entity</code> that may take this turn.     * @param   game the <code>IGame</code> this turn belongs to.     * @return  <code>true</code> if the specified entity can take this turn.     *          <code>false</code> if the entity is not valid for this turn.     */    public boolean isValidEntity(Entity entity, IGame game) {        return entity != null            && entity.getOwnerId() == playerId            && entity.isSelectableThisTurn()            //This next bit enforces the "A players Infantry/Protos            // move after that players other units" options.            && !( game.getPhase() == IGame.PHASE_MOVEMENT                  && ( (entity instanceof Infantry &&                        game.getOptions().booleanOption("inf_move_later")) ||                       (entity instanceof Protomech &&                        game.getOptions().booleanOption("protos_move_later")))                  && game.checkForValidNonInfantryAndOrProtomechs(playerId));    }    /**     * Returns true if the player and entity are both valid.     */    public boolean isValid(int playerId, Entity entity, IGame game) {        return playerId == this.playerId && isValidEntity(entity, game);    }        /**     * Returns true if the player is valid.     */    public boolean isValid(int playerId, IGame game) {        return playerId == this.playerId;    }        public String toString() {        return getClass().getName() + " [" + playerId + "]";    }    /**     * A type of game turn that allows only one specific entity to move.     */    public static class SpecificEntityTurn extends GameTurn {        private int entityId;                public SpecificEntityTurn(int playerId, int entityId) {            super(playerId);            this.entityId = entityId;        }                public int getEntityNum() {            return entityId;        }                public void setEntityNum(int entityId) {            this.entityId = entityId;        }                /**         * Returns true if the entity is normally valid and it is the specific         * entity that can move this turn.         */        public boolean isValidEntity(Entity entity, IGame game) {            return super.isValidEntity(entity, game) && entity.getId() == entityId;        }    }    /**     * A type of game turn that allows only one specific entity to      * trigger their Anti-Personell pods against attacking infantry.     */    public static class TriggerAPPodTurn extends SpecificEntityTurn {                public TriggerAPPodTurn(int playerId, int entityId) {            super(playerId, entityId);        }        /**         * Returns true if the entity matches this game turn, even if the         * entity has declared an action.         */        public boolean isValidEntity(Entity entity, IGame game) {            final boolean oldDone = entity.done;            entity.done = false;            final boolean result = super.isValidEntity( entity, game );            entity.done = oldDone;            return result;        }    }    /**     * A type of game turn that allows only one specific entity to      * counterattack a break grapple by original attacker     */    public static class CounterGrappleTurn extends SpecificEntityTurn {                public CounterGrappleTurn(int playerId, int entityId) {            super(playerId, entityId);        }        /**         * Returns true if the entity matches this game turn, even if the         * entity has declared an action.         */        public boolean isValidEntity(Entity entity, IGame game) {            final boolean oldDone = entity.done;            entity.done = false;            final boolean result = super.isValidEntity( entity, game );            entity.done = oldDone;            return result;        }    }    /** The constant to represent Infantry (and Battle Armor) entities. */    public static final int CLASS_INFANTRY      = 1;    /** The constant to represent Protomech entities. */    public static final int CLASS_PROTOMECH     = 2;    /** The constant to represent Tank entities. */    public static final int CLASS_TANK          = 4;    /** The constant to represent Mech entities. */    public static final int CLASS_MECH          = 8;    /** The constant to represent Gun Emplacement entities. */    public static final int CLASS_GUN_EMPLACEMENT   = 16;    /**     * Get the class code for the given entity.     *     * @param   entity the <code>Entity</code> whose class code is needed.     * @return  the <code>int</code> code for the entity's class.     */    public static int getClassCode( Entity entity ) {        int classCode = 0;        if ( entity instanceof Infantry ) {            classCode = GameTurn.CLASS_INFANTRY;        }        else if ( entity instanceof Protomech ) {            classCode = GameTurn.CLASS_PROTOMECH;        }        else if ( entity instanceof Tank ) {            classCode = GameTurn.CLASS_TANK;        }        else if ( entity instanceof Mech ) {            classCode = GameTurn.CLASS_MECH;        }        else if ( entity instanceof GunEmplacement ) {            classCode = GameTurn.CLASS_GUN_EMPLACEMENT;        }        return classCode;    }    /**     * A type of game turn that allows only certain types of units to move.     */    public static class EntityClassTurn extends GameTurn {        private final int mask;        /**         * Only allow entities for the given player which have types in         * the class mask to move.         *         * @param   playerId the <code>int</code> ID of the player         * @param   classMask the <code>int</code> bitmask containing         *          all the valid class types for this move.         */        public EntityClassTurn( int playerId, int classMask ) {

⌨️ 快捷键说明

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