public MainWindow()
        {
            InitializeComponent();

            HideHostGrid();
            ToolGrid.Visibility         = Visibility.Hidden;
            DrawGrid.Visibility         = Visibility.Hidden;
            GridWord.Visibility         = Visibility.Hidden;
            winningGrid.Visibility      = Visibility.Hidden;
            gridNoConnection.Visibility = Visibility.Hidden;
            lblWrongUsername.Visibility = Visibility.Hidden;

            pencilThickness.Items.Add("1");
            pencilThickness.Items.Add("2");
            pencilThickness.Items.Add("3");
            pencilThickness.Items.Add("4");
            pencilThickness.Items.Add("5");
            pencilThickness.Items.Add("6");
            pencilThickness.Items.Add("7");
            pencilThickness.Items.Add("8");
            pencilThickness.SelectedItem = "1";

            DrawHandler.GetInstance().Initialize(this);
            this.connector = new Connector();
        }
        private void Canvas_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            if (DrawHandler.GetInstance().CanDraw)
            {
                if (e.LeftButton == MouseButtonState.Pressed)
                {
                    Line line = new Line();

                    SolidColorBrush brush = new SolidColorBrush();
                    brush.Color = DrawHandler.GetInstance().Color;
                    line.Stroke = brush;

                    line.StrokeThickness = DrawHandler.GetInstance().LineThickness;
                    line.X1 = currentPoint.X;
                    line.Y1 = currentPoint.Y;
                    line.X2 = e.GetPosition(this).X;
                    line.Y2 = e.GetPosition(this).Y;

                    currentPoint = e.GetPosition(this);

                    DrawPoint drawpoint = DrawPoint.CreatePointFromLine(line, DrawHandler.GetInstance().Color);
                    this.connector.SendDrawPoint(drawpoint);

                    paintSurface.Children.Add(line);
                }
            }
        }
 public void LeaveRoom()
 {
     this.isHost = false;
     DrawHandler.GetInstance().HideHostGrid();
     DrawHandler.GetInstance().HideDrawGrid();
     DrawHandler.GetInstance().HideWordGrid();
     DrawHandler.GetInstance().CanDraw = false;
 }
Esempio n. 4
0
 public static DrawHandler GetInstance()
 {
     if (instance == null)
     {
         instance = new DrawHandler();
     }
     return(instance);
 }
 public void EndGame()
 {
     DrawHandler.GetInstance().HideWordGrid();
     DrawHandler.GetInstance().HideDrawGrid();
     if (this.isHost)
     {
         DrawHandler.GetInstance().ShowHostGrid();
     }
 }
 private void Canvas_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
 {
     if (DrawHandler.GetInstance().CanDraw)
     {
         if (e.ButtonState == MouseButtonState.Pressed)
         {
             currentPoint = e.GetPosition(this);
         }
     }
 }
 public void CheckUsername(bool validName)
 {
     if (validName)
     {
         DrawHandler.GetInstance().SetUsername();
     }
     else
     {
         DrawHandler.GetInstance().WrongUsername();
     }
 }
        private void pencilThickness_Selected(object sender, RoutedEventArgs e)
        {
            int lineThickness = int.Parse(pencilThickness.SelectedIndex.ToString());

            if (lineThickness == 0)
            {
                lineThickness = 1;
            }

            DrawHandler.GetInstance().LineThickness = lineThickness;
        }
 public void SetHost(ClientModel clientModel)
 {
     if (this.name == clientModel.Name)
     {
         this.isHost = true;
         DrawHandler.GetInstance().ShowHostGrid();
     }
     else
     {
         this.isHost = false;
         DrawHandler.GetInstance().HideHostGrid();
     }
 }
Esempio n. 10
0
        /// <summary>
        /// Makes connection to the draw server and saves the connection in the client and stream variable.
        /// </summary>
        public Connector()
        {
            try
            {
                //client = new System.Net.Sockets.TcpClient("86.82.166.205", 12242); // Create a new connection
                client = new System.Net.Sockets.TcpClient("127.0.0.1", 12242); // Create a new connection
                stream = client.GetStream();

                Message message = new Message(MessageTypes.Inform, "Hello There!");
                sendMessage(message);

                StartReading();
            }
            catch (Exception ex)
            {
                DrawHandler.GetInstance().ShowNoConnection();
            }
        }
Esempio n. 11
0
 public void ShowWinners(EndGameModel endGameModel)
 {
     DrawHandler.GetInstance().ShowWinners(endGameModel);
 }
Esempio n. 12
0
 public void SetWord(string word)
 {
     DrawHandler.GetInstance().SetWord(word);
 }
Esempio n. 13
0
 public void SetRoundLabel(int rounds)
 {
     DrawHandler.GetInstance().SetRoundsLabel(rounds);
 }
Esempio n. 14
0
 public void SetWordSize(int wordSize)
 {
     this.wordSize = wordSize;
     DrawHandler.GetInstance().SetWordSizeLabel(wordSize);
     DrawHandler.GetInstance().ShowWordGrid();
 }
Esempio n. 15
0
 public void SetRoomname(string name)
 {
     this.roomName = name;
     DrawHandler.GetInstance().SetRoomNameLabel(name);
 }
        private void btnColor_Click(object sender, RoutedEventArgs e)
        {
            SolidColorBrush buttonBrush = (SolidColorBrush)(sender as Button).Background;

            DrawHandler.GetInstance().SetColor(buttonBrush.Color);
        }
Esempio n. 17
0
 public void SetRoomSize(int roomSize)
 {
     this.roomSize = roomSize;
     DrawHandler.GetInstance().SetRoomSizeLabel(roomSize);
 }
Esempio n. 18
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;
            }
        }