use of soc.game.SOCGame in project JSettlers2 by jdmonin.
the class SOCDisplaylessPlayerClient method handleMOVEPIECE.
/**
* Handle moving a piece (a ship) around on the board.
* @since 2.0.00
*/
protected void handleMOVEPIECE(SOCMovePiece mes) {
final String gaName = mes.getGame();
SOCGame ga = games.get(gaName);
if (ga == null)
// Not one of our games
return;
SOCShip sh = new SOCShip(ga.getPlayer(mes.getPlayerNumber()), mes.getFromCoord(), null);
ga.moveShip(sh, mes.getToCoord());
}
use of soc.game.SOCGame in project JSettlers2 by jdmonin.
the class SOCDisplaylessPlayerClient method handleREMOVEPIECE.
/**
* A player's piece (a ship) has been removed from the board. Updates game state.
*<P>
* Currently, only ships can be removed, in game scenario {@code _SC_PIRI}.
* Other {@code pieceType}s are ignored.
* @since 2.0.00
*/
protected void handleREMOVEPIECE(SOCRemovePiece mes) {
final String gaName = mes.getGame();
SOCGame ga = games.get(gaName);
if (ga == null)
// Not one of our games
return;
SOCPlayer player = ga.getPlayer(mes.getParam1());
final int pieceType = mes.getParam2();
final int pieceCoordinate = mes.getParam3();
switch(pieceType) {
case SOCPlayingPiece.SHIP:
ga.removeShip(new SOCShip(player, pieceCoordinate, null));
break;
default:
System.err.println("Displayless.updateAtPieceRemoved called for un-handled type " + pieceType);
}
}
use of soc.game.SOCGame in project JSettlers2 by jdmonin.
the class SOCDisplaylessPlayerClient method handleDEVCARDACTION.
/**
* handle the "development card action" message
* @param isPractice Is the server local, or remote? Client can be connected
* only to local, or remote.
* @param mes the message
*/
protected void handleDEVCARDACTION(final boolean isPractice, final SOCDevCardAction mes) {
SOCGame ga = games.get(mes.getGame());
if (ga != null) {
SOCPlayer player = ga.getPlayer(mes.getPlayerNumber());
int ctype = mes.getCardType();
if ((!isPractice) && (sVersion < SOCDevCardConstants.VERSION_FOR_NEW_TYPES)) {
if (ctype == SOCDevCardConstants.KNIGHT_FOR_VERS_1_X)
ctype = SOCDevCardConstants.KNIGHT;
else if (ctype == SOCDevCardConstants.UNKNOWN_FOR_VERS_1_X)
ctype = SOCDevCardConstants.UNKNOWN;
}
switch(mes.getAction()) {
case SOCDevCardAction.DRAW:
player.getInventory().addDevCard(1, SOCInventory.NEW, ctype);
break;
case SOCDevCardAction.PLAY:
player.getInventory().removeDevCard(SOCInventory.OLD, ctype);
break;
case SOCDevCardAction.ADD_OLD:
player.getInventory().addDevCard(1, SOCInventory.OLD, ctype);
break;
case SOCDevCardAction.ADD_NEW:
player.getInventory().addDevCard(1, SOCInventory.NEW, ctype);
break;
}
}
}
use of soc.game.SOCGame in project JSettlers2 by jdmonin.
the class SOCDisplaylessPlayerClient method handleSIMPLEACTION.
/**
* Update any game data from "simple action" announcements from the server.
* Currently ignores them except for:
*<UL>
* <LI> {@link SOCSimpleAction#TRADE_PORT_REMOVED TRADE_PORT_REMOVED}:
* Calls {@link SOCGame#removePort(SOCPlayer, int)}
*</UL>
*
* @param games Games the client is playing, for method reuse by SOCPlayerClient
* @param mes the message
* @since 1.1.19
*/
public static void handleSIMPLEACTION(final Map<String, SOCGame> games, final SOCSimpleAction mes) {
final String gaName = mes.getGame();
SOCGame ga = games.get(gaName);
if (ga == null)
// Not one of our games
return;
final int atype = mes.getActionType();
switch(atype) {
case SOCSimpleAction.BOARD_EDGE_SET_SPECIAL:
{
final SOCBoard bd = ga.getBoard();
if (bd instanceof SOCBoardLarge)
((SOCBoardLarge) bd).setSpecialEdge(mes.getValue1(), mes.getValue2());
}
break;
case SOCSimpleAction.TRADE_PORT_REMOVED:
if (ga.hasSeaBoard)
ga.removePort(null, mes.getValue1());
break;
case SOCSimpleAction.DEVCARD_BOUGHT:
case SOCSimpleAction.RSRC_TYPE_MONOPOLIZED:
case SOCSimpleAction.SC_PIRI_FORT_ATTACK_RESULT:
// game data updates are sent in preceding or following messages, can ignore this one
break;
default:
// ignore unknown types
// Since the bots and server are almost always the same version, this
// shouldn't often occur: print for debugging.
System.err.println("handleSIMPLEACTION: Unknown type ignored: " + atype + " in game " + gaName);
}
}
use of soc.game.SOCGame in project JSettlers2 by jdmonin.
the class SOCDisplaylessPlayerClient method handleSTARTGAME.
/**
* handle the "start game" message
* @param games The hashtable of client's {@link SOCGame}s; key = game name
* @param mes the message
*/
protected static void handleSTARTGAME(Hashtable<String, SOCGame> games, SOCStartGame mes) {
final SOCGame ga = games.get(mes.getGame());
if (ga == null)
return;
handleGAMESTATE(ga, mes.getGameState());
// Look for human players to determine isBotsOnly in game's local copy
boolean isBotsOnly = true;
for (int pn = 0; pn < ga.maxPlayers; ++pn) {
if (!(ga.isSeatVacant(pn) || ga.getPlayer(pn).isRobot())) {
isBotsOnly = false;
break;
}
}
ga.isBotsOnly = isBotsOnly;
}
Aggregations