protected void btnRegister_Click(object sender, EventArgs e) { if (!String.IsNullOrEmpty(txtPwd.Text)) { byte[] pwd = Encoding.UTF8.GetBytes(txtPwd.Text); returnEncoded = Convert.ToBase64String(pwd); } LoginManagement lg = new LoginManagement(); lg.getRegisterParams("@user", txtUsr.Text); lg.getRegisterParams("@pw", returnEncoded); lg.getRegisterParams("@email", txtEmail.Text); try { FriendManagement fm = new FriendManagement(); fm.grabIDParams("@username", txtUsr.Text); int getID = fm.grabID(getCon); if (getID != 0) { Label4.Visible = true; Label4.Text = "User exists."; return; } } catch (Exception ex) { //continue } if (lg.doRegister(getCon) == true) { Label4.Visible = true; Label4.Text = "Register successful. Redirecting to Login in 3 seconds."; Thread.Sleep(3000); Response.Redirect("~/Login.aspx"); } else { Label4.Visible = true; Label4.Text = "Error occurred."; } }
protected void Page_Load(object sender, EventArgs e) { FriendManagement fm = new FriendManagement(); try { fm.grabIDParams("@username", Session["username"].ToString()); int ownID = fm.grabID(getCon); Session["ownID"] = ownID; if (GridView1.Rows.Count <= 0) { Label1.Visible = true; Label1.Text = "No data to show"; } } catch (Exception ex) { Response.Redirect("~/Login.aspx"); } }
protected void Page_Load(object sender, EventArgs e) { try { getuser = Session["username"].ToString(); } catch (Exception) { Response.Redirect("~/Login.aspx"); } try { gm.grabStatsParams("@username", getuser); string getCmd = "GrabStatsHP"; string ohp = gm.grabStats(getCon, getCmd).ToString(); int ownhp; int.TryParse(ohp, out ownhp); if (ownhp <= 0) { Label1.Visible = true; Label1.Text = "This battle cannot continue."; } GameManagement gm2 = new GameManagement(); gm2.grabStatsParams("@username", getuser); string getCmd3 = "GrabStatsAttack"; string atk = gm2.grabStats(getCon, getCmd3).ToString(); int convatk; int.TryParse(atk, out convatk); Random rnd = new Random(); int convdef = rnd.Next(10, convatk + 100); if (convatk > convdef) { Label1.Visible = true; Label1.Text = "You win vs CPU practice!"; FriendManagement fm = new FriendManagement(); fm.grabIDParams("@username", getuser); int ownID = fm.grabID(getCon); gm.logChallengeParams("@challenger", ownID); gm.logChallengeParams("@challenged", -1); //cpu string timestamp = GetUnixTimestamp().ToString(); gm.logChallengeParamsTime("@timestamp", timestamp); gm.logChallengeParams("@iswin", 1); gm.logChallengeParams("@isloss", 0); gm.logChallenge(getCon); } else { Label1.Visible = true; Label1.Text = "You lose vs CPU practice!"; FriendManagement fm = new FriendManagement(); fm.grabIDParams("@username", getuser); int ownID = fm.grabID(getCon); gm.logChallengeParams("@challenger", ownID); gm.logChallengeParams("@challenged", -1); //cpu string timestamp = GetUnixTimestamp().ToString(); gm.logChallengeParamsTime("@timestamp", timestamp); gm.logChallengeParams("@iswin", 0); gm.logChallengeParams("@isloss", 1); gm.logChallenge(getCon); } } catch (Exception ex) { Label1.Visible = true; Label1.Text = "An error has occurred"; } }
protected void Button1_Click(object sender, EventArgs e) { try { if (getuser.Equals(TextBox1.Text)) { Label2.Visible = true; Label2.Text = "You cannot fight yourself."; return; } gm.grabStatsParams("@username", getuser); string getCmd = "GrabStatsHP"; string ohp = gm.grabStats(getCon, getCmd).ToString(); int ownhp; int.TryParse(ohp, out ownhp); if (ownhp <= 0) { Label2.Visible = true; Label2.Text = "This battle cannot continue."; } if (TextBox1.Text.Length != 0) { GameManagement gm2 = new GameManagement(); gm2.grabStatsParams("@username", TextBox1.Text); string getCmd2 = "GrabStatsHP"; string ehp = gm2.grabStats(getCon, getCmd2).ToString(); int enemyhp; int.TryParse(ehp, out enemyhp); if (enemyhp <= 0) { Label2.Visible = true; Label2.Text = "This battle cannot continue."; return; } GameManagement gm3 = new GameManagement(); gm3.grabStatsParams("@username", getuser); string getCmd3 = "GrabStatsAttack"; string atk = gm3.grabStats(getCon, getCmd3).ToString(); int convatk; int.TryParse(atk, out convatk); GameManagement gm4 = new GameManagement(); gm4.grabStatsParams("@username", TextBox1.Text); string getCmd4 = "GrabStatsDefense"; string def = gm4.grabStats(getCon, getCmd4).ToString(); int convdef; int.TryParse(def, out convdef); if (convatk == convdef) { Label2.Visible = true; Label2.Text = "Draw match, routine not executed."; return; } if (convatk > convdef) { Label2.Visible = true; Label2.Text = "You win! -15hp to enemy"; gm.minushpParams("@username", TextBox1.Text); gm.minushp(getCon); gm.addWinParams("@username", getuser); gm.addWin(getCon); gm.addLossParams("@username", TextBox1.Text); gm.addLoss(getCon); FriendManagement fm = new FriendManagement(); fm.grabIDParams("@username", getuser); int ownID = fm.grabID(getCon); FriendManagement fm2 = new FriendManagement(); fm2.grabIDParams("@username", TextBox1.Text); int enemyID = fm2.grabID(getCon); gm.logChallengeParams("@challenger", ownID); gm.logChallengeParams("@challenged", enemyID); string timestamp = GetUnixTimestamp().ToString(); gm.logChallengeParamsTime("@timestamp", timestamp); gm.logChallengeParams("@iswin", 1); gm.logChallengeParams("@isloss", 0); gm.logChallenge(getCon); } else { Label2.Visible = true; Label2.Text = "You lose! -15 hp to you"; gm.minushpParams("@username", getuser); gm.minushp(getCon); gm.addWinParams("@username", TextBox1.Text); gm.addWin(getCon); gm.addLossParams("@username", getuser); gm.addLoss(getCon); FriendManagement fm = new FriendManagement(); fm.grabIDParams("@username", getuser); int ownID = fm.grabID(getCon); FriendManagement fm2 = new FriendManagement(); fm2.grabIDParams("@username", TextBox1.Text); int enemyID = fm2.grabID(getCon); gm.logChallengeParams("@challenger", ownID); gm.logChallengeParams("@challenged", enemyID); string timestamp = GetUnixTimestamp().ToString(); gm.logChallengeParamsTime("@timestamp", timestamp); gm.logChallengeParams("@iswin", 0); gm.logChallengeParams("@isloss", 1); gm.logChallenge(getCon); } } } catch (Exception ex) { Label2.Visible = true; Label2.Text = "An error has occurred"; } }