Пример #1
0
        void ws_MessageReceived(object sender, MessageReceivedEventArgs e)
        {
            Console.WriteLine(e.Message);

            JSONObjects Message = JsonConvert.DeserializeObject<JSONObjects>(e.Message);
            if (ServerConnectionStatus == (ushort)eServerConnectionStatus.ESTABLISHING)
            {
                RoomID = Message.RoomID;
                WhoIAm = Message.WhoIAm;
                Console.WriteLine(RoomID + ":" + WhoIAm);
                ServerConnectionStatus = (ushort)eServerConnectionStatus.ESTABLISHED;
                JSONObjects ACKMesssage = new JSONObjects() { RoomID = RoomID, HandShake = false, KayiNo = 0, KayiMove = 0, WhoIAm = WhoIAm, ClientVersion = ClientVersion, ClientMessage = "ACK" };
                ws.Send(ACKMesssage.ToJsonString());
            }
            if (ServerConnectionStatus == (ushort)eServerConnectionStatus.ESTABLISHED)
            {
                if (Message.ServerMessage == "ACK")
                {
                    ServerConnectionStatus = (ushort)eServerConnectionStatus.CONNECTED;
                    Console.WriteLine("Connected");
                    Display("Connected to Server",2000);
                    Display("Your Turn:"+WhoIAm);
                    SendObject = Message;
                    this.Dispatcher.Invoke((Action)delegate()
                    {
                        ChatGrid.Visibility = Visibility.Visible;
                        StartAnimation(CreateAnimation(this, Window.WidthProperty, MainWindowWidth, MainWindowWidth + 200, 1000));
                        StartAnimation(CreateAnimation(ChatGrid, Grid.WidthProperty, ChatGrid.Width, ChatGrid.Width + 200, 1000));
                        StartAnimation(CreateAnimation(ChatBox, TextBox.WidthProperty, 0, 150, 1000));
                        TimeOutBarGrid.Width += 200; 
                    }, null);
                }
            }
            if (ServerConnectionStatus == (ushort)eServerConnectionStatus.CONNECTED)
            {
                if (Message.ChatMessage)
                {
                    this.Dispatcher.Invoke((Action)delegate()
                    {
                        ChatLabel.Items.Add(Message.ClientMessage);
                    }, null);
                }
                if (Message.ServerMessage == "START")
                {
                    StartPlay = true;
                    MaxPlayer = MaxKayi;
                    if (WhoIAm != 1)
                        this.Dispatcher.Invoke((Action)delegate()
                        {
                            WaitingGIF.Play();
                        }, null);
                    if (WhoIAm == 1)
                    {
                        Message.ClientMessage = "STARTED";
                        ws.Send(Message.ToJsonString());
                        isMoved = false;
                        ThreadStart start = new ThreadStart(TimerStart);
                        TimerThread = new Thread(start);
                        TimerThread.Name = "Timer Thread";
                        TimerThread.Start();
                        PlayerStatus = ePlayerStatus.HisTurn;
                    }
                    PlayStatus = ePlayStatus.PLAYING;
                }
                else if (PlayStatus == ePlayStatus.PLAYING)
                {
                    this.Dispatcher.Invoke((Action)delegate()
                    {
                        if (Message.TurnState == WhoIAm - 1)
                        {
                            isMoved = false;
                            ThreadStart start = new ThreadStart(TimerStart);
                            TimerThread = new Thread(start);
                            TimerThread.Name = "Timer Thread";
                            TimerThread.Start();
                            PlayerStatus = ePlayerStatus.HisTurn;
                            WaitingGIF.Visibility = Visibility.Hidden;
                            WaitingGIF.Stop();
                        }
                        else
                        {
                            PlayerStatus = ePlayerStatus.OthersTurn;
                            /*
                            if (Message.ClientMessage == "TURN")
                            {
                                TurnState = Message.TurnState;
                                Turn();
                            }*/
                            WaitingGIF.Visibility = Visibility.Visible;
                            WaitingGIF.Play();
                            if (Message.ClientMessage == "KAYIMOVE")
                                LetsMoveKayi(Message.KayiMove, Message.KayiNo);
                            
                        }
                    }, null);
                }
            }
        }
Пример #2
0
        private JSONObjects HandShake()
        {
            JSONObjects HandShakeMesssage = new JSONObjects() { RoomID = RoomID, HandShake = true, KayiNo = 0, KayiMove = 0, WhoIAm = WhoIAm, ClientVersion = ClientVersion };

            return HandShakeMesssage;
        }