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