Beispiel #1
0
        //public string ShowBoardWGrid(int PGID, int Board = 0)
        //{
        //    var tbl = "";
        //    var pg = ProgramGame.FetchObject(PGID);
        //    var rows = "";
        //    var size = 800;
        //    var cellSize = (int)(800/pg.BoardWidth);
        //    size = cellSize*pg.BoardWidth;
        //    var img = string.Format("<img src='/images/Games/Board/{0}{1}.png' style=' width: {2}px; height: {2}px;' width='{2}px' height='{2}px' />",
        //        (Board == 0 ? "" : "bonus_"), PGID, size);
        //    for (int i = 0; i < pg.BoardWidth; i++)
        //    {
        //        for (int j = 0; j < pg.BoardWidth; j++)
        //        {
        //            rows = string.Format("{0}<td style='font-size: 8px; overflow: hidden;' align='center' valign='middle' width='{1}px' height='{2}px' nowrap>X = {3}<br>Y = {4}</td>", rows, cellSize, cellSize - 1, j + 1, i + 1);
        //        }
        //        rows = string.Format("<tr>{0}</tr>", rows);
        //    }
        //    tbl = string.Format("{1}<table border=1 style='border-collapse: collapse; position: relative; top:-{2}px; width: {2}px; height: {2}px;' width='{2}px' height='{2}px'>{0}</table>", rows, img, size);

        //    return tbl;
        //}

        protected void Page_Load(object sender, EventArgs e)
        {
            MasterPage.RequiredPermission = 4300;
            MasterPage.IsSecure           = true;
            MasterPage.PageTitle          = string.Format("{0}", "Game Level Add / Edit");

            if (!IsPostBack)
            {
                SetPageRibbon(StandardModuleRibbons.SetupRibbon());

                lblPK.Text = Request["PK"];
                PGID.Text  = Request["PK2"];
                if (lblPK.Text.Length == 0 && PGID.Text == "")
                {
                    Response.Redirect("ProgramGameLevelList.aspx");
                }
                if (PGID.Text != "")
                {
                    var o = ProgramGame.FetchObject(int.Parse(PGID.Text));
                    lblGameName.Text = o.GameName;
                }
                if (lblPK.Text.Length == 0)
                {
                    dv.ChangeMode(DetailsViewMode.Insert);
                }
                else
                {
                    dv.ChangeMode(DetailsViewMode.Edit);
                    var o = ProgramGame.FetchObject(ProgramGameLevel.FetchObject(int.Parse(lblPK.Text)).PGID);
                    PGID.Text        = o.PGID.ToString();
                    lblGameName.Text = o.GameName;
                }
                Page.DataBind();
            }
        }
        protected void GvRowCommand(object sender, GridViewCommandEventArgs e)
        {
            string editpage = "~/ControlRoom/Modules/Setup/BoardGameAddEdit.aspx";

            if (e.CommandName.ToLower() == "addrecord")
            {
                Session["BGID"] = ""; Response.Redirect(editpage);
            }
            if (e.CommandName.ToLower() == "editrecord")
            {
                int key = Convert.ToInt32(e.CommandArgument);
                Session["BGID"] = key; Response.Redirect(editpage);
            }
            if (e.CommandName.ToLower() == "deleterecord")
            {
                var key = Convert.ToInt32(e.CommandArgument);
                try
                {
                    var obj = new ProgramGame();
                    if (obj.IsValid(BusinessRulesValidationMode.DELETE))
                    {
                        ProgramGame.FetchObject(key).Delete();

                        LoadData();
                        var masterPage = (IControlRoomMaster)Master;
                        if (masterPage != null)
                        {
                            masterPage.PageMessage = SRPResources.DeleteOK;
                        }
                    }
                    else
                    {
                        var    masterPage = (IControlRoomMaster)Master;
                        string message    = String.Format(SRPResources.ApplicationError1, "<ul>");
                        foreach (BusinessRulesValidationMessage m in obj.ErrorCodes)
                        {
                            message = string.Format(String.Format("{0}<li>{{0}}</li>", message), m.ErrorMessage);
                        }
                        message = string.Format("{0}</ul>", message);
                        if (masterPage != null)
                        {
                            masterPage.PageError = message;
                        }
                    }
                }
                catch (Exception ex)
                {
                    var masterPage = (IControlRoomMaster)Master;
                    if (masterPage != null)
                    {
                        masterPage.PageError = String.Format(SRPResources.ApplicationError1, ex.Message);
                    }
                }
            }
        }
        public ProgramGame GetGame(Patron patron)
        {
            if (ViewState["gm"] != null)
            {
                return(ViewState["gm"] as ProgramGame);
            }

            var pg = Programs.FetchObject(patron.ProgID);
            var gm = ProgramGame.FetchObject(pg.ProgramGameID);

            ViewState["gm"] = gm;
            return(gm);
        }
        public ProgramGame GetGame()
        {
            if (ViewState["gm"] != null)
            {
                return(ViewState["gm"] as ProgramGame);
            }

            var pg = Programs.FetchObject(int.Parse(Session["PatronProgramID"].ToString()));
            var gm = ProgramGame.FetchObject(pg.ProgramGameID);

            ViewState["gm"] = gm;
            return(gm);
        }
        public string  GetGameInfo(Patron patron, Programs pgm, int StartingPoints)
        {
            //Tally up the points
            //var level = 0;
            //var points = 0;
            var    bonus = false;
            string ret   = "";

            if (pgm.ProgramGameID > 0)
            {
                // only if we have a game we can earn badges by reading ....
                var gm = ProgramGame.FetchObject(pgm.ProgramGameID);
                var ds = ProgramGameLevel.GetAll(gm.PGID);

                var normalLevelTotalPoints = GetGameCompletionPoints(ds);
                var bonusLevelTotalPoints  = GetGameCompletionBonusPoints(ds, gm.BonusLevelPointMultiplier);

                bonus = (StartingPoints > normalLevelTotalPoints);

                // loop thru the levels to see where we are at ... before awarding the new points
                var rp = StartingPoints;   //remaining points
                if (bonus)
                {
                    // if we are on the bonus, we have access to all of them
                    for (var i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        ret = string.Format("{0}{1}{2}", ret, (ret.Length > 0 ? "," : ""),
                                            Convert.ToInt32(ds.Tables[0].Rows[i]["PGLID"]));
                    }
                    return(ret);
                }

                // we have not completed the bonus yet ....
                for (var i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    var multiplier  = (bonus ? gm.BonusLevelPointMultiplier : 1.00m);
                    var levelPoints = Convert.ToInt32(Convert.ToInt32(ds.Tables[0].Rows[i]["PointNumber"]) * multiplier);
                    rp = rp - levelPoints;
                    if (rp < 0)
                    {
                        return(ret);
                        //break;
                    }
                    ret = string.Format("{0}{1}{2}", ret, (ret.Length > 0 ? "," : ""),
                                        Convert.ToInt32(ds.Tables[0].Rows[i]["PGLID"]));
                }
            }
            return(ret);
        }
Beispiel #6
0
        public void LoadData()
        {
            var patron = (Patron)Session["Patron"];

            int totalPoints = PatronPoints.GetTotalPatronPoints(patron.PID);

            lblPoints.Text = totalPoints.ToInt();
            var pgm = Programs.FetchObject(patron.ProgID);

            if (pgm.ProgramGameID > 0)
            {
                if (ProgramGame.FetchObject(pgm.ProgramGameID) != null)
                {
                    LoadNextLevelInfo(patron, pgm, totalPoints);
                }
            }


            int readingPoints             = PatronPoints.GetPatronReadingPoints(patron.PID);
            RegistrationSettings settings = RegistrationSettings.FetchObject(patron.TenID);

            if (settings.Goal_Show)
            {
                int totalGoal = patron.GoalCache;

                int percent = 0;

                /* avoid divide by zero */
                if (totalGoal > 0)
                {
                    percent = (readingPoints * 100) / totalGoal;
                }

                String percentString = $"{percent}%";
                lblPercentGoal.Text = percentString;


                /* display over 100% in label, but do not allow bar to extend outside of bounds */
                int    widthPercent       = Math.Min(percent, 100);
                String widthPercentString = $"{widthPercent}%";

                divGoalProgressBar.Style["width"] = widthPercentString;
            }
            else
            {
                divGoalProgress.Visible = false;
            }
        }
        public void LoadData()
        {
            var patron = (Patron)Session["Patron"];

            int tp = PatronPoints.GetTotalPatronPoints(patron.PID);

            lblPoints.Text = tp.ToInt();
            var pgm = Programs.FetchObject(patron.ProgID);

            if (pgm.ProgramGameID > 0)
            {
                if (ProgramGame.FetchObject(pgm.ProgramGameID) != null)
                {
                    LoadNextLevelInfo(patron, pgm, tp);
                }
            }
        }
        public void GetGameInfo(Patron patron, Programs pgm, int StartingPoints, out int level, out int points, out bool bonus)
        {
            //Tally up the points
            level  = 0;
            points = 0;
            bonus  = false;
            if (pgm.ProgramGameID > 0)
            {
                // only if we have a game we can earn badges by reading ....
                var gm = ProgramGame.FetchObject(pgm.ProgramGameID);
                var ds = ProgramGameLevel.GetAll(gm.PGID);

                var normalLevelTotalPoints = GetGameCompletionPoints(ds);
                var bonusLevelTotalPoints  = GetGameCompletionBonusPoints(ds, gm.BonusLevelPointMultiplier);

                bonus = (StartingPoints > normalLevelTotalPoints);

                // loop thru the levels to see where we are at ... before awarding the new points
                var rp = StartingPoints;   //remaining points
                if (bonus)
                {
                    // if we are on the bonus, eliminate the "fully completed boards/levels) and then see what the remainder of the points is.
                    rp    = rp - normalLevelTotalPoints;
                    level = ds.Tables[0].Rows.Count + 1;   // completed all the levels for the "normal"

                    level = level + (int)((int)rp / (int)bonusLevelTotalPoints) * (ds.Tables[0].Rows.Count + 1);

                    rp = rp % bonusLevelTotalPoints;
                }

                for (var i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    var multiplier  = (bonus ? gm.BonusLevelPointMultiplier : 1.00m);
                    var levelPoints = Convert.ToInt32(Convert.ToInt32(ds.Tables[0].Rows[i]["PointNumber"]) * multiplier);
                    rp = rp - levelPoints;
                    if (rp < 0)
                    {
                        points = -rp;
                        break;
                    }
                    level++;
                }
            }
        }
Beispiel #9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["Patron"] == null)
                {
                    Response.Redirect("/");
                }

                var patron   = (Patron)Session["Patron"];
                var pgm      = Programs.FetchObject(patron.ProgID);
                int tp       = PatronPoints.GetTotalPatronPoints(patron.PID);
                var gm       = ProgramGame.FetchObject(pgm.ProgramGameID);
                var defMGID1 = 0;
                var defMGID2 = 0;
                if (gm != null)
                {
                    defMGID1 = gm.Minigame1ID;
                    defMGID2 = gm.Minigame2ID;
                }

                /*
                 * string LevelIDs = GetGameInfo(patron, pgm, gm, tp);
                 *
                 * var getMinigames0 = DAL.Programs.GetProgramMinigames(LevelIDs, 0, defMGID1);
                 * rptrx1.DataSource = getMinigames0;
                 * rptrx1.DataBind();
                 * var getMinigames1 = DAL.Programs.GetProgramMinigames(LevelIDs, 1, defMGID2);
                 * rptrx2.DataSource = getMinigames1;
                 * rptrx2.DataBind();
                 */

                var getMinigames0 = DAL.Minigame.GetMinigamesList(GetMGIDs(patron, pgm, gm, tp, defMGID1, 1));
                rptrx1.DataSource = getMinigames0;
                rptrx1.DataBind();
                var getMinigames1 = DAL.Minigame.GetMinigamesList(GetMGIDs(patron, pgm, gm, tp, defMGID2, 2));
                rptrx2.DataSource = getMinigames1;
                rptrx2.DataBind();

                NoAdventures.Visible = getMinigames0.Tables[0].Rows.Count == 0 &&
                                       getMinigames1.Tables[0].Rows.Count == 0;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            var pg = new Programs();
            var gm = new ProgramGame();
            var pp = 0;

            try {
                pg = Programs.FetchObject(int.Parse(Session["PatronProgramID"].ToString()));
                gm = ProgramGame.FetchObject(pg.ProgramGameID);
                pp = PatronPoints.GetTotalPatronPoints(((Patron)Session["Patron"]).PID);
            }
            catch
            {
                Response.Redirect("/images/game_map_icon.png");
            }

            var PID        = pg.PID;
            var numSquares = gm.BoardWidth;
            var width      = 800;
            var height     = 800;

            //var AID = 5;

            var squareSize = width / numSquares;

            width = height = squareSize * numSquares;

            var backImageFile   = Server.MapPath(GameBoardImage());
            var stampImageFile  = Server.MapPath(GameBoardStamp);
            var avatarImageFile = Server.MapPath(GameBoardAvatarStamp);

            var newBmp = new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);

            System.Drawing.Image avatarImage = null;
            System.Drawing.Image stampImage  = null;;
            try
            {
                newBmp.SetResolution(72, 72);
                newBmp.MakeTransparent();
            }catch {}

            var newGraphic = System.Drawing.Graphics.FromImage(newBmp);

            try
            {
                newGraphic.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                newGraphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                var backImage = System.Drawing.Image.FromFile(backImageFile);
                newGraphic.DrawImage(backImage, 0, 0, width, height);
            }
            catch { }

            try
            {
                avatarImage = System.Drawing.Image.FromFile(avatarImageFile);
            }
            catch { }
            try
            {
                stampImage = System.Drawing.Image.FromFile(stampImageFile);
            }
            catch { }
            // ----------------------------------------------
            if (Request["p"] != null)
            {
                int.TryParse(Request["p"].ToString(), out pp);
            }
            // -------------------------------------------
            var ds = ProgramGameLevel.GetAll(GetGame().PGID);


            var normalLevelTotalPoints = GetGameCompletionPoints(ds);
            var bonusLevelTotalPoints  = GetGameCompletionBonusPoints(ds);


            // in bonus levels if we have more points accumulated than the total normal level points
            var bonus = (pp > normalLevelTotalPoints);
            var rp    = pp; //remaining points

            if (bonus)
            {
                // if we are on the bonus, eliminate the "fully completed boards/levels) and then see what the remainder of the points is.
                rp = rp - normalLevelTotalPoints;
                rp = rp % bonusLevelTotalPoints;
            }
            var idx = 0;

            // ----------------------------------------------

            for (var i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                idx++;
                var multiplier  = (bonus ? GetGame().BonusLevelPointMultiplier : 1.00m);
                var levelPoints = Convert.ToInt32(Convert.ToInt32(ds.Tables[0].Rows[i]["PointNumber"]) * multiplier);
                //var levelTd = (Convert.ToInt32(ds.Tables[0].Rows[i]["LocationY"]) - 1) * GameBoardWidth +
                //              Convert.ToInt32(ds.Tables[0].Rows[i]["LocationX"]);
                var locX = Convert.ToInt32(ds.Tables[0].Rows[i]["LocationX"]) - 1;
                var locY = Convert.ToInt32(ds.Tables[0].Rows[i]["LocationY"]) - 1;
                rp = rp - levelPoints;
                if (rp < 0)
                {
                    //ret = string.Format("{0}\r\n$(\"#Td{1}\").html(\"<img src='{2}' class='BoardSquareImg'/>\");", ret, levelTd, GameBoardAvatarStamp);
                    if (avatarImage != null)
                    {
                        newGraphic.DrawImage(avatarImage, locX * squareSize, locY * squareSize, squareSize, squareSize);
                    }
                    break;
                }
                else
                {
                    //ret = string.Format("{0}\r\n$(\"#Td{1}\").html(\"<img src='{2}' class='BoardSquareImg'/>\");", ret, levelTd, GameBoardStamp);
                    if (stampImage != null)
                    {
                        newGraphic.DrawImage(stampImage, locX * squareSize, locY * squareSize, squareSize, squareSize);
                    }
                }
            }



            Response.ContentType = "image/png";
            //Response.AppendHeader("Content-Disposition", "attachment; filename=GameLevelStatsReportResults.xlsx");
            EnableViewState = false;
            newBmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Png);

            if (stampImage != null)
            {
                stampImage.Dispose();
            }
            if (avatarImage != null)
            {
                avatarImage.Dispose();
            }
            newGraphic.Dispose();
            newBmp.Dispose();
            Response.End();
        }
        public Badge TallyPoints(Patron patron, Programs pgm, int StartingPoints, int EndingPoints, ref List <Badge> EarnedBadges)
        {
            Badge b = null;

            //Tally up the points and figure out if we need to award a badge.
            if (pgm.ProgramGameID > 0)
            {
                // only if we have a game we can earn badges by reading ....
                var gm = ProgramGame.FetchObject(pgm.ProgramGameID);
                var ds = ProgramGameLevel.GetAll(gm.PGID);

                var normalLevelTotalPoints = GetGameCompletionPoints(ds);
                var bonusLevelTotalPoints  = GetGameCompletionBonusPoints(ds, gm.BonusLevelPointMultiplier);

                var bonus = (StartingPoints > normalLevelTotalPoints);
                var bonusPostfix = (bonus ? "Bonus" : "");
                int BeforeLevel = 0, AfterLevel = 0;

                // loop thru the levels to see where we are at ... before awarding the new points
                var rp = StartingPoints;   //remaining points
                if (bonus)
                {
                    // if we are on the bonus, eliminate the "fully completed boards/levels) and then see what the remainder of the points is.
                    rp = rp - normalLevelTotalPoints;
                    rp = rp % bonusLevelTotalPoints;
                }

                for (var i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    var multiplier  = (bonus ? gm.BonusLevelPointMultiplier : 1.00m);
                    var levelPoints = Convert.ToInt32(Convert.ToInt32(ds.Tables[0].Rows[i]["PointNumber"]) * multiplier);
                    rp = rp - levelPoints;
                    if (rp < 0)
                    {
                        BeforeLevel = i;
                        break;
                    }
                }


                // loop thru the levels to see where we are at ... AFTER awarding the new points
                rp = EndingPoints;   //remaining points
                if (bonus)
                {
                    // if we are on the bonus, eliminate the "fully completed boards/levels) and then see what the remainder of the points is.
                    rp = rp - normalLevelTotalPoints;
                    rp = rp % bonusLevelTotalPoints;
                }
                for (var i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    var multiplier  = (bonus ? gm.BonusLevelPointMultiplier : 1.00m);
                    var levelPoints = Convert.ToInt32(Convert.ToInt32(ds.Tables[0].Rows[i]["PointNumber"]) * multiplier);
                    rp         = rp - levelPoints;
                    AfterLevel = i;
                    if (rp < 0)
                    {
                        break;
                    }
                    else
                    {
                        if (!((i + 1) < ds.Tables[0].Rows.Count))
                        {
                            AfterLevel = (i + 1);
                        }
                    }
                }

                if (BeforeLevel != AfterLevel)
                {
                    // completed the "beforeLevel" and moved up to the "AfterLevel" , so check if we need to award a badge
                    for (var i = BeforeLevel; i < AfterLevel; i++)
                    {
                        var badgeToAward = Convert.ToInt32(ds.Tables[0].Rows[i]["AwardBadgeID" + bonusPostfix]);
                        if (badgeToAward > 0)
                        {
                            b = Badge.GetBadge(badgeToAward);
                            EarnedBadges.Add(b);
                        }
                    }
                }
            }
            return(b);
        }