Inheritance: ITranslations
Example #1
0
        void CreateGames()
        {
            if (created_games == true)
                return;

            TranslationsWeb translations = new TranslationsWeb ();
            manager = Game.CreateManager ();
            GameImage.CreateDirectory (images_dir);

            GameLocator [] games;
            gbrainy.Core.Main.Game game;

            games = manager.AvailableGames;

            for (int i = 0; i < games.Length; i++)
            {
                if (games [i].IsGame == false)
                    continue;

                if (games [i].GameType == GameTypes.Memory)
                    continue;

                game = (gbrainy.Core.Main.Game) Activator.CreateInstance (games [i].TypeOf, true);
                game.Translations = translations;
                game.Variant = games [i].Variant;
                game.Begin ();
                string file = CreateImage (game, i);

                game_container.Add (new GameContainer (game.Question, game.AnswerText, file, game.TipString,
                                                        game_container.Count));
            }

            for (int i = 0; i < game_container.Count / elements_per_page; i++)
                nexts.Add (i);

            created_games = true;
        }
Example #2
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");
        }