public void EndGame(GameOverUpdate gameOver) { State = RunStates.GameOver; // Wait for few seconds Thread.Sleep(2000); Deployment.Current.Dispatcher.BeginInvoke(() => ((Page)Application.Current.RootVisual).ActiveState = new GameOverState(_mainState.LocalPlayer.Color, gameOver.Winner)); }
private void MessageReceived() { lock (_receivedData) { _receivedData.Seek(0, SeekOrigin.Begin); int messageType = _receivedData.ReadByte(); ServerMessageType type = (ServerMessageType)messageType; switch (type) { case ServerMessageType.Map: Map map = Serializer.DeserializeWithLengthPrefix <Map>(_receivedData, PrefixStyle.Base128); Debug.WriteLine("Map received."); // Map successfully received, change game state to wait for start _gameInfo.Level = map; _gameInfo.State = RunStates.WaitingForGameStart; // Update status display Deployment.Current.Dispatcher.BeginInvoke(() => _mainState.DisplayStatusMessage("Waiting for players to be ready...\nYou are NOT ready.")); SendResponse(new ClientStatusUpdate(ClientUpdate.MapOk)); break; case ServerMessageType.Player: PlayerInfo playerInfo = Serializer.DeserializeWithLengthPrefix <PlayerInfo>(_receivedData, PrefixStyle.Base128); _gameInfo.AddPlayer(playerInfo.Color, playerInfo.X, playerInfo.Y); SendResponse(new ClientStatusUpdate(ClientUpdate.PlayerInfoOk)); Debug.WriteLine("Player info received..."); break; case ServerMessageType.StatusUpdate: ServerStatusUpdate update = Serializer.DeserializeWithLengthPrefix <ServerStatusUpdate>(_receivedData, PrefixStyle.Base128); _gameInfo.UpdateStatus(update); break; case ServerMessageType.BombExplosion: BombExplode explosion = Serializer.DeserializeWithLengthPrefix <BombExplode>(_receivedData, PrefixStyle.Base128); _gameInfo.ExplodeBomb(explosion); break; case ServerMessageType.PlayerDeath: PlayerDeath playerDeath = Serializer.DeserializeWithLengthPrefix <PlayerDeath>(_receivedData, PrefixStyle.Base128); _gameInfo.KillPlayer(playerDeath); break; case ServerMessageType.GameOver: GameOverUpdate gameOverUpdate = Serializer.DeserializeWithLengthPrefix <GameOverUpdate>(_receivedData, PrefixStyle.Base128); _gameInfo.EndGame(gameOverUpdate); SendResponseSync("GO OK"); break; default: Debug.WriteLine("Unrecognised package received!"); break; } _receivedData = new MemoryStream(); } }