private void Login()//登录方法 { string user_id = txtUser.Text; string user_pwd = txtPwd.Text; string str = API_Helper.HttpPost("https://api.shisanshui.rtxux.xyz/auth/login", "{\"username\":\"" + user_id + "\",\"password\":\"" + user_pwd + "\"}", ""); JObject jo = (JObject)JsonConvert.DeserializeObject(str); int status = (int)jo["status"]; if (status == 0) { string token = (string)jo["data"]["token"]; User.token = token; int id = (int)jo["data"]["user_id"]; User.user_id = id; //FrmMain.user_id = user_id; MessageBox.Show("登录成功", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.DialogResult = System.Windows.Forms.DialogResult.OK; } else { MessageBox.Show("登陆失败,用户名或密码错误", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } //if (string.IsNullOrEmpty(message)) //{ // FrmMain.user_id = user_id; // //MessageBox.Show("登录成功", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); // this.DialogResult = System.Windows.Forms.DialogResult.OK; //} //else //{ // MessageBox.Show(message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); //} }
private void sbtnStart_Click(object sender, EventArgs e) { string str = API_Helper.HttpPost("https://api.shisanshui.rtxux.xyz/game/open", "", User.token); JObject jo = (JObject)JsonConvert.DeserializeObject(str); int status = (int)jo["status"]; if (status == 0) { string card = (string)jo["data"]["card"]; User.card = card; int id = (int)jo["data"]["id"]; User.battle_id = id; DealCards.Deal(); //FrmMain.user_id = user_id; MessageBox.Show("加入战局成功", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); //this.DialogResult = System.Windows.Forms.DialogResult.OK; FrmPlay frm = new FrmPlay(); frm.ShowDialog(); } else { MessageBox.Show("开启战局失败", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void sbtnRound_Click(object sender, EventArgs e) { MessageBox.Show("已开启循环赛(默认100局)", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); int count = 100; while ((count--) > 0) { string str = API_Helper.HttpPost("https://api.shisanshui.rtxux.xyz/game/open", "", User.token); JObject jo = (JObject)JsonConvert.DeserializeObject(str); int status = (int)jo["status"]; if (status == 0) { string card = (string)jo["data"]["card"]; User.card = card; int id = (int)jo["data"]["id"]; User.battle_id = id; DealCards.Deal(); string cardFirst = string.Join(" ", User.cardFirst); string cardSecond = string.Join(" ", User.cardSecond); string cardThird = string.Join(" ", User.cardThird); JObject data = new JObject(); data.Add("id", User.battle_id); JArray poker = new JArray(); poker.Add(cardFirst); poker.Add(cardSecond); poker.Add(cardThird); data.Add("card", poker); string dataStr = JsonConvert.SerializeObject(data); string str2 = API_Helper.HttpPost("https://api.shisanshui.rtxux.xyz/game/submit", dataStr, User.token); JObject jo2 = (JObject)JsonConvert.DeserializeObject(str2); int status2 = (int)jo2["status"]; if (status2 == 0) { string msg = jo2["data"]["msg"].ToString(); } else { MessageBox.Show("出牌失败", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } //结束当前战局,清空手牌 User.cardFirst.Clear(); User.cardSecond.Clear(); User.cardThird.Clear(); } else { MessageBox.Show("开启战局失败,参与战局数已达上限,请稍后再开启循环赛", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); break; } } MessageBox.Show("100场战局已完成", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); }
//注册按钮 private void btnReg_Click(object sender, EventArgs e) { string user_id = txtUser.Text.Trim(); string user_pwd = txtPwd.Text.Trim(); string str = API_Helper.HttpPost("https://api.shisanshui.rtxux.xyz/auth/register", "{\"username\":\"" + user_id + "\",\"password\":\"" + user_pwd + "\"}", ""); JObject jo = (JObject)JsonConvert.DeserializeObject(str); int status = (int)jo["status"]; if (status == 0) { //FrmMain.user_id = user_id; MessageBox.Show("注册成功", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.DialogResult = System.Windows.Forms.DialogResult.OK; } else { MessageBox.Show("注册失败", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void sbtnSubmit_Click(object sender, EventArgs e) { string cardFirst = string.Join(" ", User.cardFirst); string cardSecond = string.Join(" ", User.cardSecond); string cardThird = string.Join(" ", User.cardThird); JObject data = new JObject(); data.Add("id", User.battle_id); JArray poker = new JArray(); poker.Add(cardFirst); poker.Add(cardSecond); poker.Add(cardThird); data.Add("card", poker); string dataStr = JsonConvert.SerializeObject(data); string str = API_Helper.HttpPost("https://api.shisanshui.rtxux.xyz/game/submit", dataStr, User.token); JObject jo = (JObject)JsonConvert.DeserializeObject(str); int status = (int)jo["status"]; if (status == 0) { string msg = jo["data"]["msg"].ToString(); if (msg == "Success") { MessageBox.Show("出牌成功", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.DialogResult = System.Windows.Forms.DialogResult.OK; } } else { MessageBox.Show("出牌失败", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } //结束当前战局,清空手牌 User.cardFirst.Clear(); User.cardSecond.Clear(); User.cardThird.Clear(); }