-
Notifications
You must be signed in to change notification settings - Fork 0
/
TypeCode.cs
58 lines (55 loc) · 2.17 KB
/
TypeCode.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using MinigameOlympia.Models;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Net.Http;
using System.Net.Sockets;
using System.Windows.Forms;
namespace MinigameOlympia {
public partial class TypeCode : Form {
public Player player;
public Image image;
public string roomCode = "";
public TcpClient client;
public List<List<Player>> friendList;
private bool isExit = false;
public TypeCode() {
InitializeComponent();
}
public bool getIsExit() {
return isExit;
}
private async void btnEnter_Click(object sender, EventArgs e) {
HttpClient httpClient = new HttpClient();
try {
string url = "https://olympiawebservice.azurewebsites.net/api/Room/" + tbRoomCode.Text;
var response = await httpClient.GetAsync(url);
if (response.IsSuccessStatusCode) {
var res = await response.Content.ReadAsStringAsync();
JObject keyValuePairs = JObject.Parse(res);
JToken roomRes = keyValuePairs["isFull"];
if (roomRes.Value<bool>()) {
MessageBox.Show("Phòng " + tbRoomCode.Text + " đã đủ người!", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
} else {
roomCode = tbRoomCode.Text;
PhongCho pc = new PhongCho();
pc.client = client;
pc.player = player;
pc.image = image;
pc.roomCode = roomCode;
pc.friendList = friendList;
pc.isAdmin = false;
pc.Show();
isExit = true;
Close();
}
} else {
MessageBox.Show("Không tìm thấy phòng!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} catch (Exception ex) {
MessageBox.Show(ex.Message);
}
}
}
}