public virtual void updatePlayers(GameState gameState) { Console.WriteLine("updating lobby..."); if (gameState.isGameInProgress()) { backToMenu = false; //finished = true; } for (int i = 0; i < NUMPLAYERS; i++) { updateHelper(i); } foreach (DropDown dd in dropDowns) dd.setSelected("Open"); foreach (Player p in gameState.getPlayers().Values) { int seat = p.getSeat(); dropDowns[seat].setEnabled(false); dropDowns[seat].setSelected(p.getName()); if (p.getID() == Game1.client.getId()) readyCBs[seat].setEnabled(true); readyCBs[seat].setSelected(p.getReady()); } Console.WriteLine("Update side:" + gameState.getOnlySideA()); if (gameState.getOnlySideA()) { viewSideB = false; sideButton.setVisible(false); } else sideButton.setVisible(true); }
public virtual void stateUpdate(GameState gameState,UpdateType code) { }
public override void stateUpdate(GameState gameState, UpdateType code) { updatePlayers(gameState); }
public void updateResources(GameState gameState) { for (int i = 0; i < NUMRESOURCES; i++) { baseVisuals["east" + i].setString(east.getResourceNum((Resource) i) + ""); baseVisuals["west" + i].setString(west.getResourceNum((Resource)i) + ""); baseVisuals["self" + i].setString(player.getResourceNum((Resource)i) + ""); } foreach (Player p in gameState.getPlayers().Values) { baseVisuals["gear" + p.getSeat()].setString(p.getScoreNum(Score.GEAR).ToString()); baseVisuals["tablet" + p.getSeat()].setString(p.getScoreNum(Score.TABLET).ToString()); baseVisuals["compas" + p.getSeat()].setString(p.getScoreNum(Score.COMPASS).ToString()); baseVisuals["victory" + p.getSeat()].setString(p.getScoreNum(Score.VICTORY_BLUE).ToString()); baseVisuals["army" + p.getSeat()].setString(p.getScoreNum(Score.ARMY).ToString()); seatVisuals[p.getSeat()]["conflict"].setString(p.getScoreNum(Score.CONFLICT).ToString()); if (p.getBoard().getStagesBuilt() > 0) seatVisuals[p.getSeat()]["stages"].setTexture("stage" + p.getBoard().getStagesBuilt() + p.getBoard().getSide().getStageNum()).setVisible(true); } baseVisuals["Age"].setTexture("age" + gameState.getAge()); baseVisuals["discard"].setString(gameState.getDiscards().Count+"");//get actual number of discards }
private void updatePlayers(GameState gameState) { foreach (Player p in gameState.getPlayers().Values) baseVisuals["player" + p.getSeat()].setColor((p.getReady()) ? Color.Green : Color.Gray); baseVisuals["player" + seatViewed].setColor(Color.Orange); }
public void updatePlayed(GameState gameState) { foreach (Player p in gameState.getPlayers().Values) { int played1 = 0; int played2 = 0; int played3 = 0; int played4 = 0; foreach (string cardID in p.getPlayed()) { Card c = CardLibrary.getCard(cardID); Game1.cards[c.getImageId()].setWidth(CARDWIDTH).setHeight(CARDHEIGHT); if (c.colour == CardColour.BROWN || c.colour == CardColour.GRAY) { if (played1 < 5) { Game1.cards[c.getImageId()].setPosition(new Vector2(SEC1WIDTH + MARGIN * 2, MARGIN + (MARGIN + ((int)(CARDHEIGHT * 0.25))) * played1)); played1++; } else if (played2 < 5) { Game1.cards[c.getImageId()].setPosition(new Vector2(SEC1WIDTH + MARGIN * 3 + CARDWIDTH, MARGIN + (MARGIN + ((int)(CARDHEIGHT * 0.25))) * played2)); played2++; } else if (played3 < 5) { Game1.cards[c.getImageId()].setPosition(new Vector2(SEC1WIDTH + MARGIN * 4 + CARDWIDTH * 2, MARGIN + (MARGIN + ((int)(CARDHEIGHT * 0.25))) * played3)); played3++; } else { Game1.cards[c.getImageId()].setPosition(new Vector2(SEC1WIDTH + MARGIN * 5 + CARDWIDTH * 3, MARGIN + (MARGIN + ((int)(CARDHEIGHT * 0.25))) * played4)); played4++; } } else { if (played4 < 5) { Game1.cards[c.getImageId()].setPosition(new Vector2(SEC1WIDTH + MARGIN * 5 + CARDWIDTH * 3, MARGIN + (MARGIN + ((int)(CARDHEIGHT * 0.25))) * played4)); played4++; } else if (played3 < 5) { Game1.cards[c.getImageId()].setPosition(new Vector2(SEC1WIDTH + MARGIN * 4 + CARDWIDTH * 2, MARGIN + (MARGIN + ((int)(CARDHEIGHT * 0.25))) * played3)); played3++; } else if (played2 < 5) { Game1.cards[c.getImageId()].setPosition(new Vector2(SEC1WIDTH + MARGIN * 3 + CARDWIDTH, MARGIN + (MARGIN + ((int)(CARDHEIGHT * 0.25))) * played2)); played2++; } else { Game1.cards[c.getImageId()].setPosition(new Vector2(SEC1WIDTH + MARGIN * 2 + CARDWIDTH, MARGIN + (MARGIN + ((int)(CARDHEIGHT * 0.25))) * played1)); played1++; } } if (!seatVisuals[p.getSeat()].ContainsKey(cardID)) { seatVisuals[p.getSeat()].Add(c.getImageId(), Game1.cards[c.getImageId()].setVisible(true)); } } } }
public void updateLast(GameState gameState) { int n= 1; foreach (Player p in gameState.getPlayers().Values) { lastPlayed["action" + p.getSeat()].setPosition(new Vector2(Game1.WIDTH * ((n - 1) % 4 + 2) / 6 + MARGIN, Game1.HEIGHT * ((int)(n / 5) * 2 + 1) / 6 + LABELHEIGHT + MARGIN * 2)).setWidth(Game1.WIDTH / 6 - MARGIN * 6).setHeight(Game1.HEIGHT / 3 - MARGIN * 3 - LABELHEIGHT); if (p.getLastActions()[0] == ActionType.BUILD_CARD) lastPlayed["action" + p.getSeat()].setTexture(p.getLastCardsPlayed()[0]); else if (p.getLastActions()[0] == ActionType.BUILD_WONDER) lastPlayed["action" + p.getSeat()].setTexture("stage" + p.getBoard().getStagesBuilt() + p.getBoard().getSide().getStageNum()); else { lastPlayed["action" + p.getSeat()].setPosition(new Vector2(Game1.WIDTH * ((n - 1) % 4 + 2) / 6 + MARGIN + (Game1.WIDTH / 6 - MARGIN * 6) / 3, Game1.HEIGHT * ((int)(n / 5) * 2 + 1) / 6 + LABELHEIGHT + MARGIN * 2 + (Game1.HEIGHT / 3 - MARGIN * 3 - LABELHEIGHT)/3)).setWidth(Game1.WIDTH / 12 - MARGIN * 2).setHeight(Game1.HEIGHT / 9 - MARGIN - LABELHEIGHT / 3); lastPlayed["action" + p.getSeat()].setTexture("coin"); } n++; } }
//observer code public override void stateUpdate(GameState gameState, UpdateType code) { Console.WriteLine("UPDATING STATE"); if (!init) { Initialize(); } if (code==UpdateType.HAND_UPDATE) { leftButton.setEnabled(true); showhand = false; updateHands(); updateScroll(); if (gameState.getTurn() != 1 || gameState.getAge() != 1) { updateLast(gameState); showLastTurn = true; } } if (code == UpdateType.PLAYER_UPDATE) { updatePlayed(gameState); updateResources(gameState); updatePlayers(gameState); } if (code == UpdateType.END_UPDATE) { hand.Clear(); //<-- bit of a hack showScore = true; baseVisuals["Scorehead"].setVisible(true); foreach (Player p in gameState.getPlayers().Values) { baseVisuals["name" + p.getSeat()].setVisible(true); baseVisuals["conflict" + p.getSeat()].setString(p.getScoreNum(Score.CONFLICT).ToString()).setVisible(true); baseVisuals["coin" + p.getSeat()].setString(p.getScoreNum(Score.COIN).ToString()).setVisible(true); baseVisuals["stages" + p.getSeat()].setString(p.getScoreNum(Score.STAGES).ToString()).setVisible(true); baseVisuals["blue" + p.getSeat()].setString(p.getScoreNum(Score.VICTORY_BLUE).ToString()).setVisible(true); baseVisuals["commerce" + p.getSeat()].setString(p.getScoreNum(Score.COMMERCE).ToString()).setVisible(true); baseVisuals["guild" + p.getSeat()].setString(p.getScoreNum(Score.GUILD).ToString()).setVisible(true); baseVisuals["science" + p.getSeat()].setString(p.getScoreNum(Score.SCIENCE).ToString()).setVisible(true); baseVisuals["sum" + p.getSeat()].setString(p.getScoreNum(Score.VICTORY).ToString()).setVisible(true); } quit.setVisible(true); } }
public static void ApplyEndGameEffect(GameState gameState) { int numPlayers = gameState.getPlayers().Count(); foreach (KeyValuePair<long, Player> player in gameState.getPlayers()) { Player curr = player.Value; int position = curr.getSeat(); Player east = null; Player west = null; int schoiceCount = 0; // Setting up the east and west neighbors foreach (KeyValuePair<long, Player> neighbor in gameState.getPlayers()) { if ((position + 1) % numPlayers == neighbor.Value.getSeat()) east = neighbor.Value; if ((position - 1) == neighbor.Value.getSeat() || (position == 0 && neighbor.Value.getSeat() == numPlayers - 1)) west = neighbor.Value; } // Check Wonder board effects first // This way if a player has guildCopy, it will take into account that the scientist guild // card is added into the players played hand and counted for (int i = 0; i < curr.getBoard().getStagesBuilt(); i++) { foreach (Effect e in curr.getBoard().getSide().getStageEffects(i)) { if (e.type.Equals(Effect.TypeType.SCHOICE)) schoiceCount += 1; // Loop through Wonder Effects for the players // GUILD COPY - not finished else if (e.type.Equals(Effect.TypeType.GUILD)) { CopyGuild(curr, east, west); } } // Foreach loop through Wondestage effects } // For loop through the stages // Looping through the player's played cards foreach (string cardID in curr.getPlayed()) { Card c = CardLibrary.getCard(cardID); // Looping through the effects of each Card for End Game purposes foreach (Effect e in c.effects) { // Victory Points if (e.type.Equals(Effect.TypeType.VICTORY)) { // FROM: NEIGHBORS // and BASIS: CardColour, Wonderstages, Defeat if (e.from != Effect.FromType.NONE && e.from.Equals(Effect.FromType.NEIGHBOURS)) { // Apply victory points awarded for each // Wonderstage neigboring cities own if (e.basis.Equals(Effect.BasisType.WONDER)) AddVictoryAllWonders(curr, east, west); //Victory points given per neighbor's conlfict token else if (e.basis.Equals(Effect.BasisType.DEFEAT)) AddVictoryNeighboursConflict(curr, east, west); // Victory points awarded per certain structure built by neighbours else AddVictoryNeighboursColour(curr, east, west, cardType[e.basis], e.amount); } // FROM: PLAYER // BASIS: CardColour, Wonderstages, else if (e.from != Effect.FromType.NONE && e.from.Equals(Effect.FromType.PLAYER)) { if (e.basis.Equals(Effect.BasisType.WONDER)) AddVictoryWonder(curr); else AddVictoryColour(curr, cardType[e.basis], e.amount); } // FROM: ALL // BASIS: Wonderstages else if (e.from != Effect.FromType.NONE && e.from.Equals(Effect.FromType.ALL)) AddVictoryAllWonders(curr, east, west); } // End Victory Points // SCIENCE CHOICE else if (e.type.Equals(Effect.TypeType.SCHOICE)) schoiceCount += 1; } // End Effect Loop for Cards } // End Current Player's Card Loop for (int i = 0; i < curr.getBoard().getStagesBuilt(); i++) { foreach (Effect e in curr.getBoard().getSide().getStageEffects(i)) { if (e.type.Equals(Effect.TypeType.VICTORY)) curr.addScore(Score.STAGES, e.amount); } } // Max Function, will add onto the max science value AddScienceChoice(curr, schoiceCount); curr.addScore(Score.VICTORY, CalculateScience(curr.getScoreNum(Score.GEAR),curr.getScoreNum(Score.COMPASS),curr.getScoreNum(Score.TABLET))); curr.addScore(Score.SCIENCE, CalculateScience(curr.getScoreNum(Score.GEAR), curr.getScoreNum(Score.COMPASS), curr.getScoreNum(Score.TABLET))); curr.addScore(Score.VICTORY, curr.getScoreNum(Score.CONFLICT)); //curr.addScore(Score.VICTORY, (int)curr.getResourceNum(Resource.COIN) / 3); //curr.addScore(Score.COIN, (int)curr.getResourceNum(Resource.COIN) / 3); curr.addScore(Score.VICTORY, GetTreasuryScore(curr)); curr.addScore(Score.COIN, GetTreasuryScore(curr)); curr.addScore(Score.COMMERCE, GetCommercialScore(curr)); curr.addScore(Score.GUILD, GetGuildsScore(curr,east,west)); } // End Player Loop }
// Effects to be applied during the last turn of every age // Dependant on Wonders public static void ApplyEndAge(GameState gameState) { foreach (KeyValuePair<long, Player> player in gameState.getPlayers()) { Player curr = player.Value; foreach (Effect effect in curr.getBoard().getSide().getStageEffects(gameState.getAge())) { if (effect.type.Equals(Effect.TypeType.LASTCARD)) { } } // End Loop for Wonder Effects } // End Player Loop }