예제 #1
0
 public static string CreateImage(gbrainy.Core.Main.Game game, int i)
 {
     string file = images_dir + "/" + i.ToString () + ".png";
     GameImage image = new GameImage (game);
     image.CreateImage (file);
     return file;
 }
예제 #2
0
파일: Game.aspx.cs 프로젝트: GNOME/gbrainy
        private void Page_Load(Object sender, EventArgs e)
        {
            // If the Language has not been set the user has a expired
            // session or does not come from the main page
            if (String.IsNullOrEmpty (WebSession.LanguageCode))
            {
                Response.Redirect ("/");
                return;
            }

            if (IsPostBack == false)
                InitPage ();

            Logger.Debug ("Game.Page_Load. Page load starts. Session ID {0}, IsPostBack {1}", Session.SessionID,
                IsPostBack);

            HtmlForm form = (HtmlForm) Master.FindControl ("main_form");
            form.DefaultButton = answer_button.UniqueID;

            translations = new TranslationsWeb ();
            translations.Language = WebSession.LanguageCode;

            string answer = Request.QueryString ["answer"];
            if (IsPostBack == false && string.IsNullOrEmpty (answer) == false)
            {
                ProcessAnswer (answer);
            }

            if (WebSession.GameState == null)
            {
                Logger.Debug ("Game.Page_Load creating new session");
                session = new gbrainy.Core.Main.GameSession (translations);
                session.GameManager = CreateManager ();
             	session.PlayList.Difficulty = gbrainy.Core.Main.GameDifficulty.Medium;
                session.PlayList.GameType = gbrainy.Core.Main.GameSession.Types.LogicPuzzles |
                    gbrainy.Core.Main.GameSession.Types.Calculation |
                    gbrainy.Core.Main.GameSession.Types.VerbalAnalogies;

                session.New ();
                WebSession.GameState = session;
                Global.TotalGamesSessions++;

                _game = GetNextGame ();
                UpdateGame ();

                // If the first time that loads this does not have a session
                // send the user to the home page
                //Logger.Debug ("New Session, redirecting to Default.aspx");
                //Response.Redirect ("Default.aspx");
            } else if (WebSession.GameState != null && WebSession.GameState.Status == GameSession.SessionStatus.Finished)
            {
                // Finished game
                image = new GameImage (null);
                game_image.ImageUrl = CreateImage (WebSession);
                answer_button.Enabled = false;
                answer_textbox.Text = string.Empty;
                answer_textbox.Enabled = false;
                nextgame_link.Enabled = false;
                endgames_button.Enabled = false;
                UpdateGame ();
            }
            else {
                session = WebSession.GameState;

                if (_game == null)
                    _game = WebSession.GameState.CurrentGame;

                UpdateGame ();
            }

            if (IsPostBack == false)
                SetText ();

            if (IsPostBack == true) {
                Logger.Debug ("Game.Page_Load. Ignoring postback");
                return;
            }

            Logger.Debug ("Game.Page_Load. Page load completed");
        }
예제 #3
0
파일: Game.aspx.cs 프로젝트: GNOME/gbrainy
        void UpdateGame()
        {
            if (_game == null)
                return;

            status.Text = session.StatusText;
            question.Text = _game.Question;

            image = new GameImage (_game);
            game_image.ImageUrl = CreateImage (WebSession);

            areas_repeater.DataSource = image.GetShapeAreas ();
            areas_repeater.DataBind ();
        }
예제 #4
0
        private void Page_Load(Object sender, EventArgs e)
        {
            // If the Language has not been set the user has a expired
            // session or does not come from the main page
            if (String.IsNullOrEmpty(WebSession.LanguageCode))
            {
                Response.Redirect("/");
                return;
            }

            if (IsPostBack == false)
            {
                InitPage();
            }

            Logger.Debug("Game.Page_Load. Page load starts. Session ID {0}, IsPostBack {1}", Session.SessionID,
                         IsPostBack);

            HtmlForm form = (HtmlForm)Master.FindControl("main_form");

            form.DefaultButton = answer_button.UniqueID;

            translations          = new TranslationsWeb();
            translations.Language = WebSession.LanguageCode;

            string answer = Request.QueryString ["answer"];

            if (IsPostBack == false && string.IsNullOrEmpty(answer) == false)
            {
                ProcessAnswer(answer);
            }

            if (WebSession.GameState == null)
            {
                Logger.Debug("Game.Page_Load creating new session");
                session                     = new gbrainy.Core.Main.GameSession(translations);
                session.GameManager         = CreateManager();
                session.PlayList.Difficulty = gbrainy.Core.Main.GameDifficulty.Medium;
                session.PlayList.GameType   = gbrainy.Core.Main.GameSession.Types.LogicPuzzles |
                                              gbrainy.Core.Main.GameSession.Types.Calculation |
                                              gbrainy.Core.Main.GameSession.Types.VerbalAnalogies;

                session.New();
                WebSession.GameState = session;
                Global.TotalGamesSessions++;

                _game = GetNextGame();
                UpdateGame();

                // If the first time that loads this does not have a session
                // send the user to the home page
                //Logger.Debug ("New Session, redirecting to Default.aspx");
                //Response.Redirect ("Default.aspx");
            }
            else if (WebSession.GameState != null && WebSession.GameState.Status == GameSession.SessionStatus.Finished)
            {
                // Finished game
                image = new GameImage(null);
                game_image.ImageUrl     = CreateImage(WebSession);
                answer_button.Enabled   = false;
                answer_textbox.Text     = string.Empty;
                answer_textbox.Enabled  = false;
                nextgame_link.Enabled   = false;
                endgames_button.Enabled = false;
                UpdateGame();
            }
            else
            {
                session = WebSession.GameState;

                if (_game == null)
                {
                    _game = WebSession.GameState.CurrentGame;
                }

                UpdateGame();
            }


            if (IsPostBack == false)
            {
                SetText();
            }

            if (IsPostBack == true)
            {
                Logger.Debug("Game.Page_Load. Ignoring postback");
                return;
            }

            Logger.Debug("Game.Page_Load. Page load completed");
        }