Example #1
0
 public void CheckForWinner()
 {
     if (Building.TotalValue > 0)
     {
         return;
     }
     string winnerId = this.PlayerScore.OrderByDescending(x => x.Value).Select(x => x.Key).FirstOrDefault();
     if (!string.IsNullOrEmpty(winnerId))
     {
         Winner = GetLocalPlayer(winnerId);
     }
 }
Example #2
0
        public void UpdateFrom(GameTransport data, bool checkVersions)
        {
            if (this.Building == null)
                return;

            if (data.floors != null)
            {
                foreach(var f in data.floors)
                {
                    if ((checkVersions && ( f.d.i < this.FloorVersions.Length && this.FloorVersions[f.d.i] < f.v)) || !checkVersions) // if data has higher version
                    {
                        this.FloorVersions[f.d.i] = f.v;
                        this.Building.Floors[f.d.i] = FloorData.ToFloor(f.d);
                    }
                }
            }
            if (data.game != null)
            {
                if ((checkVersions && GameMetaVersion < data.game.v) || !checkVersions) // if data has higher version
                {
                    GameMetaVersion = data.game.v;
                    Winner = PlayerMetaData.ToPlayer(data.game.d.winner);
                    Building.TotalValue = data.game.d.buildingScore;
                }
            }
            if (data.me != null)
            {
                var player = data.me.d;
                if (player != null)
                {
                    if (!PlayerVersions.ContainsKey(player.id))
                    {
                        PlayerVersions.Add(player.id, 0);
                    }
                    if ((checkVersions && PlayerVersions[player.id] < data.me.v) || !checkVersions) // if data has higher version
                    {
                        PlayerVersions[player.id] = data.me.v;
                        if (!PlayerScore.ContainsKey(player.id))
                        {
                            PlayerScore.Add(player.id, 0);
                        }
                        PlayerScore[player.id] = player.score;
                    }
                }
            }
        }
Example #3
0
        public static Game Create(Player owner, string title, int floors, int roomsPerFloor, List<Player> players)
        {
            if (floors > MAX_GAME_FLOORS)
                floors = MAX_GAME_FLOORS;

            if (roomsPerFloor > MAX_GAME_ROOMS_PER_FLOOR)
                roomsPerFloor = MAX_GAME_ROOMS_PER_FLOOR;

            players.Add(owner);
            var playerIds = players.Select(x => x.Id).Distinct().ToList();
            Game result = new Game()
            {
                Title = title,
                Creator = owner,
                PlayerIds = playerIds,
                Players = players.Select(x => x.Clone()).ToList(),
                Id = Guid.NewGuid().ToString("N"),
                Floors = floors,
                RoomsPerFloor = roomsPerFloor,
                Building = Building.Generate(floors, roomsPerFloor, MAX_ITEMS_PER_ROOM, 10),
                FloorVersions = new int[floors],
                PlayerVersions = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase),
                GameMetaVersion = 1,
                RunningState = GameState.WaitingForAllToJoin
            };
            for (int i = 0; i < floors; i++)
            {
                result.FloorVersions[i] = 1;
            }
            foreach (var id in playerIds)
            {
                result.PlayerVersions.Add(id, 1);
                result.PlayerScore.Add(id, 0);
            }
            return result;
        }