Пример #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();
            }
        }
Пример #2
0
        public string GetGameboardPath(Patron patron, int programGameId)
        {
            var patronPoints       = PatronPoints.GetTotalPatronPoints(patron.PID);
            var programGameLevelDs = ProgramGameLevel.GetAll(programGameId);

            int normalLevelTotalPoints = 0;

            for (var i = 0; i < programGameLevelDs.Tables[0].Rows.Count; i++)
            {
                normalLevelTotalPoints +=
                    Convert.ToInt32(programGameLevelDs.Tables[0].Rows[i]["PointNumber"]);
            }
            var onBonusLevel = (patronPoints > normalLevelTotalPoints);

            var gameboardPath = onBonusLevel
                ? string.Format(BaseBonusGameBoardPath, programGameId)
                : string.Format(BaseGameBoardPath, programGameId);

            if (!File.Exists(HttpContext.Current.Server.MapPath(gameboardPath)))
            {
                return(null);
            }

            return(gameboardPath);
        }
Пример #3
0
        public string GetMGIDs(Patron patron, Programs pgm, ProgramGame gm, int StartingPoints, int defMGID = 0, int whichMinigames = 1)
        {
            //Tally up the points
            //var level = 0;
            //var points = 0;
            var    bonus       = false;
            string ret         = defMGID == 0 ? "" : defMGID.ToString();
            var    prefix1     = whichMinigames == 1 ? "1" : "2";
            var    prefixBonus = bonus ? "Bonus" : "";

            if (pgm.ProgramGameID > 0)
            {
                // only if we have a game we can earn badges by reading ....
                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)
                {
                    prefixBonus = string.Empty;   // first do all non bonus levels
                    // if we are on the bonus, we have access to all of them
                    for (var i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        var MGIDfield = string.Format("Minigame{0}ID{1}", prefix1, prefixBonus);
                        if (Convert.ToInt32(ds.Tables[0].Rows[i][MGIDfield]) != 0)
                        {
                            ret = string.Format("{0}{1}{2}", ret, (ret.Length > 0 ? "," : ""), Convert.ToInt32(ds.Tables[0].Rows[i][MGIDfield]));
                        }
                    }
                    rp = StartingPoints - normalLevelTotalPoints;
                }

                prefixBonus = bonus ? "Bonus" : "";
                // we have not tallied the bonus levels yet, or if not on bonus mode we have not tallied the regular levels 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;
                    }
                    var MGIDfield = string.Format("Minigame{0}ID{1}", prefix1, prefixBonus);
                    if (Convert.ToInt32(ds.Tables[0].Rows[i][MGIDfield]) != 0)
                    {
                        ret = string.Format("{0}{1}{2}", ret, (ret.Length > 0 ? "," : ""), Convert.ToInt32(ds.Tables[0].Rows[i][MGIDfield]));
                    }
                }
            }
            return(ret);
        }
        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);
        }
        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++;
                }
            }
        }
        public string GameBoardImage()
        {
            var pp = PatronPoints.GetTotalPatronPoints(((Patron)Session["Patron"]).PID);;     //pp = patron points

            // -------------------------------------------
            if (Request["p"] != null)
            {
                int.TryParse(Request["p"].ToString(), out pp);
            }
            // -------------------------------------------

            var ds = ProgramGameLevel.GetAll(GetGame().PGID);
            var normalLevelTotalPoints = GetGameCompletionPoints(ds);
            var bonus = (pp > normalLevelTotalPoints);

            if (bonus)
            {
                return(GameBoardBonusImage);
            }
            return(string.Format("/images/Games/Board/{0}.png", GetGame().PGID.ToString()));
        }
Пример #7
0
        protected void DvItemCommand(object sender, DetailsViewCommandEventArgs e)
        {
            string returnURL = "~/ControlRoom/Modules/Setup/ProgramGameLevelList.aspx?PGID=" + PGID.Text;

            if (e.CommandName.ToLower() == "back")
            {
                Response.Redirect(returnURL);
            }
            if (e.CommandName.ToLower() == "refresh")
            {
                try
                {
                    odsData.DataBind();
                    dv.DataBind();
                    dv.ChangeMode(DetailsViewMode.Edit);

                    var masterPage = (IControlRoomMaster)Master;
                    if (masterPage != null)
                    {
                        masterPage.PageMessage = SRPResources.RefreshOK;
                    }
                }
                catch (Exception ex)
                {
                    var masterPage = (IControlRoomMaster)Master;
                    masterPage.PageError = String.Format(SRPResources.ApplicationError1, ex.Message);
                }
            }
            if (e.CommandName.ToLower() == "add" || e.CommandName.ToLower() == "addandback")
            {
                try
                {
                    var obj = new ProgramGameLevel();
                    obj.PGID = FormatHelper.SafeToInt(PGID.Text);

                    obj.LevelNumber = -1;// FormatHelper.SafeToInt(((TextBox)((DetailsView)sender).FindControl("LevelNumber")).Text);
                    obj.LocationX   = FormatHelper.SafeToInt(((TextBox)((DetailsView)sender).FindControl("LocationX")).Text);
                    obj.LocationY   = FormatHelper.SafeToInt(((TextBox)((DetailsView)sender).FindControl("LocationY")).Text);
                    obj.PointNumber = FormatHelper.SafeToInt(((TextBox)((DetailsView)sender).FindControl("PointNumber")).Text);

                    obj.Minigame1ID  = FormatHelper.SafeToInt(((DropDownList)((DetailsView)sender).FindControl("Minigame1ID")).SelectedValue);
                    obj.Minigame2ID  = FormatHelper.SafeToInt(((DropDownList)((DetailsView)sender).FindControl("Minigame2ID")).SelectedValue);
                    obj.AwardBadgeID = FormatHelper.SafeToInt(((DropDownList)((DetailsView)sender).FindControl("AwardBadgeID")).SelectedValue);

                    obj.LocationXBonus    = FormatHelper.SafeToInt(((TextBox)((DetailsView)sender).FindControl("LocationXBonus")).Text);
                    obj.LocationYBonus    = FormatHelper.SafeToInt(((TextBox)((DetailsView)sender).FindControl("LocationYBonus")).Text);
                    obj.Minigame1IDBonus  = FormatHelper.SafeToInt(((DropDownList)((DetailsView)sender).FindControl("Minigame1IDBonus")).SelectedValue);
                    obj.Minigame2IDBonus  = FormatHelper.SafeToInt(((DropDownList)((DetailsView)sender).FindControl("Minigame2IDBonus")).SelectedValue);
                    obj.AwardBadgeIDBonus = FormatHelper.SafeToInt(((DropDownList)((DetailsView)sender).FindControl("AwardBadgeIDBonus")).SelectedValue);

                    obj.AddedDate   = DateTime.Now;
                    obj.AddedUser   = ((SRPUser)Session[SessionData.UserProfile.ToString()]).Username; //"N/A";  // Get from session
                    obj.LastModDate = obj.AddedDate;
                    obj.LastModUser = obj.AddedUser;

                    if (obj.IsValid(BusinessRulesValidationMode.INSERT))
                    {
                        obj.Insert();
                        if (e.CommandName.ToLower() == "addandback")
                        {
                            Response.Redirect(returnURL);
                        }

                        lblPK.Text = obj.PGLID.ToString();

                        odsData.DataBind();
                        dv.DataBind();
                        dv.ChangeMode(DetailsViewMode.Edit);

                        var masterPage = (IControlRoomMaster)Master;
                        masterPage.PageMessage = SRPResources.AddedOK;
                    }
                    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);
                        masterPage.PageError = message;
                    }
                }
                catch (Exception ex)
                {
                    var masterPage = (IControlRoomMaster)Master;
                    masterPage.PageError = String.Format(SRPResources.ApplicationError1, ex.Message);
                }
            }
            if (e.CommandName.ToLower() == "save" || e.CommandName.ToLower() == "saveandback")
            {
                try
                {
                    var obj = new ProgramGameLevel();
                    int pk  = int.Parse(lblPK.Text);
                    obj.Fetch(pk);

                    //obj.PGID = FormatHelper.SafeToInt(((TextBox)((DetailsView)sender).FindControl("PGID")).Text);
                    //obj.LevelNumber = FormatHelper.SafeToInt(((TextBox)((DetailsView)sender).FindControl("LevelNumber")).Text);
                    obj.LocationX   = FormatHelper.SafeToInt(((TextBox)((DetailsView)sender).FindControl("LocationX")).Text);
                    obj.LocationY   = FormatHelper.SafeToInt(((TextBox)((DetailsView)sender).FindControl("LocationY")).Text);
                    obj.PointNumber = FormatHelper.SafeToInt(((TextBox)((DetailsView)sender).FindControl("PointNumber")).Text);

                    obj.Minigame1ID  = FormatHelper.SafeToInt(((DropDownList)((DetailsView)sender).FindControl("Minigame1ID")).SelectedValue);
                    obj.Minigame2ID  = FormatHelper.SafeToInt(((DropDownList)((DetailsView)sender).FindControl("Minigame2ID")).SelectedValue);
                    obj.AwardBadgeID = FormatHelper.SafeToInt(((DropDownList)((DetailsView)sender).FindControl("AwardBadgeID")).SelectedValue);

                    obj.LocationXBonus    = FormatHelper.SafeToInt(((TextBox)((DetailsView)sender).FindControl("LocationXBonus")).Text);
                    obj.LocationYBonus    = FormatHelper.SafeToInt(((TextBox)((DetailsView)sender).FindControl("LocationYBonus")).Text);
                    obj.Minigame1IDBonus  = FormatHelper.SafeToInt(((DropDownList)((DetailsView)sender).FindControl("Minigame1IDBonus")).SelectedValue);
                    obj.Minigame2IDBonus  = FormatHelper.SafeToInt(((DropDownList)((DetailsView)sender).FindControl("Minigame2IDBonus")).SelectedValue);
                    obj.AwardBadgeIDBonus = FormatHelper.SafeToInt(((DropDownList)((DetailsView)sender).FindControl("AwardBadgeIDBonus")).SelectedValue);

                    obj.LastModDate = DateTime.Now;
                    obj.LastModUser = ((SRPUser)Session[SessionData.UserProfile.ToString()]).Username;  //"N/A";  // Get from session

                    if (obj.IsValid(BusinessRulesValidationMode.UPDATE))
                    {
                        obj.Update();
                        if (e.CommandName.ToLower() == "saveandback")
                        {
                            Response.Redirect(returnURL);
                        }

                        odsData.DataBind();
                        dv.DataBind();
                        dv.ChangeMode(DetailsViewMode.Edit);

                        var masterPage = (IControlRoomMaster)Master;
                        masterPage.PageMessage = SRPResources.SaveOK;
                    }
                    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);
                        masterPage.PageError = message;
                    }
                }
                catch (Exception ex)
                {
                    var masterPage = (IControlRoomMaster)Master;
                    masterPage.PageError = String.Format(SRPResources.ApplicationError1, ex.Message);
                }
            }
        }
Пример #8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var patron = Session[SessionKey.Patron] as Patron;

            if (patron == null)
            {
                Response.Redirect("~");
            }

            Programs    pg = null;
            ProgramGame gm = null;
            var         pp = 0;

            try {
                pg = Programs.FetchObject(patron.ProgID);
                gm = GetGame(patron);
                pp = PatronPoints.GetTotalPatronPoints(patron.PID);
            } catch {
                pg = null;
                gm = null;
            }
            if (pg == null || gm == null)
            {
                Response.Redirect(Server.MapPath("~/images/game_map_icon.png"));
            }

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

            var squareSize = width / numSquares;

            width = height = squareSize * numSquares;

            var backImageFile   = Server.MapPath(new Logic.Game().GetGameboardPath(patron, gm.PGID));
            var stampImageFile  = Server.MapPath(string.Format(StampBasePath, gm.PGID));
            var avatarImageFile = Server.MapPath(string.Format(AvatarBasePath, patron.AvatarID));

            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(patron).PGID);


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


            // in bonus levels if we have more points accumulated than the total normal level points
            var bonus        = (pp > normalLevelTotalPoints);
            var bonusPostfix = (bonus ? "Bonus" : "");
            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(patron).BonusLevelPointMultiplier : 1.00m);
                var levelPoints = Convert.ToInt32(Convert.ToInt32(ds.Tables[0].Rows[i]["PointNumber"]) * multiplier);

                var locX = Convert.ToInt32(ds.Tables[0].Rows[i]["LocationX" + bonusPostfix]) - 1;
                var locY = Convert.ToInt32(ds.Tables[0].Rows[i]["LocationY" + bonusPostfix]) - 1;
                rp = rp - levelPoints;
                if (rp < 0)
                {
                    if (avatarImage != null)
                    {
                        newGraphic.DrawImage(avatarImage, locX * squareSize, locY * squareSize, squareSize, squareSize);
                    }
                    break;
                }
                else
                {
                    if (stampImage != null)
                    {
                        newGraphic.DrawImage(stampImage, locX * squareSize, locY * squareSize, squareSize, squareSize);
                    }
                }
            }



            Response.ContentType = "image/png";
            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();
        }
        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();
        }
Пример #10
0
        protected void GvRowCommand(object sender, GridViewCommandEventArgs e)
        {
            string editpage = "~/ControlRoom/Modules/Setup/ProgramGameLevelAddEdit.aspx";

            if (e.CommandName.ToLower() == "moveup")
            {
                var key = Convert.ToInt32(e.CommandArgument);
                DAL.ProgramGameLevel.MoveUp(key);
                var masterPage = (IControlRoomMaster)Master;
                masterPage.PageMessage = "Level Moved Up!";
                LoadData();
            }

            if (e.CommandName.ToLower() == "movedn")
            {
                var key = Convert.ToInt32(e.CommandArgument);
                DAL.ProgramGameLevel.MoveDn(key);
                var masterPage = (IControlRoomMaster)Master;
                masterPage.PageMessage = "Level Moved Down";
                LoadData();
            }

            if (e.CommandName.ToLower() == "addrecord")
            {
                Response.Redirect(editpage + "?PK2=" + PGID.SelectedValue);
            }
            if (e.CommandName.ToLower() == "editrecord")
            {
                int key = Convert.ToInt32(e.CommandArgument);
                Response.Redirect(String.Format("{0}?PK={1}", editpage, key));
            }
            if (e.CommandName.ToLower() == "deleterecord")
            {
                var key = Convert.ToInt32(e.CommandArgument);
                try
                {
                    var obj = new ProgramGameLevel();
                    if (obj.IsValid(BusinessRulesValidationMode.DELETE))
                    {
                        ProgramGameLevel.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);
                    }
                }
            }
        }
Пример #11
0
        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);
        }