Esempio n. 1
0
        public void OnMessageReceived(string message)
        {
            Console.WriteLine("Received message from server: " + message);

            if (JSONSerialization.TryParseJson(message, out GameState gameState))
            {
                Console.WriteLine("Received game state");
                _gameForm.OnGameState(gameState);
                // pass new game state to game form
            }
            else if (JSONSerialization.TryParseJson(message, out PlayerList players))
            {
                Console.WriteLine("Received player list");
                // pass new player list to main form
                if (players.playernames[0] == playerName)
                {
                    _mainForm.ShowStartButton();
                }
                else
                {
                    _mainForm.HideStartButton();
                }
            }
            else if (message == StringLiterals.StartGame)
            {
                StartGame();
            }
            else if (message == StringLiterals.EndGame)
            {
                EndGame();
            }
            _mainForm.OnMessageReceived(message);
        }