当前位置: 首页>>代码示例>>Java>>正文


Java SetCurrentPlayerMessage类代码示例

本文整理汇总了Java中net.sf.freecol.common.networking.SetCurrentPlayerMessage的典型用法代码示例。如果您正苦于以下问题:Java SetCurrentPlayerMessage类的具体用法?Java SetCurrentPlayerMessage怎么用?Java SetCurrentPlayerMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SetCurrentPlayerMessage类属于net.sf.freecol.common.networking包,在下文中一共展示了SetCurrentPlayerMessage类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: enterRevengeMode

import net.sf.freecol.common.networking.SetCurrentPlayerMessage; //导入依赖的package包/类
/**
 * Enters revenge mode against those evil AIs.
 *
 * @param serverPlayer The {@code ServerPlayer} entering revenge mode.
 * @return A {@code ChangeSet} encapsulating this action.
 */
public ChangeSet enterRevengeMode(ServerPlayer serverPlayer) {
    if (!getFreeColServer().getSinglePlayer()) {
        return serverPlayer.clientError("Can not enter revenge mode,"
            + " as this is not a single player game.");
    }
    Game game = getGame();
    List<UnitType> undeads = game.getSpecification()
        .getUnitTypesWithAbility(Ability.UNDEAD);
    List<UnitType> navalUnits = new ArrayList<>();
    List<UnitType> landUnits = new ArrayList<>();
    for (UnitType undead : undeads) {
        if (undead.hasAbility(Ability.NAVAL_UNIT)) {
            navalUnits.add(undead);
        } else if (undead.hasAbility(Ability.MULTIPLE_ATTACKS)) {
            landUnits.add(undead);
        }
    }
    if (navalUnits.isEmpty() || landUnits.isEmpty()) {
        return serverPlayer.clientError("Can not enter revenge mode,"
            + " because we can not find the undead units.");
    }

    ChangeSet cs = new ChangeSet();
    UnitType navalType = getRandomMember(logger, "Choose undead navy",
                                         navalUnits, random);
    Tile start = serverPlayer.getEntryTile()
        .getSafeTile(serverPlayer, random);
    Unit theFlyingDutchman
        = new ServerUnit(game, start, serverPlayer,
                         navalType);//-vis(serverPlayer)
    UnitType landType = getRandomMember(logger, "Choose undead army",
                                        landUnits, random);
    new ServerUnit(game, theFlyingDutchman, serverPlayer, landType);//-vis
    serverPlayer.setDead(false);
    serverPlayer.changePlayerType(PlayerType.UNDEAD);
    serverPlayer.invalidateCanSeeTiles();//+vis(serverPlayer)

    // No one likes the undead.
    for (Player p : transform(game.getLivePlayers(serverPlayer),
                              p2 -> serverPlayer.hasContacted(p2))) {
        serverPlayer.csChangeStance(Stance.WAR, (ServerPlayer)p, true, cs);
    }

    // Revenge begins
    game.setCurrentPlayer(serverPlayer);
    cs.add(See.all(), new SetCurrentPlayerMessage(serverPlayer));

    // Others can tell something has happened to the player,
    // and possibly see the units.
    cs.add(See.all(), serverPlayer);
    cs.add(See.perhaps(), start);
    getGame().sendToOthers(serverPlayer, cs);
    return cs;
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:61,代码来源:InGameController.java


注:本文中的net.sf.freecol.common.networking.SetCurrentPlayerMessage类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。