예제 #1
0
 public void CheckDrawer(ClientModel client)
 {
     if (initialized)
     {
         if (client.Name == ClientHandler.GetInstance().Name)
         {
             this.canDraw = true;
             this.mainWindow.ShowDrawGrid();
         }
         else
         {
             this.canDraw = false;
             this.mainWindow.HideDrawGrid();
         }
     }
 }
예제 #2
0
 /// <summary>
 /// Leave the current room and return to hub
 /// </summary>
 public void LeaveRoom()
 {
     ClientHandler.GetInstance().LeaveRoom();
     this.sendMessage(new Message(MessageTypes.LeaveRoom, JsonConvert.SerializeObject(new RoomModel(ClientHandler.GetInstance().Roomname, 0))));
 }
 private void btnEnterGame_Click(object sender, RoutedEventArgs e)
 {
     ClientHandler.GetInstance().SetName(txtUsername.Text);
     this.connector.SendCheckUsername(txtUsername.Text);
 }
예제 #4
0
        /// <summary>
        /// Handle thie incoming message, destination from: ReadMessage();
        /// </summary>
        /// <param name="stringMessage"></param>
        private void HandleMessage(string stringMessage)
        {
            Message message = JsonConvert.DeserializeObject <Message>(stringMessage);

            switch (message.Type)
            {
            case MessageTypes.Inform:
                GuessModel guessModel = JsonConvert.DeserializeObject <GuessModel>(message.Data);
                DrawHandler.GetInstance().WriteMessage(guessModel.Word);
                break;

            case MessageTypes.SendDrawing:
                DrawPoint drawPoint = JsonConvert.DeserializeObject <DrawPoint>(message.Data);
                DrawHandler.GetInstance().DrawLine(drawPoint);
                break;

            case MessageTypes.NewDrawer:
                DrawHandler.GetInstance().CheckDrawer(JsonConvert.DeserializeObject <ClientModel>(message.Data));
                break;

            case MessageTypes.NewHost:
                ClientHandler.GetInstance().SetHost(JsonConvert.DeserializeObject <ClientModel>(message.Data));
                break;

            case MessageTypes.JoinRoom:
                RoomModel room = JsonConvert.DeserializeObject <RoomModel>(message.Data);
                ClientHandler.GetInstance().SetRoomname(room.Name);
                ClientHandler.GetInstance().SetRoomSize(room.AmountOfPlayers);
                break;

            case MessageTypes.StartGame:
                GameModel gameModel = JsonConvert.DeserializeObject <GameModel>(message.Data);
                ClientHandler.GetInstance().SetWordSize(gameModel.LengthOfWord);
                ClientHandler.GetInstance().SetRoundLabel(gameModel.CurrentRound);
                DrawHandler.GetInstance().HideHostGrid();
                DrawHandler.GetInstance().HideWinners();
                break;

            case MessageTypes.EndGame:
                EndGameModel endGameModel = JsonConvert.DeserializeObject <EndGameModel>(message.Data);
                ClientHandler.GetInstance().ShowWinners(endGameModel);
                ClientHandler.GetInstance().EndGame();
                break;

            case MessageTypes.GuessWord:
                ClientHandler.GetInstance().SetWord(JsonConvert.DeserializeObject <GuessModel>(message.Data).Word);
                break;

            case MessageTypes.NewRound:
                gameModel = JsonConvert.DeserializeObject <GameModel>(message.Data);
                ClientHandler.GetInstance().SetWordSize(gameModel.LengthOfWord);
                ClientHandler.GetInstance().SetRoundLabel(gameModel.CurrentRound);
                DrawHandler.GetInstance().ClearCanvas();
                break;

            case MessageTypes.UsernameCheck:
                bool validName = JsonConvert.DeserializeObject <ClientModel>(message.Data).ValidName;
                ClientHandler.GetInstance().CheckUsername(validName);
                break;

            case MessageTypes.Ping:
                this.sendMessage(new Message(MessageTypes.Pong, ""));
                break;

            default:
                break;
            }
        }