Esempio n. 1
0
 public bool CreateGame(List<User> users)
 {
     List<Player> players = new List<Player>();
     List<ServerUser> serverUsers = new List<ServerUser>();
     int idCounter = 0;
     foreach (User targetUser in users)
     {
         ServerUser user = targetUser as ServerUser;
         players.Add(user.player = new ServerPlayer(idCounter++, targetUser.userName));
         serverUsers.Add(user);
     }
     ServerGame game = new ServerGame(20000, players, serverUsers);
     game.OnGameOver += CloseGame;
     game.canRollDice = true;
     foreach (Block block in game.map.blocks)
     {
         if (block is LandBlock)
         {
             block.OnTokenPlaceInto += PayForTollEventTask;
             block.OnTokenPlaceInto += UpgradeLandSelectionEventTask;
             block.OnTokenPlaceInto += BuyLandSelectionEventTask;
         }
         else if (block is StartBlock)
         {
             block.OnTokenPass += PassStartBlockEventTask;
         }
         else if (block is CardBlock)
         {
             block.OnTokenPlaceInto += DrawCardEventTask;
         }
     }
     gameDictionary.Add(game.id, game);
     foreach (User targetUser in users)
     {
         (targetUser as ServerUser).playingGame = game;
     }
     Dictionary<byte, object> parameter = new Dictionary<byte, object>
     {
         {(byte)GameStartBroadcastParameterItem.GameDataString, JsonConvert.SerializeObject(game.Serialize(), new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto }) }
     };
     List<Peer> peers = new List<Peer>();
     foreach (ServerUser targetUser in game.users)
     {
         peers.Add(targetUser.Peer);
     }
     Broadcast(peers.ToArray(), BroadcastType.GameStart, parameter);
     return true;
 }
Esempio n. 2
0
 private void CloseGame(ServerGame game)
 {
     Player winner = game.GameOverReturnWinnner();
     Dictionary<byte, object> parameter = new Dictionary<byte, object>
     {
         {(byte)EndGameBroadcastParameterItem.WinerName, winner.username },
         {(byte)EndGameBroadcastParameterItem.WinerMoney, winner.money },
         {(byte)EndGameBroadcastParameterItem.GameDataString, JsonConvert.SerializeObject(game.Serialize(), new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto }) }
     };
     List<Peer> peers = new List<Peer>();
     foreach (ServerUser targetUser in game.users)
     {
         peers.Add(targetUser.Peer);
         targetUser.playingGame = null;
         if(targetUser == (targetUser.userGroup as Room).host)
             targetUser.ready = true;
         else
             targetUser.ready = false;
     }
     Broadcast(peers.ToArray(), BroadcastType.EndGame, parameter);
     gameDictionary.Remove(game.id);
 }