private void btnCreate_Click(object sender, EventArgs e) { clsProfile profile; if (txtUserName.Text != "") { profile = new clsProfile(txtUserName.Text); profile.TotalGames = 0; profile.TotalWin = 0; profile.TotalLose = 0; profile.TotalDraw = 0; profile.Rating = 1200; clsImage img = new clsImage(picAvatar.Image, picAvatar.Width, picAvatar.Height); profile.Avatar = img; profile.SaveProfile(); MessageBox.Show("Tạo Profile Thành Công !!!"); this.Close(); } else { MessageBox.Show("Bạn Chưa Nhập Tên !!!"); } }
private void lstPlayer_SelectedIndexChanged(object sender, EventArgs e) { if (lstPlayer.SelectedIndex != -1) { clsProfile profile = new clsProfile(lstPlayer.SelectedItem.ToString()); profile.LoadProfile(); pictureBox1.Image = profile.Avatar.Avatar; } }
private void frmManageProfile_Load(object sender, EventArgs e) { clsProfile profile = new clsProfile(strPlayerName); profile.LoadProfile(); picAvatar.Image = profile.Avatar.Avatar; lblPlayerName.Text = profile.PlayerName; lblTotalGames.Text = profile.TotalGames.ToString(); lblTotalWin.Text = profile.TotalWin.ToString(); lblTotalLose.Text = profile.TotalLose.ToString(); lblTotalDraw.Text = profile.TotalDraw.ToString(); lblRating.Text = profile.Rating.ToString(); }
private static int GetDevelopmenCoefficien(clsProfile profile) { if (profile._TotalGames < 30) { return(25); } else if (profile.Rating < 2400) { return(15); } else { return(10); } }
public void LoadProfile(string ProfileName) { clsProfile profile = new clsProfile(ProfileName); profile.LoadProfile(); this._profile = profile; clsImage Avatar = profile.Avatar; picAvatar.Image = Avatar.Avatar; lblPlayerName.Text = profile.PlayerName; lblTotalWin.Text = profile.TotalWin.ToString(); lblTotalDraw.Text = profile.TotalDraw.ToString(); lblTotalLose.Text = profile.TotalLose.ToString(); lblRating.Text = profile.Rating.ToString(); }
private void btnJoinGame_Click(object sender, EventArgs e) { if (lstHost.SelectedItems.Count > 0) { tListenForRequest.Abort(); this.ActiveListener = false; timerSendBroadcast.Stop(); timerUpdateHost.Stop(); frmMain.localpc.DisconnectUDP(); frmMain.localpc.ConnectState = 1; frmMain.localpc.Function = 2; ListViewItem li = lstHost.SelectedItems[0]; string strHost = li.Text; string[] arrHostEntry = strHost.Split(':'); frmMain.localpc.ParnerIP = arrHostEntry[1]; frmMain.localpc.ParnerName = arrHostEntry[0]; clsProfile profile = new clsProfile(frmMain.localpc.Profile); string a = profile.TotalWin.ToString(); string b = profile.TotalDraw.ToString(); string c = profile.TotalLose.ToString(); string d = profile.Rating.ToString(); frmMain.localpc.SendUDPData(frmMain.localpc.ParnerIP, "JOIN", a + ":" + b + ":" + c + ":" + d); this.Hide(); this.AlHost = new ArrayList(); lstHost.Items.Clear(); ///Join Game frmLanGame frmlangame = new frmLanGame(); frmlangame.ShowDialog(); ///Escape Game this.Show(); this.ActiveListener = true; timerSendBroadcast.Start(); timerUpdateHost.Start(); tListenForRequest = new Thread(new ThreadStart(ListenForRequest)); tListenForRequest.IsBackground = true; tListenForRequest.Start(); } else { MessageBox.Show("Vui lòng chọn máy ...", "Join Game"); } }
public static void CalculateResult(ref clsProfile profile1, ref clsProfile profile2, GameResult result) { profile1.TotalGames += 1; profile2.TotalGames += 1; int k1 = GetDevelopmenCoefficien(profile1); int k2 = GetDevelopmenCoefficien(profile2); float fResult1 = new float(); if (result == GameResult.Win) { fResult1 = 1.0f; profile1.TotalWin += 1; profile2.TotalLose += 1; } if (result == GameResult.Lose) { fResult1 = 0.0f; profile1.TotalLose += 1; profile2.TotalWin += 1; } if (result == GameResult.Draw) { fResult1 = 0.5f; profile1.TotalDraw += 1; profile2.TotalDraw += 1; } float fResult2 = 1.0f - fResult1; int difference = profile1.Rating - profile2.Rating; float dp1 = GetScoringProbability(difference); float dp2 = 1.0f - dp1; int score1 = (int)Math.Round((fResult1 - dp1) * k1); int score2 = (int)Math.Round((fResult2 - dp2) * k2); profile1.Rating = profile1.Rating + score1; profile2.Rating = profile2.Rating + score2; }
void ListenForRequestBroadcast() { while (ActiveListenerBroadcast) { string message = frmMain.localpc.ReceiveUDPDataBroadCast(); if (message != "") { string strType; string strParnerIp = ""; string strParnerName, strItem; frmMain.localpc.AnalysisReceiveUDPString(message, out strType, out strParnerIp, out strParnerName, out strItem); if (strParnerIp != frmMain.localpc.ipAddress.ToString()) { switch (strType.ToUpper()) { case "FINDHOST": if (frmMain.localpc.ConnectState == 0) { frmMain.localpc.SendUDPData(strParnerIp, "HOST", ""); } break; case "JOIN": string[] arrProfileInfo = strItem.Split(':'); string totalwin = arrProfileInfo[0]; string totoldraw = arrProfileInfo[1]; string totallose = arrProfileInfo[2]; string rating = arrProfileInfo[3]; ucOppProfile.LoadProfile(strParnerName, totalwin, totoldraw, totallose, rating); frmMain.localpc.ConnectState = 1; btnkichout.Enabled = true; frmMain.localpc.ParnerIP = strParnerIp; frmMain.localpc.ParnerName = strParnerName; frmMain.localpc.ConnectState = 1; frmMain.localpc.Function = 1; btnSanSang.Enabled = true; clsProfile profile = new clsProfile(frmMain.localpc.Profile); totalwin = profile.TotalWin.ToString(); totoldraw = profile.TotalDraw.ToString(); totallose = profile.TotalLose.ToString(); rating = profile.Rating.ToString(); frmMain.localpc.SendUDPData(frmMain.localpc.ParnerIP, "PROFILE", totalwin + ":" + totoldraw + ":" + totallose + ":" + rating); lblstatus.Text = "Đang tiến hành kết nối với " + strParnerName; this.ActiveListenerBroadcast = false; this.ActiveListenerUDP = true; tRec = new Thread(new ThreadStart(ListenForRequestUDP)); tRec.IsBackground = true; tRec.Start(); break; case "CHAT": lstChatBox.Items.Add(strParnerName + " :" + strItem); lstChatBox.TopIndex = lstChatBox.Items.Count - 1; break; } } } frmMain.localpc.DisconnectUDP(); } }