public static TotemLocation GetLocationOnBoard(Player player)
 {
     var location = GetMidpointOf(player.Location.Index);
       var totemLocation = new TotemLocation(location.OffsetFromLeft, location.OffsetFromTop, player.Index, player.Location.Index);
       var adjustedPoint = AdjustPointToTopLeftOfTotem(totemLocation);
       var finalPoint = ShiftForPlayerIndex(adjustedPoint);
       return finalPoint;
 }
Example #2
0
 private static PlayerStatusViewModel Convert(Player player)
 {
     var vm = new PlayerStatusViewModel();
       vm.Name = player.PlayerName;
       vm.PlayerNumber = player.Index;
       vm.Icon = player.IsHuman ? "human_player.png" : "robot_scum.png";
       vm.TotemIcon = GetIconFor(player.Totem);
       vm.Cash = CashHelper.FormatAsCash(player.Cash);
       vm.Holdings = Convert(player.Holdings);
       var coordinates = TokenCoordinatesHelper.GetLocationOnBoard(player);
       vm.OffsetFromLeft = coordinates.OffsetFromLeft.ToString();
       vm.OffsetFromTop = coordinates.OffsetFromTop.ToString();
       return vm;
 }
Example #3
0
 protected bool Equals(Player other)
 {
     return Index == other.Index;
 }
Example #4
0
 public void PayRentTo(Player propertyOwner)
 {
     var rent = Location.Property.Rent;
       Cash -= rent;
       propertyOwner.ReceiveRent(rent);
 }
Example #5
0
        private bool CanBuyProperty(Player player)
        {
            if (!player.Location.HasAProperty)
            return false;

              var someoneOwnsThisProperty = Players.SelectMany(x => x.Holdings).Any(x => Equals(x, player.Location.Property));
              if (someoneOwnsThisProperty)
            return false;

              return player.CanAffordProperty();
        }
Example #6
0
        private void RollForPlayer(Player player)
        {
            const int boardSize = 40;
              int newLocation = player.Location.Index + Dice.Roll();

              if (newLocation > boardSize)
              {
            player.PassGo();
              }
              else if (newLocation == boardSize)
              {
            player.PassesGoOnNextRoll = true;
              }
              else if (player.PassesGoOnNextRoll)
              {
            player.PassesGoOnNextRoll = false;
            player.PassGo();
              }

              newLocation %= boardSize;
              player.Location = Locations.All[newLocation];

              DoRentTransaction(player);
        }
Example #7
0
 private IEnumerable<Player> GetOpponents(Player player)
 {
     return Players.Where(x => !Equals(x, player));
 }
Example #8
0
        private void DoRentTransaction(Player player)
        {
            if (!player.Location.HasAProperty)
            return;

              //I hate using reference equality but I'll do it here for player == player and property == property
              var allOtherPlayers = GetOpponents(player);
              var otherPlayersProperty = allOtherPlayers.SelectMany(x => x.Holdings);
              var matchingProperties = otherPlayersProperty.Where(x => Equals(x, player.Location.Property)).ToList();
              if (!matchingProperties.Any())
            return;

              var matchingProperty = matchingProperties.First();
              var propertyOwner = Players.Where(x => x.Holdings.Any(y=>y.Equals(matchingProperty))).First();

              player.PayRentTo(propertyOwner);
        }