protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); Xamarin.Essentials.Platform.Init(this, savedInstanceState); // Set our view from the "main" layout resource SetContentView(Resource.Layout.activity_main); edtBetValue = FindViewById <EditText>(Resource.Id.edtGuessedNumber); edtMoney = FindViewById <EditText>(Resource.Id.edtMoney); txtCount = FindViewById <TextView>(Resource.Id.txtCount); txtScore = FindViewById <TextView>(Resource.Id.txtScore); txtResult = FindViewById <TextView>(Resource.Id.txtResult); txtMoney = FindViewById <TextView>(Resource.Id.txtMoney); txtStatus = FindViewById <TextView>(Resource.Id.txtStatus); btnSubmit = FindViewById <Button>(Resource.Id.btnSubmitBet); btnSubmit.Click += delegate { try { if (canPlay) { if (!isBet) { int betValueMoney = Convert.ToInt32(edtMoney.Text.ToString()); if (Common.score >= betValueMoney) { JSONObject jsonObject = new JSONObject(); jsonObject.Put("money", betValueMoney); jsonObject.Put("betValue", Convert.ToInt32(edtBetValue.Text.ToString())); socket.Emit("client_send_money", jsonObject); Common.score -= betValueMoney; txtScore.Text = Convert.ToString(Common.score); isBet = true; } else { Toast.MakeText(this, "You do not have enough money", ToastLength.Short).Show(); } } else { Toast.MakeText(this, "You already bet in this turn.", ToastLength.Short).Show(); } } else { Toast.MakeText(this, "Please wait until to next turn.", ToastLength.Short).Show(); } } catch (Exception ex) { Toast.MakeText(this, ex.Message, ToastLength.Short).Show(); } }; btnDisconnect = FindViewById <Button>(Resource.Id.btnDisconnect); btnDisconnect.Click += delegate { if (!isDisconnect) { socket.Disconnect(); btnDisconnect.Text = "CONNECT"; } else { socket.Connect(); btnDisconnect.Text = "DISCONNECT"; } isDisconnect = !isDisconnect; }; try { socket = IO.Socket("http://10.0.2.2:3000"); socket.On(Socket.EventConnect, new MyConnectEventListener(this)); socket.Connect(); } catch (System.Exception ex) { Toast.MakeText(this, ex.Message, ToastLength.Short).Show(); } //Register all event from socket RegisterListeningEvent(); }
public void Disconect() { Socket?.Disconnect(); }