public void OnEnable() { _itemViews = new List <ComparedPlayerView> (); _itemPrefab.gameObject.SetActive(false); _model = PlayerSerializer.LoadComparer(); UpdateView(); }
void InitializeObjectsSender(GameObject level, UpdateManager updateManager) { // enable all the local players and their serializers on the sending side foreach (LocalPlayerController localPlayer in level.GetComponentsInChildren <LocalPlayerController>()) { localPlayer.enabled = true; PlayerSerializer localSerializer = localPlayer.GetComponent <PlayerSerializer> (); localSerializer.enabled = true; localSerializer.updateManager = updateManager; } // on the sender side, keys, key blocks and pressure playes should // all respond to collisions, not remote updates! foreach (KeyController key in level.GetComponentsInChildren <KeyController>()) { key.enabled = true; } foreach (PressurePlateController plate in level.GetComponentsInChildren <PressurePlateController>()) { plate.enabled = true; } foreach (KeyBlockController block in level.GetComponentsInChildren <KeyBlockController>()) { block.enabled = true; } // all of these obstacles need to be set up to notify the // update manager when something changes! foreach (BoolObstacleSerializer obstacle in level.GetComponentsInChildren <BoolObstacleSerializer>()) { obstacle.enabled = true; obstacle.updateManager = updateManager; } // as for push blocks, we'll need to enable their // normal controllers to, so that they can be pushed around // and we'll also set them up to foreach (PushBlockController pbc in level.GetComponentsInChildren <PushBlockController>()) { pbc.enabled = true; PushBlockSerializer pbs = pbc.GetComponent <PushBlockSerializer> (); pbs.enabled = true; pbs.updateManager = updateManager; } }
/// <summary> /// Retrieves the players. /// </summary> /// <returns>A <typeparamref name="T"/> representation of the JSON value.</returns> private static List <T> GetPlayers() { string jsonData = FileManagement.OpenFile(typeof(T).Name); if (!string.IsNullOrWhiteSpace(jsonData)) { return(PlayerSerializer.DeserializePlayers <List <T> >(jsonData)); } return(new List <T>()); }
private void saveExecute() { string playerSaveFile = Path.Combine(dataDir, "players.elo"); List <PlayerSerializer> pSerials = PlayerSerializer.SerializeList(Players); Serializer <PlayerSerializer> .Save(pSerials, playerSaveFile); string gameSaveFile = Path.Combine(dataDir, "games.elo"); List <GameSerializer> gSerials = GameSerializer.SerializeList(History.GameHistory); Serializer <GameSerializer> .Save(gSerials, gameSaveFile); }
public void OnSavePlayerPressed() { int bestAverage = int.MinValue; int firstBest = -1; for (int i = 0; i < _population.Players.Count; i++) { if (bestAverage < _population.Players[i].AverageScore) { bestAverage = _population.Players[i].AverageScore; firstBest = i; } } PlayerSerializer.SavePlayer("Rodriges", _population.Players[firstBest].Player); }
public void InitializeGameNode() { //for (int i = 0; i < 30; i++) //{ // this.Player.Deck.Cards.Add(this.CardLibrary.CreateCard("wheel", this.Player)); //} //for (int i = 0; i < 30; i++) //{ // this.Opponent.Deck.Cards.Add(this.CardLibrary.CreateCard("wheel", this.Opponent)); //} this.Player = PlayerSerializer.Deserialize("player.xml"); this.Opponent = PlayerSerializer.Deserialize("opponent.xml"); this.gameNode.VisitStart(this); }
void InitializeObjectsReceiver(GameObject level, UpdateManager updateManager) { // enable all the local players and their serializers on the sending side foreach (LocalPlayerController remotePlayer in level.GetComponentsInChildren <LocalPlayerController>()) { remotePlayer.GetComponent <LerpingPhysicsController>().enabled = true; // enable the serialisers! and link them to update manager PlayerSerializer remoteSerializer = remotePlayer.GetComponent <PlayerSerializer> (); remoteSerializer.enabled = true; updateManager.Subscribe(remoteSerializer, UpdateManager.Channel.PLAYER); } // on the receiver side, there's no need to control keys and stuff via // collisions! they should just respond to network updates through their // serializer foreach (BoolObstacleSerializer obstacle in level.GetComponentsInChildren <BoolObstacleSerializer>()) { obstacle.enabled = true; updateManager.Subscribe(obstacle, UpdateManager.Channel.OBSTACLE); } // push blocks are also meant to subscribe to notifications from the // network, and should be remote controllable foreach (PushBlockController pbc in level.GetComponentsInChildren <PushBlockController>()) { LerpingPhysicsController rpc = pbc.GetComponent <LerpingPhysicsController> (); rpc.enabled = true; PushBlockSerializer pbs = pbc.GetComponent <PushBlockSerializer> (); pbs.enabled = true; updateManager.Subscribe(pbs, UpdateManager.Channel.PUSHBLOCK); } }
private void loadExecute() { string playerSaveFile = Path.Combine(dataDir, "players.elo"); if (!File.Exists(playerSaveFile)) { return; } IEnumerable <PlayerSerializer> pSerials = Serializer <PlayerSerializer> .Load(playerSaveFile); refreshPlayers(PlayerSerializer.UnserializeList(pSerials)); string gameSaveFile = Path.Combine(dataDir, "games.elo"); if (!File.Exists(gameSaveFile)) { return; } IEnumerable <GameSerializer> gSerials = Serializer <GameSerializer> .Load(gameSaveFile); History.Refresh(GameSerializer.UnserializeList(gSerials, Players)); }
public IEnumerable <Player> GetPlayers(string country = null) => PlayerSerializer.GetPlayers(country);
/// <summary> /// Saves the players. /// </summary> public void SavePlayers() { var jsonData = PlayerSerializer.SerializePlayers(PlayerList); FileManagement.SaveFile(typeof(T).Name, jsonData); }
protected override BaseSerializer PerformAction(ClientConnection conn, BaseSerializer requestData) { RequestSerializer data = (RequestSerializer)requestData; ResponseSerializer resp = (ResponseSerializer)InitializeResponseSerializer(); resp.Status = "OK"; Lobby lobby = (Lobby)conn.Session.Get("joined-lobby"); Match game = lobby.Game; string username = (string)conn.Session.Get("username"); resp.MatchInfo = new MatchSerializer(); resp.MatchInfo.EWPointsHistory = new string[game.History.WEHistory.Count]; resp.MatchInfo.NSPointsHistory = new string[game.History.NSHistory.Count]; for (int i = 0; i < game.History.WEHistory.Count; i++) { resp.MatchInfo.EWPointsHistory[i] = game.History.WEHistory[i]; } for (int i = 0; i < game.History.NSHistory.Count; i++) { resp.MatchInfo.NSPointsHistory[i] = game.History.NSHistory[i]; } resp.MatchInfo.CurrentBidding = new BiddingSerializer(); resp.MatchInfo.CurrentBidding.ContractList = new ContractSerializer[game.CurrentBidding.ContractList.Count]; for (int i = 0; i < game.CurrentBidding.ContractList.Count; i++) { var tmp = new ContractSerializer(); tmp.ContractColor = (int)game.CurrentBidding.ContractList[i].ContractColor; tmp.ContractHeight = (int)game.CurrentBidding.ContractList[i].ContractHeight; tmp.PlayerTag = (int)game.CurrentBidding.ContractList[i].DeclaredBy; tmp.XEnabled = game.CurrentBidding.ContractList[i].XEnabled; tmp.XXEnabled = game.CurrentBidding.ContractList[i].XXEnabled; resp.MatchInfo.CurrentBidding.ContractList[i] = tmp; } resp.MatchInfo.CurrentBidding.BiddingEnded = game.CurrentBidding.End; resp.MatchInfo.CurrentBidding.CurrentPlayerTag = (int)game.CurrentBidding.CurrentPlayer; resp.MatchInfo.CurrentBidding.Dealer = (int)game.CurrentBidding.Dealer; var tmpHighestBidContract = new ContractSerializer(); tmpHighestBidContract.ContractColor = (int)game.CurrentBidding.HighestContract.ContractColor; tmpHighestBidContract.ContractHeight = (int)game.CurrentBidding.HighestContract.ContractHeight; tmpHighestBidContract.PlayerTag = (int)game.CurrentBidding.HighestContract.DeclaredBy; tmpHighestBidContract.XEnabled = game.CurrentBidding.HighestContract.XEnabled; tmpHighestBidContract.XXEnabled = game.CurrentBidding.HighestContract.XXEnabled; resp.MatchInfo.CurrentBidding.HighestContract = tmpHighestBidContract; //resp.MatchInfo.CurrentBidding.PassCounter = game.CurrentBidding.HighestContract resp.MatchInfo.PointsNS = new int[game.PointsNS.Length]; resp.MatchInfo.PointsEW = new int[game.PointsWE.Length]; for (int i = 0; i < game.PointsNS.Length; i++) { resp.MatchInfo.PointsNS[i] = game.PointsNS[i]; } for (int i = 0; i < game.PointsWE.Length; i++) { resp.MatchInfo.PointsEW[i] = game.PointsWE[i]; } resp.MatchInfo.RoundsNS = game.RoundsNS; resp.MatchInfo.RoundsEW = game.RoundsWE; resp.MatchInfo.Dealer = (int)game.Dealer; resp.MatchInfo.GameState = (int)game.GameState; resp.MatchInfo.PlayerList = new PlayerSerializer[4]; resp.MatchInfo.GrandpaCards = new CardSerializer[13]; PlayerSerializer tmpPlayerSerializer; for (int i = 0; i < 4; i++) { if (game.PlayerList[i] != null) { tmpPlayerSerializer = new PlayerSerializer(); tmpPlayerSerializer.PlayerTag = (int)game.PlayerList[i].Tag; tmpPlayerSerializer.Username = game.PlayerList[i].Name; resp.MatchInfo.PlayerList[i] = tmpPlayerSerializer; switch (game.PlayerList[i].Tag) { case PlayerTag.N: resp.MatchInfo.NPlayerHandSize = game.PlayerList[i].Hand.Length; break; case PlayerTag.E: resp.MatchInfo.EPlayerHandSize = game.PlayerList[i].Hand.Length; break; case PlayerTag.S: resp.MatchInfo.SPlayerHandSize = game.PlayerList[i].Hand.Length; break; case PlayerTag.W: resp.MatchInfo.WPlayerHandSize = game.PlayerList[i].Hand.Length; break; } bool IsGrand = IsPlayerGrand(game.PlayerList[i].Tag, game); if (game.PlayerList[i].Name == username) // przypadek gdy to są moje karty { resp.MatchInfo.PlayerCards = new CardSerializer[game.PlayerList[i].Hand.Length]; for (int c = 0; c < game.PlayerList[i].Hand.Length; c++) { resp.MatchInfo.PlayerCards[c] = new CardSerializer(); resp.MatchInfo.PlayerCards[c].Color = (int)game.PlayerList[i].Hand[c].Color; resp.MatchInfo.PlayerCards[c].Figure = (int)game.PlayerList[i].Hand[c].Figure; resp.MatchInfo.PlayerCards[c].State = (int)game.PlayerList[i].Hand[c].CurrentState; } resp.MatchInfo.GrandpaCards = null; } else if (IsGrand) // przypadek gdy to nie są moje karty { resp.MatchInfo.PlayerCards = null; bool GrandCardsVisible = AreGrandCardsVisible(game); if (GrandCardsVisible) { resp.MatchInfo.GrandpaCards = new CardSerializer[game.PlayerList[i].Hand.Length]; for (int c = 0; c < game.PlayerList[i].Hand.Length; c++) { resp.MatchInfo.GrandpaCards[c] = new CardSerializer(); resp.MatchInfo.GrandpaCards[c].Color = (int)game.PlayerList[i].Hand[c].Color; resp.MatchInfo.GrandpaCards[c].Figure = (int)game.PlayerList[i].Hand[c].Figure; resp.MatchInfo.GrandpaCards[c].State = (int)game.PlayerList[i].Hand[c].CurrentState; } } else { resp.MatchInfo.GrandpaCards = null; } } } else { resp.MatchInfo.PlayerList[i] = null; } } resp.MatchInfo.GameInfo = new GameInfoSerializer(); resp.MatchInfo.GameInfo.ContractColor = (int)game.CurrentGame.ContractColor; resp.MatchInfo.GameInfo.CurrentPlayer = (int)game.CurrentGame.CurrentPlayer; resp.MatchInfo.GameInfo.CurrentTrick = new TrickSerializer(); resp.MatchInfo.GameInfo.CurrentTrick.CardList = new CardSerializer[4]; for (int i = 0; i < 4; i++) { resp.MatchInfo.GameInfo.CurrentTrick.CardList[i] = null; } for (int i = 0; i < game.CurrentGame.currentTrick.CardList.Count; i++) { resp.MatchInfo.GameInfo.CurrentTrick.CardList[i] = new CardSerializer(); resp.MatchInfo.GameInfo.CurrentTrick.CardList[i].Color = (int)game.CurrentGame.currentTrick.CardList[i].Color; resp.MatchInfo.GameInfo.CurrentTrick.CardList[i].Figure = (int)game.CurrentGame.currentTrick.CardList[i].Figure; resp.MatchInfo.GameInfo.CurrentTrick.CardList[i].State = (int)game.CurrentGame.currentTrick.CardList[i].CurrentState; } resp.MatchInfo.GameInfo.CurrentTrick.Winner = (int)game.CurrentGame.currentTrick.Winner; resp.MatchInfo.GameInfo.Declarer = (int)game.CurrentGame.Declarer; return(resp); }
public void OnSavePressed() { PlayerSerializer.SaveComparer(_model); }
protected override BaseSerializer PerformAction(ClientConnection conn, BaseSerializer requestData) { RequestSerializer data = (RequestSerializer)requestData; ResponseSerializer resp = (ResponseSerializer)InitializeResponseSerializer(); Lobby lobby = (Lobby)conn.Session.Get("joined-lobby"); Match game = lobby.Game; // Serializacja podstawowych informacji resp.Status = "OK"; resp.GameState = (int)game.GameState; resp.Dealer = (int)game.Dealer; resp.PointsNSAboveLine = game.PointsNS[1]; resp.PointsNSBelowLine = game.PointsNS[0]; resp.PointsWEAboveLine = game.PointsWE[1]; resp.PointsWEBelowLine = game.PointsWE[0]; resp.NumberOfPlayers = game.PlayerList.Count; resp.Players = new PlayerSerializer[4]; resp.NumberOfLobbyUsers = lobby.ConnectedClients.Count; resp.LobbyUsers = new LobbyUserSerializer[lobby.ConnectedClients.Count]; for (int i = 0; i < 4; i++) { resp.Players[i] = null; } // Serializacja graczy przy stole PlayerSerializer tmpPlayer; int index = 0; foreach (var player in game.PlayerList) { tmpPlayer = new PlayerSerializer(); tmpPlayer.PlayerTag = (int)player.Tag; tmpPlayer.Username = player.Name; resp.Players[index] = tmpPlayer; index++; } // Serializacja użytkowników w lobby LobbyUserSerializer tmpLobbyUser; Player tmpGamePlayer; index = 0; foreach (var lobbyUser in lobby.ConnectedClients) { tmpLobbyUser = new LobbyUserSerializer(); tmpLobbyUser.Username = lobbyUser.Session.Get <string>("username"); if (!lobbyUser.Session.Has("player")) { tmpLobbyUser.IsSitted = false; tmpLobbyUser.PlayerTag = -1; } else { tmpGamePlayer = lobbyUser.Session.Get <Player>("player"); tmpLobbyUser.IsSitted = true; tmpLobbyUser.PlayerTag = (int)tmpGamePlayer.Tag; } resp.LobbyUsers[index] = tmpLobbyUser; index++; } // test API for bidding serialization /*var match = new Match(); * match.AddPlayer(new Player(PlayerTag.W, "WPlayer")); * match.AddPlayer(new Player(PlayerTag.S, "SPlayer")); * match.AddPlayer(new Player(PlayerTag.E, "EPlayer")); * match.AddPlayer(new Player(PlayerTag.N, "NPlayer")); * * match.Start(); * match.AddBid(new Contract(ContractHeight.ONE, ContractColor.C, PlayerTag.E)); * match.AddBid(new Contract(ContractHeight.ONE, ContractColor.D, PlayerTag.S)); * match.AddBid(new Contract(ContractHeight.ONE, ContractColor.H, PlayerTag.W)); * match.AddBid(new Contract(ContractHeight.NONE, ContractColor.NONE, PlayerTag.N)); * match.AddBid(new Contract(ContractHeight.TWO, ContractColor.C, PlayerTag.E)); * match.AddBid(new Contract(ContractHeight.NONE, ContractColor.NONE, PlayerTag.S, true)); * match.AddBid(new Contract(ContractHeight.NONE, ContractColor.NONE, PlayerTag.W, false, true)); * match.AddBid(new Contract(ContractHeight.NONE, ContractColor.NONE, PlayerTag.N)); * match.AddBid(new Contract(ContractHeight.NONE, ContractColor.NONE, PlayerTag.E)); * match.AddBid(new Contract(ContractHeight.NONE, ContractColor.NONE, PlayerTag.S)); * * if (true)//game.GameState == GameState.BIDDING) * { * var tmp = new BiddingSerializer(); * tmp.CurrentPlayerTag = (int)match.CurrentBidding.CurrentPlayer; * tmp.ContractList = new ContractSerializer[match.CurrentBidding.ContractList.Count]; * * Contract tmpContract; * for (int i = 0; i < match.CurrentBidding.ContractList.Count; i++) * { * tmpContract = match.CurrentBidding.ContractList[i]; * tmp.ContractList[i] = new ContractSerializer(); * * tmp.ContractList[i].ContractColor = (int)tmpContract.ContractColor; * tmp.ContractList[i].ContractHeight = (int)tmpContract.ContractHeight; * tmp.ContractList[i].XEnabled = tmpContract.XEnabled; * tmp.ContractList[i].XXEnabled = tmpContract.XXEnabled; * tmp.ContractList[i].PlayerTag = (int)tmpContract.DeclaredBy; * } * * tmp.HighestContract = new ContractSerializer(); * tmp.HighestContract.ContractColor = (int)match.CurrentBidding.HighestContract.ContractColor; * tmp.HighestContract.ContractHeight = (int)match.CurrentBidding.HighestContract.ContractHeight; * tmp.HighestContract.XEnabled = match.CurrentBidding.HighestContract.XEnabled; * tmp.HighestContract.XXEnabled = match.CurrentBidding.HighestContract.XXEnabled; * tmp.HighestContract.PlayerTag = (int)match.CurrentBidding.HighestContract.DeclaredBy; * * tmp.Dealer = (int)PlayerTag.N; * tmp.BiddingEnded = match.CurrentBidding.IsEnd(); * * resp.CurrentBidding = tmp; * }*/ // end test for bidding serialization // Serializacja licytacji if (game.GameState == GameState.BIDDING) { var tmp = new BiddingSerializer(); tmp.CurrentPlayerTag = (int)game.CurrentBidding.CurrentPlayer; tmp.ContractList = new ContractSerializer[game.CurrentBidding.ContractList.Count]; Contract tmpContract; for (int i = 0; i < game.CurrentBidding.ContractList.Count; i++) { tmpContract = game.CurrentBidding.ContractList[i]; tmp.ContractList[i] = new ContractSerializer(); tmp.ContractList[i].ContractColor = (int)tmpContract.ContractColor; tmp.ContractList[i].ContractHeight = (int)tmpContract.ContractHeight; tmp.ContractList[i].XEnabled = tmpContract.XEnabled; tmp.ContractList[i].XXEnabled = tmpContract.XXEnabled; tmp.ContractList[i].PlayerTag = (int)tmpContract.DeclaredBy; } tmp.HighestContract = new ContractSerializer(); tmp.HighestContract.ContractColor = (int)game.CurrentBidding.HighestContract.ContractColor; tmp.HighestContract.ContractHeight = (int)game.CurrentBidding.HighestContract.ContractHeight; tmp.HighestContract.XEnabled = game.CurrentBidding.HighestContract.XEnabled; tmp.HighestContract.XXEnabled = game.CurrentBidding.HighestContract.XXEnabled; tmp.HighestContract.PlayerTag = (int)game.CurrentBidding.HighestContract.DeclaredBy; tmp.Dealer = (int)game.Dealer; tmp.BiddingEnded = game.CurrentBidding.IsEnd(); resp.CurrentBidding = tmp; } else { resp.CurrentBidding = null; } // Rundy resp.RoundsNS = game.RoundsNS; resp.RoundsWE = game.RoundsWE; return(resp); }
public void TestMethod() { var response = PlayerSerializer.GetPlayers("Brazil"); }