private void ProcessRecieveMessages(BaseClientServer clientServer) { for (int i = 0; i < clientServer.CountRecievedData(); i++) { curMessage = clientServer.GetRecievedData(); if (curMessage == string.Empty) { continue; } NetMessage netMessage = JsonReader.Deserialize <NetMessage>(curMessage); if (netMessage != null) { switch ((NetMessageCode)netMessage.messType) { case NetMessageCode.RequestGameState: { SendMessage(NetMessageCode.GetGameState, null); break; } case NetMessageCode.GetGameState: { GameStateProxy proxy = JsonReader.Deserialize <GameStateProxy>(netMessage.message); GameController.StartNetWatchGame(proxy); break; } case NetMessageCode.NewBubble: { if (GameController.curGameMode == GameMode.netView) { NewBubbleProxy proxy = JsonReader.Deserialize <NewBubbleProxy>(netMessage.message); GameController.CreateNetWatchBubble(proxy); } break; } case NetMessageCode.UserDestroyBubble: { if (GameController.curGameMode == GameMode.netView) { UserDestroyBubbleProxy proxy = JsonReader.Deserialize <UserDestroyBubbleProxy>(netMessage.message); GameController.DestroyNetWatchBuble(proxy); } break; } case NetMessageCode.NewLevel: { if (GameController.curGameMode == GameMode.netView) { NewLevelProxy proxy = JsonReader.Deserialize <NewLevelProxy>(netMessage.message); GameController.NewNetWatchLevel(proxy); } break; } } } } }
public static GameStateProxy GetGameState() { GameStateProxy proxy = new GameStateProxy(); proxy.level = curLevel; proxy.score = score; proxy.timer = levelTimer; proxy.smallBubbleSpeed = singleton.smallBubbleSpeed; proxy.bigBubbleSpeed = singleton.bigBubbleSpeed; List <NewBubbleProxy> bubbles = new List <NewBubbleProxy>(); foreach (KeyValuePair <int, BubbleController> bubble in singleton.bubblesDict) { bubbles.Add(bubble.Value.GenerateNewBubbleProxy()); } proxy.bubbles = bubbles.ToArray <NewBubbleProxy>(); return(proxy); }
public static void StartNetWatchGame(GameStateProxy proxy) { if (singleton._curGameMode != GameMode.netView) { UserInterfaceController.ChangeUserInterfaceMode(InterfaceMode.WatchNetGame); singleton._curGameMode = GameMode.netView; singleton.DestroyAllBubblesInDict(); singleton._curGameMode = GameMode.netView; singleton._curLevel = proxy.level; singleton._score = proxy.score; ResourceManager.GenerateNewTexturesSet(); singleton.smallBubbleSpeed = proxy.smallBubbleSpeed; singleton.bigBubbleSpeed = proxy.bigBubbleSpeed; singleton._levelTimer = proxy.timer; for (int i = 0; i < proxy.bubbles.Length; i++) { BubbleController newBubble = singleton.bubblesGenerator.GenerateNewNetWatchBubble(proxy.bubbles[i], singleton.smallBubbleSpeed, singleton.bigBubbleSpeed); singleton.bubblesDict.Add(newBubble.id, newBubble); } } }