Adding player tokens on sites.

This commit is contained in:
marcins78@gmail.com
2011-09-16 10:36:03 +00:00
parent 1d51c1d67f
commit 10cc7571f6
7 changed files with 67 additions and 9 deletions

View File

@@ -36,4 +36,6 @@ public interface GameStateListener {
public void removeTokens(PhysicalCard card, Token token, int count); public void removeTokens(PhysicalCard card, Token token, int count);
public void sendMessage(String message); public void sendMessage(String message);
public void setSite(PhysicalCard card);
} }

View File

@@ -280,12 +280,17 @@ public class GameState {
public void addCardToZone(PhysicalCard card, Zone zone) { public void addCardToZone(PhysicalCard card, Zone zone) {
getZoneCards(card.getOwner(), card.getBlueprint().getCardType(), zone).add((PhysicalCardImpl) card); getZoneCards(card.getOwner(), card.getBlueprint().getCardType(), zone).add((PhysicalCardImpl) card);
((PhysicalCardImpl) card).setZone(zone); ((PhysicalCardImpl) card).setZone(zone);
if (isZonePublic(zone)) if (zone == Zone.ADVENTURE_PATH) {
for (GameStateListener listener : getAllGameStateListeners()) for (GameStateListener listener : getAllGameStateListeners())
listener.cardCreated(card); listener.setSite(card);
else if (isZonePrivate(zone)) } else {
for (GameStateListener listener : getPrivateGameStateListeners(card)) if (isZonePublic(zone))
listener.cardCreated(card); for (GameStateListener listener : getAllGameStateListeners())
listener.cardCreated(card);
else if (isZonePrivate(zone))
for (GameStateListener listener : getPrivateGameStateListeners(card))
listener.cardCreated(card);
}
} }
private void removeAllTokens(PhysicalCard card) { private void removeAllTokens(PhysicalCard card) {

View File

@@ -104,6 +104,11 @@ public class GatheringParticipantCommunicationChannel implements GameStateListen
_events.add(new GameEvent(MESSAGE).message(message)); _events.add(new GameEvent(MESSAGE).message(message));
} }
@Override
public void setSite(PhysicalCard card) {
_events.add(new GameEvent(PUT_CARD_IN_PLAY).card(card).index(card.getBlueprint().getSiteNumber()));
}
public List<GameEvent> consumeGameEvents() { public List<GameEvent> consumeGameEvents() {
List<GameEvent> result = _events; List<GameEvent> result = _events;
_events = new LinkedList<GameEvent>(); _events = new LinkedList<GameEvent>();

View File

@@ -8,6 +8,7 @@ var GempLotrGameUI = Class.extend({
selfPlayerId: null, selfPlayerId: null,
currentPlayerId: null, currentPlayerId: null,
allPlayerIds: null, allPlayerIds: null,
playerPositions: null,
cardActionDialog: null, cardActionDialog: null,
smallDialog: null, smallDialog: null,
gameStateElem: null, gameStateElem: null,
@@ -395,6 +396,8 @@ var GempLotrGameUI = Class.extend({
this.addTokens(gameEvent); this.addTokens(gameEvent);
} else if (eventType == "REMOVE_TOKENS") { } else if (eventType == "REMOVE_TOKENS") {
this.removeTokens(gameEvent); this.removeTokens(gameEvent);
} else if (eventType == "PLAYER_POSITION") {
this.playerPosition(gameEvent);
} else if (eventType == "MESSAGE") { } else if (eventType == "MESSAGE") {
this.message(gameEvent); this.message(gameEvent);
} else if (eventType == "WARNING") { } else if (eventType == "WARNING") {
@@ -438,6 +441,21 @@ var GempLotrGameUI = Class.extend({
alert("There was a problem during communication with server"); alert("There was a problem during communication with server");
}, },
playerPosition: function(element) {
var participantId = element.getAttribute("participantId");
var position = element.getAttribute("index");
if (this.playerPositions == null)
this.playerPositions = new Array();
var index = -1;
for (var i = 0; i < this.allPlayerIds.length; i++)
if (this.allPlayerIds[i] == participantId)
this.playerPositions[i] = position;
this.advPathGroup.setPositions(this.playerPositions);
},
addTokens: function(element) { addTokens: function(element) {
var cardId = element.getAttribute("cardId"); var cardId = element.getAttribute("cardId");
var zone = element.getAttribute("zone"); var zone = element.getAttribute("zone");
@@ -540,7 +558,11 @@ var GempLotrGameUI = Class.extend({
// TODO finish off the other zones (DISCARD, DEAD) // TODO finish off the other zones (DISCARD, DEAD)
if (zone != "DISCARD" && zone != "DEAD") { if (zone != "DISCARD" && zone != "DEAD") {
var card = new Card(blueprintId, zone, cardId, participantId); var card;
if (zone == "ADVENTURE_PATH")
card = new Card(blueprintId, zone, cardId, participantId, element.getAttribute("index"));
else
card = new Card(blueprintId, zone, cardId, participantId);
var cardDiv = this.createCardDiv(card); var cardDiv = this.createCardDiv(card);
$("#main").append(cardDiv); $("#main").append(cardDiv);

View File

@@ -71,6 +71,8 @@ var CardGroup = Class.extend({
}); });
var AdvPathCardGroup = CardGroup.extend({ var AdvPathCardGroup = CardGroup.extend({
positions: null,
init: function(container) { init: function(container) {
this._super(container, this._super(container,
function(card) { function(card) {
@@ -78,6 +80,10 @@ var AdvPathCardGroup = CardGroup.extend({
}); });
}, },
setPositions: function(positions) {
this.positions = positions;
},
layoutCards: function() { layoutCards: function() {
var cardsToLayout = new Array(); var cardsToLayout = new Array();
var that = this; var that = this;
@@ -88,6 +94,12 @@ var AdvPathCardGroup = CardGroup.extend({
} }
}); });
cardsToLayout.sort(
function(first, second) {
return (first.data("card").siteNumber - second.data("card").siteNumber);
}
);
var cardCount = cardsToLayout.length; var cardCount = cardsToLayout.length;
var totalHeight = 0; var totalHeight = 0;
@@ -103,6 +115,12 @@ var AdvPathCardGroup = CardGroup.extend({
var cardElem = cardsToLayout[cardId]; var cardElem = cardsToLayout[cardId];
var cardData = cardsToLayout[cardId].data("card"); var cardData = cardsToLayout[cardId].data("card");
var cardHeight = (cardElem.data("card").getHeightForWidth(this.width)); var cardHeight = (cardElem.data("card").getHeightForWidth(this.width));
cardData.tokens = {};
for (var i = 0; this.positions.length; i++)
if (this.positions[i] == cardData.siteNumber)
cardData.tokens["" + (i + 1)] = 1;
this.layoutCard(cardElem, x, y, this.width, cardHeight, index); this.layoutCard(cardElem, x, y, this.width, cardHeight, index);
for (var i = 0; i < cardData.attachedCards.length; i++) { for (var i = 0; i < cardData.attachedCards.length; i++) {

View File

@@ -8,13 +8,16 @@ var Card = Class.extend({
zone: null, zone: null,
cardId: null, cardId: null,
owner: null, owner: null,
siteNumber: null,
attachedCards: null, attachedCards: null,
init: function(blueprintId, zone, cardId, owner) { init: function(blueprintId, zone, cardId, owner, siteNumber) {
this.blueprintId = blueprintId; this.blueprintId = blueprintId;
this.zone = zone; this.zone = zone;
this.cardId = cardId; this.cardId = cardId;
this.owner = owner; this.owner = owner;
if (siteNumber)
this.siteNumber = parseInt(siteNumber);
this.attachedCards = new Array(); this.attachedCards = new Array();
if (blueprintId == "rules") { if (blueprintId == "rules") {
this.imageUrl = "/gemp-lotr/images/rules.png"; this.imageUrl = "/gemp-lotr/images/rules.png";

View File

@@ -1,11 +1,13 @@
TO DO: TO DO:
Before release:
15. Add join game screen, where players can choose to play and get paired automatically when a pair becomes available. 15. Add join game screen, where players can choose to play and get paired automatically when a pair becomes available.
18. Add display of site where player is on adventure path. 18. Add display of site where player is on adventure path.
21. Scale wounds, burdens, other tokens with the card size. 21. Scale wounds, burdens, other tokens with the card size.
22. If skirmish is in progress, the total strength of each side should be displayed. 22. If skirmish is in progress, the total strength of each side should be displayed.
16. Add an option to view an ongoing game. 20. Display "chess-clock" for each player.
20. Display clock. Next priority:
16. Add an option to view an ongoing game.
13. Add dead/discard pile displays. 13. Add dead/discard pile displays.
14. Add hand/deck card count displays. 14. Add hand/deck card count displays.
19. Add filtering cards to deck-builder. 19. Add filtering cards to deck-builder.
@@ -14,6 +16,7 @@ TO DO:
23. Add ghost cards attached to cards they are affecting in case of things (non-possessions) affecting only one card 23. Add ghost cards attached to cards they are affecting in case of things (non-possessions) affecting only one card
(like skirmish strength bonuses, etc) (like skirmish strength bonuses, etc)
Optional:
4. Modify the Blueprint hierarchy to return possible return objects (PlayEventAction), TriggeredAction, etc. Use 4. Modify the Blueprint hierarchy to return possible return objects (PlayEventAction), TriggeredAction, etc. Use
final methods were possible to avoid implementation errors on new cards added. final methods were possible to avoid implementation errors on new cards added.
10. Add active/all cards switch to the user interface. 10. Add active/all cards switch to the user interface.