protected void AnswerButton_Click(object sender, EventArgs e) { llicon.Visible = false; Session["showhistory"] = ""; if (Session["abbr"] == null) { Response.Redirect("Default.aspx"); } if (ddlStates.SelectedItem.Value == "") { lblResult.Text = "Please select a state"; return; } string strAbbr = Session["abbr"].ToString(); int intRank = Convert.ToInt32((Session["rank"].ToString())); int gameScore; litLifeline.Text = ""; string[] players = Session["Players"].ToString().TrimEnd('|').Split('|'); string[] playerScores = Session["PlayerScores"].ToString().TrimEnd('|').Split('|'); int playerTurn = (int)Session["PlayerTurn"]; int newScore; //Correct Answer if (strAbbr == ddlStates.SelectedItem.Value) { llicon.ImageUrl = "images/icons/correct.png"; llicon.AlternateText = "Correct"; llicon.ToolTip = "Correct"; lblResult.Text = "Correct!<br /><br />" + Session["name"].ToString().ToUpper() + " is in " + stateFromAbbr(strAbbr).ToUpper(); int answerValue = (int)Session["answerValue"]; gameScore = answerValue + (int)Session["score"]; newScore = Convert.ToInt32(playerScores[playerTurn]) + answerValue; playerScores[playerTurn] = newScore.ToString(); Session["PlayerScores"] = String.Join("|", playerScores); //Record and display scores for single players int gameLevel = Convert.ToInt32(Session["level"]); if ((gameLevel == 12 || gameLevel == 24 || gameLevel == 36 || gameLevel == 48) && (players.Length == 1)) { Geography geography = new Geography(); geography.PutScore(Session["Players"].ToString().TrimEnd('|').Split('|')[0], DateTime.Now, gameLevel, newScore); Session["showhistory"] = Session["Players"].ToString().TrimEnd('|').Split('|')[0]; } } //Incorrect Answer else { llicon.ImageUrl = "images/icons/incorrect.png"; llicon.AlternateText = "Incorrect"; llicon.ToolTip = "Incorrect"; lblResult.Text = "I'm sorry, that is Incorrect!<br /><br />" + Session["name"].ToString().ToUpper() + " is in " + stateFromAbbr(strAbbr).ToUpper(); int gameLevel = -1 + Convert.ToInt32(Session["level"]); // Don't advance to next level Session["level"] = gameLevel; //int originalAnswerValue = answerBaseScore + (gameLevel * answerIncrement); //Penalize wrong answer if single player, otherwise no penalty int originalAnswerValue = (players.Length == 1) ? answerBaseScore + (gameLevel * answerIncrement) : 0; gameScore = (int)Session["score"] - originalAnswerValue; // Deduct original answer value gameScore = Math.Max(gameScore, 0); // Don't allow score to go negative newScore = Convert.ToInt32(playerScores[playerTurn]) - originalAnswerValue; // Deduct original answer value; newScore = Math.Max(newScore, 0); // Don't allow score to go negative playerScores[playerTurn] = newScore.ToString(); } llicon.Visible = true; string wikiUrl = @"https://en.wikipedia.org/wiki/" + Session["name"].ToString() + ",_" + stateFromAbbr(strAbbr); string wikiLink = "<a href=\"" + wikiUrl + "\" target=\"_blank\">wikipedia</a>"; string gmapUrl = @"https://www.google.com/maps/place/" + Session["name"].ToString() + ",+" + strAbbr; string gmapLink = "<a href=\"" + gmapUrl + "\" target=\"_blank\">google map</a>"; lblResult.Text += "<br /><br /><br />Learn more about " + Session["name"].ToString() + ":<br /><br /> " + wikiLink + " | " + gmapLink; Session["score"] = gameScore; Session["PlayerScores"] = String.Join("|", playerScores); litPlayerScores.Text = ""; for (int i = 0; i < playerScores.Length; i++) { litPlayerScores.Text += "<td class='playerScore'>" + playerScores[i] + "</th>"; } int[] intArrLifeline = RandomIntegerArray(lifelineCount); string strLifelines = string.Join("|", Array.ConvertAll <int, String>(intArrLifeline, Convert.ToString)); Session["lifelines"] = strLifelines; Session["llIndex"] = 0; playerTurn = (playerTurn + 1) % players.Length; Session["PlayerTurn"] = playerTurn; btnLifeline.Visible = false; btnNext.Visible = true; }