Exemple #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Session["wwPlayers"] == null || Session["wwPlayerScores"] == null || Session["wwPlayerTurn"] == null)
            {
                getPlayers.Visible = true;
                playGame.Visible   = false;
            }
            else
            {
                getPlayers.Visible = false;
                playGame.Visible   = true;

                string[] wwPlayers      = Session["wwPlayers"].ToString().TrimEnd('|').Split('|');
                string[] wwPlayerScores = Session["wwPlayerScores"].ToString().TrimEnd('|').Split('|');
                int      playerCount    = wwPlayers.Length;
                int      playerTurn     = (int)Session["wwPlayerTurn"];
                int      gameScore      = (Session["wwscore"] != null) ? (int)Session["wwscore"] : 0;
                Session["wwscore"] = gameScore;

                int gameLevel = (Session["wwlevel"] != null) ? 1 + Convert.ToInt32(Session["wwlevel"]) : 1;
                Session["wwlevel"] = gameLevel;

                if (gameLevel > 48)
                {
                    lblResult.Text      = "Congratulations...  You have reached the highest level!";
                    litAnswerValue.Text = Session["wwanswerValue"].ToString();
                    for (int i = 0; i < playerCount; i++)
                    {
                        litPlayerNames.Text  += "<th class='playerName'>" + wwPlayers[i] + "</th>";
                        litPlayerScores.Text += "<td class='playerScore'>" + wwPlayerScores[i] + "</td>";
                    }
                    Session.Abandon();
                    return;
                }

                int answerValue = answerBaseScore + (gameLevel - 1) * answerIncrement;
                Session["wwanswerValue"] = answerValue;
                litAnswerValue.Text      = answerValue.ToString();
                for (int i = 0; i < playerCount; i++)
                {
                    string activeClass = ((i == playerTurn) ? " active" : "");
                    litPlayerNames.Text  += "<th class='playerName" + activeClass + "'>" + wwPlayers[i] + "</th>";
                    litPlayerScores.Text += "<td class='playerScore'>" + wwPlayerScores[i] + "</td>";
                }

                litLifeline.Visible = false;
                Geography  geography      = new Geography();
                int        effectiveLevel = (int)Math.Ceiling((decimal)gameLevel / 4);
                List <int> prevDestList   = (List <int>)Session["wwPrevDestList"];
                DataRow    drDestination  = geography.GetRandomWWDestination(effectiveLevel);
                string     strId          = drDestination["id"].ToString();
                int        intId          = Convert.ToInt32(strId);
                prevDestList.Add(intId);
                string strA2          = drDestination["a2"].ToString();
                string strCountry     = drDestination["country"].ToString();
                string strLevel       = drDestination["level"].ToString();
                string strName        = drDestination["destination"].ToString();
                string strDescription = drDestination["description"].ToString();
                int[]  intArrLifeline = RandomIntegerArray(lifelineCount);
                string strLifelines   = string.Join("|", Array.ConvertAll <int, String>(intArrLifeline, Convert.ToString));

                Session["wwid"]           = strId;
                Session["wwPrevDestList"] = prevDestList;
                Session["wwa2"]           = strA2;
                Session["wwcountry"]      = strCountry;
                //Session["wwlevel"] = strLevel;
                Session["wwname"]        = strName;
                Session["wwdescription"] = strDescription;
                Session["wwlifelines"]   = strLifelines;
                Session["wwllIndex"]     = 0;
                destName.Text            = Session["wwlevel"].ToString() + ". " + strName;
                destDescription.Text     = strDescription;
                //destImg.Text = "<img src=\"" + "images/destimages/" + strA2 + "/" + strLevel + "-" + strName.Replace(" ", "-").Replace(".", "") + ".jpg\" class=\"destImg\">";
                destImg.Text = "<img src=\"" + "images/destimages/" + strA2 + "/" + drDestination["imagefilename"].ToString() + "\" class=\"destImg\">";
            }
        }
        btnLifeline.Visible = true;
        btnNext.Visible     = false;
    }