using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using BlackjackClasses; using System.Text; public partial class ajax_Game : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string reqAction = ""; BlackjackClasses.User u = null; if (Session["USER"] == null) Response.Write("User session is null"); else u = (BlackjackClasses.User)Session["USER"]; if (Request.QueryString["ACTION"] != null && !Request.QueryString["ACTION"].ToString().Equals("")) reqAction = Request.QueryString["ACTION"].ToString().ToUpper(); if(reqAction.Equals("GETSTATUS")) { var sb = new StringBuilder(); if(u.Status.Equals(Round.GameStatus.UnfinishedGame)) sb.Append("U"); if(u.Status.Equals(Round.GameStatus.DealerWin)) sb.Append("H"); if(u.Status.Equals(Round.GameStatus.PlayerWin)) sb.Append("P"); if(u.Status.Equals(Round.GameStatus.Draw)) sb.Append("D"); sb.Append("House Score: "); sb.Append(u.HouseScore); sb.Append("
"); sb.Append("Player Score: "); sb.Append(u.PlayerScore); Response.Write(sb.ToString()); } else if (reqAction.Equals("SAVEGAME")) { u.saveRound(); Session["USER"] = u; } else if (reqAction.Equals("STATS")) { Response.Write(getHistory(u)); } else Response.Write("Invalid Querystring, ACTION = " + reqAction); } private string getHistory(User u) { List history = u.getRoundHistory(); StringBuilder sb = new StringBuilder(); int winsCount = history.Count(x => x.status.Equals(Round.GameStatus.PlayerWin)); int loseCount = history.Count(x => x.status.Equals(Round.GameStatus.DealerWin)); int drawCount = history.Count(x => x.status.Equals(Round.GameStatus.Draw)); int TotalRounds = history.Count(); sb.Append(""); sb.Append(""); sb.Append("
WinsLossesDraws
"); sb.Append(winsCount); sb.Append(""); sb.Append(loseCount); sb.Append(""); sb.Append(drawCount); sb.Append("
"); sb.Append("
"); int altColour = 0; foreach (Round r in history) { if(altColour % 2 == 0) sb.Append(""); altColour++; } sb.Append("
House ScorePlayer ScoreWinner
"); else sb.Append("
"); sb.Append(r.HouseDummyScore); sb.Append(""); sb.Append(r.PlayerDummyScore); sb.Append(""); sb.Append(r.status.ToString()); sb.Append("
"); return sb.ToString(); } }