示例#1
0
        public async void LoadInfo()
        {
            int expLevel = 75;
            int exp;
            await Task.Run(() =>
            {
                CaroAPI.ThongKe().GetAwaiter().GetResult();
            });

            lblSotran.Text = CaroAPI.thongke.win + "/" + CaroAPI.thongke.lose + "/" + CaroAPI.thongke.draw;
            for (int i = 0; i < 100; i++)
            {
                exp = CaroAPI.thongke.win * 50 + CaroAPI.thongke.draw * 25;
                if ((exp / expLevel) >= 1)
                {
                    lblLevel.Text = (i + 1).ToString();
                    expLevel      = expLevel * 2;
                }
                else if (exp == 0)
                {
                    lblLevel.Text = i.ToString();
                    break;
                }
                else
                {
                    break;
                }
            }
        }
示例#2
0
        private async void btnLogin_Click(object sender, EventArgs e)
        {
            //không cho hành động khi chờ response
            txt_Log1.Enabled = false;
            txt_Log2.Enabled = false;
            btnLogin.Enabled = false;


            user_id = txt_Log1.Text;
            string user_pass = txt_Log2.Text;
            bool   check     = await CaroAPI.Login(txt_Log1.Text, txt_Log2.Text);

            if (check)
            {
                InitClient();

                //Load home
                HomeLoad();

                //check login và chạy hàm load
                processbartime.Start();

                SendUserOnline(user_id);
            }
            else
            {
                try
                {
                    MessageBox.Show(CaroAPI.userReturn.statuscode);
                }
                catch (NullReferenceException ex)
                {
                    MessageBox.Show("Cannot connect to server!");
                }

                // cho hành động lại khi thông báo lỗi
                txt_Log1.Enabled = true;
                txt_Log2.Enabled = true;
                btnLogin.Enabled = true;

                CaroAPI.userReturn = null;
            }
        }
示例#3
0
        public async void LoadAvatar()
        {
            int    expLevel      = 75;
            int    expLevelcoban = 75;
            int    exp;
            string url = $"http://159.89.193.234/svg/" + CaroAPI.user.avatar;

            userAvatar.Load(url);

            // lưu giá trị của avatar dùng để chuyển cho user khác
            user_avatar = CaroAPI.user.avatar;

            await Task.Run(() =>
            {
                CaroAPI.ThongKe().GetAwaiter().GetResult();
            });

            lblSotran.Text = CaroAPI.thongke.win + "/" + CaroAPI.thongke.lose + "/" + CaroAPI.thongke.draw;
            for (int i = 0; i < 100; i++)
            {
                exp = CaroAPI.thongke.win * 50 + CaroAPI.thongke.draw * 25;
                if ((exp / expLevel) >= 1)
                {
                    lblLevel.Text = (i + 1).ToString();
                    expLevel      = expLevel * 2;
                }
                else if (exp == 0)
                {
                    lblLevel.Text = i.ToString();
                    break;
                }
                else
                {
                    break;
                }
            }
        }
示例#4
0
        private async void btnSignup_Click(object sender, EventArgs e)
        {
            if (txtFullname.Text == "")
            {
                MessageBox.Show("Full name can not be empty!", "Caro");
            }
            else if (txtUsername.Text == "")
            {
                MessageBox.Show("Username can not be empty!", "Caro");
            }
            else if (txtPassword.Text == "")
            {
                MessageBox.Show("Password can not be empty!", "Caro");
            }
            else if (txtPassword.Text != password2.Text)
            {
                MessageBox.Show("Passwords do not match!", "Caro");
            }
            else if (!reg.IsMatch(textBox1.Text))
            {
                MessageBox.Show("Invalid email format!", "Caro");
            }
            else
            {
                bool check = await CaroAPI.SignUp(txtUsername.Text, txtFullname.Text, txtPassword.Text, textBox1.Text);

                if (check)
                {
                    MessageBox.Show("Success", "Caro");
                }
                else
                {
                    MessageBox.Show("Username or Email exists", "Caro");
                }
            }
        }
示例#5
0
        private async void DoRefreshFriend(object sender, DoWorkEventArgs e)
        {
            int server_friend = 0;
            int client_friend = 0;

            //List<string> oldFriend_name = new List<string>();

            while (true)
            {
                // cancel worker nếu có tín hiệu cancel gửi đến
                if (workerRefreshFriend.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }

                // do something to refresh friendlist here
                await Task.Run(() =>
                {
                    CaroAPI.FriendList().GetAwaiter().GetResult();
                });


                // đếm số friend
                server_friend = CaroAPI.getFriendList.data.Count;

                // nhét friend nhận đc từ server vào danh sách bạn
                if (server_friend > client_friend)
                {
                    for (int i = 0; i < (server_friend - client_friend); i++)
                    {
                        Invoke(new Action(() =>
                        {
                            danhsachban.Rows.Add();
                        }));
                    }
                }

                for (int i = 0; i < server_friend; i++)
                {
                    FriendList friend = CaroAPI.getFriendList.data[i];

                    if (danhsachban.Rows[i].Cells[0].Value == null)
                    {
                        danhsachban.Rows[i].Cells[0].Value = Resources.left_arrow;
                    }

                    danhsachban.Rows[i].Cells[1].Value = friend.name;

                    if (friend.status == 1)
                    {
                        danhsachban.Rows[i].Cells[2].Value = Resources.online;
                    }
                    else
                    {
                        danhsachban.Rows[i].Cells[2].Value = null;
                    }

                    danhsachban.Rows[i].Cells[3].Value = friend.user.avatar;
                    danhsachban.Rows[i].Cells[4].Value = Convert.ToString(friend.thongke.win);
                    danhsachban.Rows[i].Cells[5].Value = Convert.ToString(friend.thongke.draw);
                    danhsachban.Rows[i].Cells[6].Value = Convert.ToString(friend.thongke.lose);

                    //oldFriend_name.Add(friend.name);
                }


                client_friend = server_friend;

                Thread.Sleep(10000);
            }
        }
示例#6
0
        private async void DoRefreshRoom(object sender, DoWorkEventArgs e)
        {
            int server_room = 0;
            int client_room = 0;

            List <string> oldRoom_no = new List <string>();

            while (true)
            {
                // cancel worker nếu có tín hiệu cancel gửi đến
                if (workerRefreshRoom.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }


                // lấy danh sách phòng trên server
                await Task.Run(() =>
                {
                    CaroAPI.Room().GetAwaiter().GetResult();
                });


                // đếm số phòng nhận được từ server và nhét vào danhsachphong
                server_room = CaroAPI.getRoom.data.Count;


                // quét và xóa những phòng đã thoát

                if (server_room == 0)
                {
                    for (int i = 0; i < client_room; i++)
                    {
                        Invoke(new Action(() =>
                        {
                            danhsachphong.Rows[i].Cells[0].Value = null;
                            danhsachphong.Rows[i].Cells[1].Value = null;
                            danhsachphong.Rows[i].Cells[2].Value = null;
                            danhsachphong.Rows[i].Cells[3].Value = null;
                            danhsachphong.Rows[i].Cells[4].Value = null;
                            danhsachphong.Rows[i].Cells[5].Value = null;
                        }));
                    }
                }

                if (server_room < client_room && server_room != 0)
                {
                    for (int i = 0; i < client_room; i++)
                    {
                        DataGridViewRow row = danhsachphong.Rows[i];

                        foreach (string roomold in oldRoom_no)
                        {
                            if (!row.Cells[2].Value.Equals(roomold))
                            {
                                Invoke(new Action(() =>
                                {
                                    danhsachphong.Rows[row.Index].Cells[0].Value = null;
                                    danhsachphong.Rows[row.Index].Cells[1].Value = null;
                                    danhsachphong.Rows[row.Index].Cells[2].Value = null;
                                    danhsachphong.Rows[row.Index].Cells[3].Value = null;
                                    danhsachphong.Rows[row.Index].Cells[4].Value = null;
                                    danhsachphong.Rows[row.Index].Cells[5].Value = null;
                                }));

                                break;
                            }
                        }
                    }
                    oldRoom_no.Clear();
                }


                // lưu số lượng phòng mới vào biến tạm thời trên client
                client_room = server_room;


                for (int i = 0; i < server_room; i++)
                {
                    RoomGame room = CaroAPI.getRoom.data[i];

                    if (room.room_key != null)
                    {
                        if (room.room_key.Equals("duelyst"))
                        {
                            danhsachphong.Rows[i].Cells[0].Value = Resources.duel;
                            danhsachphong.Rows[i].Cells[1].Value = room.room_key;
                        }
                        else
                        {
                            danhsachphong.Rows[i].Cells[0].Value = Resources.key;
                            danhsachphong.Rows[i].Cells[1].Value = room.room_key;
                        }
                    }
                    danhsachphong.Rows[i].Cells[2].Value = room.room_no;
                    danhsachphong.Rows[i].Cells[3].Value = room.roomname;
                    danhsachphong.Rows[i].Cells[4].Value = room.host_id;
                    danhsachphong.Rows[i].Cells[5].Value = room.join_id;
                    oldRoom_no.Add(room.room_no);
                }
                Thread.Sleep(3000);
            }
        }