示例#1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //I used the MSDN docs to learn about sessions, found here:
        //https://msdn.microsoft.com/en-us/library/ms178581.aspx

        //I also used StackOverflow to learn about checking if session data exists, found here:
        //https://stackoverflow.com/questions/12971966/cant-detect-whether-session-variable-exists?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa

        //we need to initialize a gameboard
        FloodItBoard game;

        //need to check if there are additional parameters to load in
        if (System.Web.HttpContext.Current.Session["CustomGameParameters"] != null)
        {
            //we need to grab the board size
            int sizeX = (int)System.Web.HttpContext.Current.Session["sizeX"];
            int sizeY = (int)System.Web.HttpContext.Current.Session["sizeY"];
            //the random seed
            int randomSeed = (int)System.Web.HttpContext.Current.Session["randomSeed"];
            game = new FloodItBoard(sizeX, sizeY, randomSeed);
            //now we set the parameter marker to null, so that when the page reloads, we don't reset the object
            System.Web.HttpContext.Current.Session["CustomGameParameters"] = null;
            //now that the game board has been created and initialized, we can put the game object in the session
            System.Web.HttpContext.Current.Session["gameboard"] = game;
        }

        //when the page loads, we need to see if the user has an incomplete game running
        else if (System.Web.HttpContext.Current.Session["gameboard"] == null)
        {
            //if there's no game board in the session, we need to make one

            //for now, just going to let the game board create its own seed, also going to init with a 8x8 board
            int dailySeed = DailySeedGenerator.GetDailySeed();
            game = new FloodItBoard(9, 9, dailySeed);
            //now that the game board has been created and initialized, we can put the game object in the session
            System.Web.HttpContext.Current.Session["gameboard"] = game;
        }

        //now that we've run the above checks, we can grab it from the session
        game = (FloodItBoard)System.Web.HttpContext.Current.Session["gameboard"];

        //we now need to set up the board
        GenerateTable();

        //we also need to set the score label to the score variable
        lblScoreField.Text = "" + game.GetScore();

        //finally, we'll check if the game has been completed to see if we should bring down the modal
        if (game.IsGameOver())
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModal();", true);
        }

        lblFinalScore.Text = game.GetScore().ToString();
    }
示例#2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //the task here is pretty simple, we just need to load in the scores and display them

        //we can get the daily scores by grabbing the daily seed and throwing it to the LeaderBoardFileLoader
        int dailySeed = DailySeedGenerator.GetDailySeed();

        //get the top ten scores for the daily seed
        Tuple <int, string, int, DateTime>[] dailyHighScores = LeaderBoardFileLoader.GetTopScores(dailySeed, 10);

        TableRow  row  = new TableRow();
        TableCell cell = new TableCell {
            Text = "Rank"
        };

        row.Cells.Add(cell);
        cell = new TableCell {
            Text = "Score"
        };
        row.Cells.Add(cell);
        cell = new TableCell {
            Text = "Initials"
        };
        row.Cells.Add(cell);

        tblDailyLeaderboard.Rows.Add(row);

        for (int i = 1; i <= dailyHighScores.Length; i++)
        {
            row = new TableRow();
            //getting the rank
            cell = new TableCell {
                Text = i.ToString()
            };
            row.Cells.Add(cell);
            //getting the score
            cell = new TableCell {
                Text = dailyHighScores[i - 1].Item1.ToString()
            };
            row.Cells.Add(cell);
            //getting the initials
            cell = new TableCell {
                Text = dailyHighScores[i - 1].Item2
            };
            row.Cells.Add(cell);

            tblDailyLeaderboard.Rows.Add(row);
        }

        //now we want to get the all time high scores
        Tuple <int, string, int, DateTime>[] allTimeHighScores = LeaderBoardFileLoader.GetAllTimeTopScores(10);

        //set the top labels for the table
        row  = new TableRow();
        cell = new TableCell {
            Text = "Rank"
        };
        row.Cells.Add(cell);
        cell = new TableCell {
            Text = "Score"
        };
        row.Cells.Add(cell);
        cell = new TableCell {
            Text = "Initials"
        };
        row.Cells.Add(cell);
        cell = new TableCell {
            Text = "Seed"
        };
        row.Cells.Add(cell);
        cell = new TableCell {
            Text = "Date"
        };
        row.Cells.Add(cell);

        tblAllTimeLeaderboard.Rows.Add(row);

        for (int i = 1; i <= allTimeHighScores.Length; i++)
        {
            row = new TableRow();

            //rank
            cell = new TableCell {
                Text = i.ToString()
            };
            row.Cells.Add(cell);
            //score
            cell = new TableCell {
                Text = dailyHighScores[i - 1].Item1.ToString()
            };
            row.Cells.Add(cell);
            //initials
            cell = new TableCell {
                Text = dailyHighScores[i - 1].Item2
            };
            row.Cells.Add(cell);
            //seed
            cell = new TableCell {
                Text = dailyHighScores[i - 1].Item3.ToString()
            };
            row.Cells.Add(cell);
            //date
            cell = new TableCell {
                Text = dailyHighScores[i - 1].Item4.ToString()
            };
            row.Cells.Add(cell);

            tblAllTimeLeaderboard.Rows.Add(row);
        }
    }