/// <summary> /// Determines the winner of the TradeRoute /// </summary> /// <param name="game"></param> /// <returns></returns> public GamePlayer Winner(XmlGame game, GamePlayer player) { int playerCount = this.Where(rn => rn.PlayerID == player.XmlPlayer.ID).Count(); var opponentIDs = this.Where(rn => rn.PlayerID !=player.XmlPlayer.ID); int opponentID=0; if (opponentIDs.Count() >0) opponentID=opponentIDs.First().PlayerID; if (opponentID != 0) { int ships = GetShipCount(player.XmlPlayer.ID); int opponentShips=GetShipCount(opponentID); if (ships > opponentShips) return player; if (ships < opponentShips) return game.GetPlayer(opponentID); else // we have equal amount of ships, decide on earliest route { return null; //TODO: lookup the trade route } } else // no opponents, return current player { return player; } }
/// <summary> /// Constructs a buildpointvisual using a list of hexsides of a player /// </summary> /// <param name="board"></param> /// <param name="places"></param> public BuildPlaces(BoardVisual board, GamePlayer player) { List<HexPoint> possiblePlaces = player.GetTownBuildPlaces(board.Game, board.Board); foreach (HexPoint pointToAdd in possiblePlaces) { Point2D point2 = board.CalculatePosition(pointToAdd); BuildPointVisual bpv = new BuildPointVisual(point2, pointToAdd); Children.Add(bpv); } }
private Image CreateImage(GamePlayer player) { Image image = new Image() { Source = (ImageSource)Core.Instance.Icons["IconTimber"], Margin = new Thickness(0, 10, 0, 0), Tag=player }; image.MouseUp += new MouseButtonEventHandler(image_MouseUp); return image; }
void image_MouseUp(object sender, MouseButtonEventArgs e) { if (_ActiveImage != null) { _ActiveImage.Margin = new Thickness(0, 10, 0, 0); } _ActiveImage = (Image)sender; _ActiveImage.Margin = new Thickness(0, 0, 0, 0); _Victim = (GamePlayer)_ActiveImage.Tag; btnOK.IsEnabled = true; }
private void OnLargestArmyChanged(GamePlayer player) { if (_LargestArmyChanged != null) { _LargestArmyChanged(player); } }
private void OnLongestRouteChanged(GamePlayer player, Route newRoute) { if (_LongestRouteChanged != null) { _LongestRouteChanged(player, newRoute); } }
/// <summary> /// Recalculates every route in case of a blokage /// </summary> /// <param name="town"></param> /// <param name="player"></param> public void CalculateLongestRoad(HexPoint town, GamePlayer player) { Route current = LongestRoute; // When we have a current route, check if the new town is part of it if (current != null) { // But only when the player building the town is other then the player owning // the current route if (!player.Equals(LongestRouteOwner)) { // Create a list of hexpoints in current route List<HexPoint> routePoints = new List<HexPoint>(); // Put all points into the list foreach (RouteNode node in current) { if (!routePoints.Contains(node.GetNeighbourPoints()[0])) routePoints.Add(node.GetNeighbourPoints()[0]); if (!routePoints.Contains(node.GetNeighbourPoints()[1])) routePoints.Add(node.GetNeighbourPoints()[1]); } // Check if the town is placed on a hexpoint in the route if (routePoints.Contains(town)) { // We have a winner! Nice play. This means given town which is built blocks // We should iterate over all players, calculating their longest routes. // If current keeper of the longest route has a new route with length // equalling length of another player, current keeper keeps his LR. // However, when two other players both have longest route, no one gets // the route. // TODO: make static function call of CalculateALongestRoute Route phony = new Route(); // Get us some nice new dictionairy to store the calculated routes Dictionary<GamePlayer, Route> playersRoutes = new Dictionary<GamePlayer, Route>(); // Fill the dictionairy with new routes foreach (GamePlayer p in _Players) playersRoutes.Add(p, phony.CalculateALongestRoute(p, this)); // Sweet! Now let's see who is the winner of the routecontest // First get the longest route of current keeper of LR Route currentWinnerRoute = playersRoutes[LongestRouteOwner]; // Get the length of the longest route(s) int newWinnerLength = playersRoutes.Max(kvp => kvp.Value.Count); Route newRoute = null; if (currentWinnerRoute.Count == newWinnerLength) { // Current keeper of longest route has a new route with the maximum length. // Therefore, he stays the keeper of the longest route newRoute = currentWinnerRoute; } else { // Some other player(s) have a longer route then the previous route, and still longer // then the longest route of the keeper of the previous route. // Determine if we have a single player having so. If a single player is found, // declare him the winner. When multiple players are found, no one gets // declared winner. IEnumerable<KeyValuePair<GamePlayer, Route>> winners = playersRoutes.Where(kvp => kvp.Value.Count == newWinnerLength); // We have more then one new winners. No one gets LR. if (winners.Count() > 1) { newRoute = null; } // Only one new winner if (winners.Count() == 1) { newRoute = winners.First().Value; } // Old player lost route, no players with routes > 4 if (winners.Count() == 0) { newRoute = null; } } } } } else { CalculateLongestRoad(player); } }
/// <summary> /// checks if player has a ship or road connecting to the point /// </summary> /// <param name="location"></param> /// <returns></returns> public bool HasRoadShipAtPoint(HexPoint location, GamePlayer player) { foreach (HexSide side in location.GetNeighbourSides) { if (player.Roads.Contains(side)) return true; if (player.Ships.Contains(side)) return true; } //no ship or road found return false; }
/// <summary> /// Checks current situation for a new LR owner /// Should be called whenever a ship, road or town is added, moved or removed /// MoveShip: old/new ship can be part of longer route /// BuildRoad/BuildShip: LR can be extended /// BuildTown: road/ship may be connected (previously blown up town) /// new town may block other players' LR /// VolcanoExplosion: blown up town/city may link two parts (ship+road) /// </summary> public void CalculateLongestRoad(GamePlayer player) { Route possibleNewLR = new Route().CalculateALongestRoute(player, this); if (possibleNewLR != null) { if (!player.HasLongestRoute) { // Claim the route as first when route is 5 long and not claimed yet if (possibleNewLR.Count > 4 && LongestRoute == null) { OnLongestRouteChanged(player, possibleNewLR); } } else { if (possibleNewLR.Count > player.LongestRoute.Count) { OnLongestRouteChanged(player, possibleNewLR); } } } }
public void CalculateLargestArmy(GamePlayer soldierPlayingPlayer) { // Get current keeper of LA GamePlayer currentMightyPlayer = _Players.Where(p => p.HasLargestArmy == true).SingleOrDefault(); // Check if there is a current winner if ((currentMightyPlayer != null && // If we are already winner, no changes happens !currentMightyPlayer.Equals(soldierPlayingPlayer) && // New winner must have more soldiers then current winner soldierPlayingPlayer.PlayedSoldierCount > currentMightyPlayer.PlayedSoldierCount) || // Becoming first to get 3 devs also declares winner (soldierPlayingPlayer.PlayedSoldierCount > 2)) { OnLargestArmyChanged(soldierPlayingPlayer); } }
void _Game_LongestRouteChanged(GamePlayer player, Route newRoute) { ShowLongestRoute(); }
void _Game_LongestRouteChanged(GamePlayer player, Route newRoute) { LongestRouteAchievedAction newLongestRoute = new LongestRouteAchievedAction() { GamePlayer = player, Route = newRoute }; newLongestRoute.PerformTurnAction(_Game); _CallBack.Receive(newLongestRoute); }
void _Game_LargestArmyChanged(GamePlayer player) { LargestArmyAchievedAction newLargestArmy = new LargestArmyAchievedAction() { GamePlayer = player }; newLargestArmy.PerformTurnAction(_Game); _CallBack.Receive(newLargestArmy); }