public static void GuiToaDo(Quobject.SocketIoClientDotNet.Client.Socket socket, int row, int col) { //Thực hiện gửi vị trí đánh cho server đầu vào là hàng cột, socket.On(Socket.EVENT_ERROR, (data) => { MessageBox.Show(data.ToString()); }); socket.Emit("MyStepIs", JObject.FromObject(new { row = row, col = col })); }
public static void guitoado(Quobject.SocketIoClientDotNet.Client.Socket socket, int row, int col) { socket.On(Socket.EVENT_ERROR, (data) => { MessageBox.Show(data.ToString()); }); socket.Emit("MyStepIs", JObject.FromObject(new { row = row, col = col })); }
public static void KetNoi(Quobject.SocketIoClientDotNet.Client.Socket socket, string name) { //Việc cần làm: Kết nối tới server, thành công đăng kí danh tính MyNameIs, và ConnectToOtherPlayer //Đồng thời khởi tạo cái socket.On() để bắt tương ứng các nội dung //Bắt ChatMessage //Bắt EndGame //Bắt NextStepIs //Thất bại(Không kết tới server thành công) xuất thông báo và return socket.On(Socket.EVENT_CONNECT, () => { MessageBox.Show("Connected", "Thông báo", MessageBoxButton.OK); }); socket.On(Socket.EVENT_MESSAGE, (data) => { MessageBox.Show(data.ToString()); }); socket.On("ChatMessage", (data) => { string s = "You are the first player!"; turn = data.ToString().Contains(s); MessageBox.Show(data.ToString()); if (((Newtonsoft.Json.Linq.JObject)data)["message"].ToString() == "Welcome!") { socket.Emit("MyNameIs", name); socket.Emit("ConnectToOtherPlayer"); _name = name; } else if (((Newtonsoft.Json.Linq.JObject)data)["message"].ToString() != "Welcome!") { _mes = data.ToString(); } }); socket.On(Socket.EVENT_ERROR, (data) => { MessageBox.Show(data.ToString()); }); socket.On("NextStepIs", (data) => { var a = JObject.Parse(data.ToString()); _row = (int)a["row"]; _col = (int)a["col"]; }); socket.On("EndGame", (data) => { MessageBox.Show(data.ToString()); }); }
public static void KetNoi(Quobject.SocketIoClientDotNet.Client.Socket socket, string name) { socket.On(Socket.EVENT_CONNECT, () => { MessageBox.Show("Connected sucessfully"); }); socket.On(Socket.EVENT_MESSAGE, (data) => { MessageBox.Show(data.ToString()); }); socket.On(Socket.EVENT_CONNECT_ERROR, (data) => { MessageBox.Show(data.ToString()); }); socket.On("ChatMessage", (data) => { string k = "You are the first player!"; bl = data.ToString().Contains(k); MessageBox.Show(data.ToString()); if (((Newtonsoft.Json.Linq.JObject)data)["message"].ToString() == "Welcome!") { socket.Emit("MyNameIs", name); socket.Emit("ConnectToOtherPlayer"); copy = name; } }); socket.On(Socket.EVENT_ERROR, (data) => { MessageBox.Show(data.ToString()); }); socket.On("NextStepIs", (data) => { var o = JObject.Parse(data.ToString()); BanCo.rows = (int)o["row"]; BanCo.columns = (int)o["col"]; }); }
public static void connected(Quobject.SocketIoClientDotNet.Client.Socket socket, string name) { //socket.On(Socket.EVENT_CONNECT, () => //{ // MessageBox.Show("connected", "Thông báo "); //}); socket.On(Socket.EVENT_MESSAGE, (data) => { MessageBox.Show(data.ToString()); }); socket.On(Socket.EVENT_CONNECT_ERROR, (data) => { MessageBox.Show(data.ToString()); }); socket.On("ChatMessage", (data) => { string s = "You are the first player!"; turn = data.ToString().Contains(s); if (MainWindow.type == 4 && turn == true) { Application.Current.Dispatcher.Invoke((Action)(() => { MainWindow.txt.Text = data.ToString(); })); } string ten = ""; var o = JObject.Parse(data.ToString()); if ((string)o["from"] != null) { ten = (string)o["from"]; } else { ten = "Server"; } var jobject = data as JToken; AppSetting.mes.Mes += ten + "\t\t" + DateTime.Now.ToString() + "\n" + jobject.Value<String>("message") + "\n\t***************************************\n\n"; if (((Newtonsoft.Json.Linq.JObject)data)["message"].ToString() == "Welcome!") { socket.Emit("MyNameIs", name); socket.Emit("ConnectToOtherPlayer"); Ten = name; } }); socket.On(Socket.EVENT_ERROR, (data) => { MessageBox.Show(data.ToString()); }); //ham nhan toa do socket.On("NextStepIs", (data) => { var o = JObject.Parse(data.ToString()); if (MainWindow.type == 1) { ChessBoard.currPlayer = Player.Onl; //BanCo.currPlayer = o.Value<int>("player"); ChessBoard.rows = (int)o["row"]; ChessBoard.columns = (int)o["col"]; } }); }
public void connected(Quobject.SocketIoClientDotNet.Client.Socket socket, string name) { socket.On(Socket.EVENT_CONNECT, () => { MessageBox.Show("connected", "Thông báo "); }); socket.On(Socket.EVENT_MESSAGE, (data) => { MessageBox.Show(data.ToString()); }); socket.On(Socket.EVENT_CONNECT_ERROR, (data) => { MessageBox.Show(data.ToString()); }); socket.On("ChatMessage", (data) => { MessageBox.Show(data.ToString()); if (((Newtonsoft.Json.Linq.JObject)data)["message"].ToString() == "Welcome!") { socket.Emit("MyNameIs", name); socket.Emit("ConnectToOtherPlayer"); } string mes = ((Newtonsoft.Json.Linq.JObject)data)["message"].ToString(); if (mes.Contains("You are the first player!") == true) { activer = 2; } }); socket.On(Socket.EVENT_ERROR, (data) => { MessageBox.Show(data.ToString()); }); socket.On("NextStepIs", (data) => { MessageBox.Show(data.ToString()); var o = JObject.Parse(data.ToString()); activer = (int)o["player"]; row = (int)o["row"]; column = (int)o["col"]; MessageBox.Show(row + " " + column + " " + activer); if (activer == 1) { board.play(column, row, activer); activer = 2; } if (activer == 2) { activer = 2; } }); }
public static void connected(Quobject.SocketIoClientDotNet.Client.Socket socket, string name) { socket.On(Socket.EVENT_CONNECT, () => { MessageBox.Show("connected", "Thông báo "); }); socket.On(Socket.EVENT_MESSAGE, (data) => { MessageBox.Show(data.ToString()); }); socket.On(Socket.EVENT_CONNECT_ERROR, (data) => { MessageBox.Show(data.ToString()); }); socket.On("ChatMessage", (data) => { string k = "You are the first player!"; bl = data.ToString().Contains(k); var o = JObject.Parse(data.ToString()); if (connect.bl == true) { if (BanCo.Option.WhoPlayWith == Player.Online) { BanCo.currPlayer = Player.Human; } if (BanCo.Option.WhoPlayWith == Player.MayOnline) { Application.Current.Dispatcher.Invoke((Action)(() => { BanCo.currPlayer = Player.Com; MainWindow.txtNguoiMay.Text = data.ToString(); })); } } MainWindow.message = (string)o["message"]; var jobject = data as JToken; NhanMessage.ketnoi.Message += jobject.Value<String>("message") + " " + DateTime.Now.ToString() + "\n\n"; if (((Newtonsoft.Json.Linq.JObject)data)["message"].ToString() == "Welcome!") { socket.Emit("MyNameIs", name); socket.Emit("ConnectToOtherPlayer"); copy = name; } if ((string)o["from"] != null) { MainWindow.name = (string)o["from"]; } }); socket.On(Socket.EVENT_ERROR, (data) => { MessageBox.Show(data.ToString()); }); socket.On("NextStepIs", (data) => { var o = JObject.Parse(data.ToString()); if (BanCo.Option.WhoPlayWith == Player.Online) { if (((int)o["row"] != connect.rw || (int)o["col"] != connect.cl)) { BanCo.rows = (int)o["row"]; BanCo.columns = (int)o["col"]; Application.Current.Dispatcher.Invoke((Action)(() => { MainWindow.txt.Text = data.ToString(); })); } } if (BanCo.Option.WhoPlayWith == Player.MayOnline) { if (((int)o["row"] != connect.rw1 || (int)o["col"] != connect.cl1)) { BanCo.rows = (int)o["row"]; BanCo.columns = (int)o["col"]; Application.Current.Dispatcher.Invoke((Action)(() => { MainWindow.txtMay.Text = data.ToString(); })); } } }); }