using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Text; public partial class ajax_Hand : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string reqHand=""; string reqAction=""; if (Request.QueryString["HAND"] != null && !Request.QueryString["HAND"].ToString().Equals("")) reqHand = Request.QueryString["HAND"].ToString().ToUpper(); if (Request.QueryString["ACTION"] != null && !Request.QueryString["ACTION"].ToString().Equals("")) reqAction =Request.QueryString["ACTION"].ToString().ToUpper(); var sb = new StringBuilder(); BlackjackClasses.User u; if(Session["USER"] == null) { sb.AppendLine("Session User is null"); Response.Write(sb.ToString()); } else if(reqAction.Equals("DISPLAY") && !(reqHand.Equals("HOUSE") || reqHand.Equals("PLAYER"))) { sb.AppendLine("Invalid Querystring: reqAction= " + reqAction); sb.AppendLine("ReqHand = " + reqHand); Response.Write(sb.ToString()); } else if(!(reqAction.Equals("DISPLAY")) && !(reqAction.Equals("HIT") || reqAction.Equals("STAY") || reqAction.Equals("DEAL"))) { sb.AppendLine("Invalid Querystring: reqAction= " + reqAction); sb.AppendLine("ReqHand = " + reqHand); Response.Write(sb.ToString()); } else { u = (BlackjackClasses.User)Session["USER"]; if (reqAction.Equals("HIT")) { u.hit(); Session["USER"] = u; } if(reqAction.Equals("DISPLAY")) { List handData = new List(); if(reqHand.Equals("PLAYER")) handData= u.getPlayerHand(); if (reqHand.Equals("HOUSE")) handData = u.getHouseHand(); buildHand(reqHand, sb, handData); } if (reqAction.Equals("STAY")) { u.stay(); Session["USER"] = u; } if (reqAction.Equals("DEAL")) { u.NewGame(); Session["USER"] = u; } } Response.Write(sb.ToString()); } private void buildHand(string reqHand, StringBuilder sb,List cards) { foreach (BlackjackClasses.Card c in cards) { int suitInt = (int)c.CardSuit; int faceInt = (int)c.FaceValue; int pngInt = -1; if (faceInt ==1) //an ace pngInt = suitInt; else // not an ace pngInt = (52 - ((faceInt - 1) * 4)) + suitInt; sb.AppendLine(buildCard(reqHand.ToLower(), c.CardSuit.ToString(), pngInt)); } } private string buildCard(string cardName, string cardSuit, int cardInt) { return "
Card" + cardSuit + cardInt + "
"; } }