Inheritance: IDrawable, IDrawRequest, IMouseEvent
Ejemplo n.º 1
0
        static public 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);
        }
Ejemplo n.º 2
0
        public gbrainy.Core.Main.Game GetNextGame()
        {
            gbrainy.Core.Main.Game g = null;

            if (session.Status != gbrainy.Core.Main.GameSession.SessionStatus.Finished)
            {
                session.NextGame();
                g = session.CurrentGame;
            }
            return(g);
        }
Ejemplo n.º 3
0
        // Page Life-Cycle Events
        //
        // - Page_Load
        // - Control events
        // - Page_LoadComplete
        //
        private void Page_LoadComplete(Object sender, EventArgs e)
        {
            if (WebSession.GameState != null && WebSession.GameState.Status == GameSession.SessionStatus.Finished)
            {
                return;
            }

            if (WebSession.NextGame == true)
            {
                _game = GetNextGame();
                UpdateGame();
            }
            WebSession.NextGame = false;
        }
Ejemplo n.º 4
0
        public bool GeneratePdf(Game [] games, int games_page, string file)
        {
            int columns, rows;
            switch (games_page) {
            case 1:
                columns = 1;
                rows = 1;
                break;
            case 2:
                columns = 2;
                rows = 1;
                break;
            case 4:
                columns = 2;
                rows = 2;
                break;
            default:
                throw new InvalidOperationException ("Invalid games per page value");
            }

            try {

                PdfSurface pdf = new PdfSurface (file, page_width * columns, page_height * rows);

                if (pdf.Status != Status.Success)
                    return false;

                CairoContextEx cr = new CairoContextEx (pdf, "sans 12", 72);

                GenerateQuestions (cr, games, columns, rows);
                GenerateAnswers (cr, games, columns, rows);

                pdf.Finish ();
                ((IDisposable)cr).Dispose();
                return true;
            }
            catch (Exception e)
            {
                Console.WriteLine ("PdfExporter.GeneratePdf. Exception: {0}", e);
                return false;
            }
        }
Ejemplo n.º 5
0
        static void GenerateAnswers(CairoContextEx cr, Game [] games, int columns, int rows)
        {
            int x, y, page;
            string str;
            int column, row;
            const int space_lines = 80;

            x = y = page = 0;
            column = row = 0;

            // Draw solution title
            cr.SetPangoFontSize (20);
            cr.DrawStringWithWrapping (x + margin, y + margin,
                ServiceLocator.Instance.GetService <ITranslations> ().GetString ("Solutions"), width - margin);
            y += space_lines;
            cr.Stroke ();

            cr.SetPangoFontSize (12);
            cr.UseMarkup = true;
            for (int i = 0; i < games.Length; i++)
            {
                str = String.Format (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("Game #{0}. {1}"), i + 1, games[i].AnswerText);

                // Draw Solution
                cr.DrawStringWithWrapping (x + margin, y + margin, str, width - margin);
                cr.Stroke ();

                y += space_lines;

                // Next lateral page (right)
                if (y + space_lines >= page_height * (row + 1) && x + page_width < page_width * columns) {
                    column++;

                    x = column * page_width;
                    y = row * page_height;
                    page++;
                } else {
                    // No more space (right), new row
                    if (y + space_lines >= page_height * (row + 1) && x + page_width >= page_width * columns) {
                        row++;
                        column = 0;

                        x = column * page_width;
                        y = row * page_height;
                        page++;
                    }
                }

                if (page >= rows * columns) {
                    cr.ShowPage ();
                    page = x = y = 0;
                    column = row = 0;
                }
            }

            if (y > 0)
                cr.ShowPage ();
        }
Ejemplo n.º 6
0
        static void GenerateQuestions(CairoContextEx cr, Game [] games, int columns, int rows)
        {
            int x, y, page;
            Game puzzle;
            string str;

            x = y = page = 0;
            for (int i = 0; i < games.Length; i++)
            {
                puzzle = games [i];
                puzzle.Begin ();
                page++;

                cr.Save ();
                cr.Translate (x, y);
                cr.Rectangle (0, 0, width, height + question_height);
                cr.Clip ();

                // Translators: {0} is the game number and {1} the game question or answer
                // The number is used as reference when looking for the game solution in the PDF
                str = String.Format (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("Game #{0}. {1}"), i + 1, puzzle.Question);

                // Draw question
                cr.SetPangoFontSize (12);
                cr.UseMarkup = true;
                cr.DrawStringWithWrapping (margin, 10, str, width - margin);
                cr.Stroke ();
                cr.UseMarkup = false;

                // Draw from question_height up height since from 0 to question_height is the question
                // Translate adds always to previous matrix's transformation
                cr.Translate (0, question_height);
                puzzle.DrawPreview (cr, width, height, false);
                if (i == 0) {
                    cr.Save ();
                    cr.SetPangoFontSize (0.02);
                    cr.MoveTo (0.05, 0.95);
                    cr.ShowPangoText (String.Format (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("Created by gbrainy {0}"), Defines.VERSION));
                    cr.Stroke ();
                    cr.Restore ();
                }

                x += width + margin;
                if (x > width + margin) {
                    x = 0;
                    y += height + margin + question_height;
                }
                cr.Restore ();
                cr.Stroke ();

                if (page >= columns * rows) {
                    cr.ShowPage ();
                    page = x = y = 0;
                }
            }

            if (y > 0)
                cr.ShowPage ();
        }
Ejemplo n.º 7
0
        // Page Life-Cycle Events
        //
        // - Page_Load
        // - Control events
        // - Page_LoadComplete
        //
        private void Page_LoadComplete(Object sender, EventArgs e)
        {
            if (WebSession.GameState != null && WebSession.GameState.Status == GameSession.SessionStatus.Finished)
                return;

            if (WebSession.NextGame == true)
            {
                _game = GetNextGame ();
                UpdateGame ();
            }
            WebSession.NextGame = false;
        }
Ejemplo n.º 8
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");
        }
Ejemplo n.º 9
0
 public GameImage(gbrainy.Core.Main.Game game)
 {
     this.game = game;
 }
Ejemplo n.º 10
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");
        }
Ejemplo n.º 11
0
        void GeneratePdf(GameSession.Types types, int num_games, int gamespage, GameDifficulty difficulty, bool colorblind, string filename)
        {
            Game [] games;
            GameSession session;
            string msg;
            MessageType msg_type;

            games = new Game [num_games];
            session = new GameSession (Translations);
            session.GameManager = manager;
            session.PlayList.ColorBlind = colorblind;
            session.PlayList.Difficulty = difficulty;
            session.PlayList.GameType = types;

            for (int n = 0; n < num_games; n++)
            {
                games [n] = session.PlayList.GetPuzzle ();
                games [n].Translations = Translations;
            }

            if (pdfExporter.GeneratePdf (games, gamespage, filename) == true) {
                msg = Catalog.GetString ("The PDF file has been exported correctly.");
                msg_type = MessageType.Info;
            } else {
                msg = Catalog.GetString ("There was a problem generating the PDF file. The file has not been created.");
                msg_type = MessageType.Error;
            }

            // Notify operation result
            MessageDialog md = new MessageDialog (this, DialogFlags.Modal, msg_type, ButtonsType.Ok, msg);
            md.Run ();
            md.Destroy ();
        }
Ejemplo n.º 12
0
 public GameImage(gbrainy.Core.Main.Game game)
 {
     this.game = game;
 }