예제 #1
0
        List<int> play_list; // Play list for the Selected difficulty, game types

        #endregion Fields

        #region Constructors

        public GameSessionPlayList(GameManager manager)
        {
            this.manager = manager;
            play_list = new List <int> ();
            game_type = GameSession.Types.AllGames;
            difficulty = GameDifficulty.Medium;
            RandomOrder = true;
            dirty = true;
        }
예제 #2
0
파일: Game.aspx.cs 프로젝트: GNOME/gbrainy
        public static GameManager CreateManager()
        {
            if (manager != null)
                return manager;

            manager = new GameManager ();
            manager.LoadAssemblyGames (Defines.GAME_ASSEMBLY);
            manager.LoadVerbalAnalogies (System.IO.Path.Combine ("data/", Defines.VERBAL_ANALOGIES));
            manager.LoadGamesFromXml (System.IO.Path.Combine ("data/", "games.xml"));

            return manager;
        }
예제 #3
0
        public GameSession()
        {
            id = 0;
            game_manager = new GameManager ();
            game_time = TimeSpan.Zero;

            timer = new System.Timers.Timer ();
            timer.Elapsed += TimerUpdater;
            timer.Interval = (1 * 1000); // 1 second

            controler = new ViewsControler (this);
            Status = SessionStatus.NotPlaying;
            player_history = new PlayerHistory ();
            history = new GameSessionHistoryExtended ();
        }
예제 #4
0
        public void ColorBlind()
        {
            Game game;
            GameManager.GameLocator [] games;

            GameManager manager = new GameManager ();
            manager.GameType = GameSession.Types.AllGames;
            manager.ColorBlind = true;
            games = manager.AvailableGames;

            for (int i = 0; i < games.Length; i++)
            {
                game = (Game) manager.GetPuzzle ();
                Assert.AreEqual (false, game.UsesColors);
            }
        }
예제 #5
0
        public GameSession(ITranslations translations)
        {
            Translations = translations;
            id = 0;
            game_manager = new GameManager ();
            play_list = new GameSessionPlayList (game_manager);
            game_time = TimeSpan.Zero;

            timer = new System.Timers.Timer ();
            timer.Elapsed += TimerUpdater;
            timer.Interval = (1 * 1000); // 1 second

            controler = new ViewsControler (translations, this);
            Status = SessionStatus.NotPlaying;
            player_history = new PlayerHistory ();
            history = new GameSessionHistoryExtended ();
        }
예제 #6
0
        public void CustomGame()
        {
            const int game_cnt = 5; // number of games to pass as parameters
            CommandLine line;
            string [] args;
            GameManager.GameLocator [] games;
            GameManager gm = new GameManager ();
            StringBuilder game_list = new StringBuilder ();
            int [] candidates; // Stores the indexes of the games passed as parameters
            int cand_idx = 0;

            games = gm.AvailableGames;
            candidates = new int [game_cnt];

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

                Game game = (Game) Activator.CreateInstance (games[i].TypeOf, true);
                game.Variant = games[i].Variant;

                if (cand_idx > 0)
                    game_list.Append (CommandLine.GAME_SEPARATOR + " ");

                game_list.Append (game.Name);
                candidates [cand_idx++] = i;

                if (cand_idx >= game_cnt)
                    break;
            }

            args = new string [2];
            args [0] = "--customgame";
            args [1] = game_list.ToString ();

            line = new CommandLine (args);
            line.Parse ();

            Assert.AreEqual (cand_idx, line.PlayList.Length);

            cand_idx = 0;
            foreach (int idx in line.PlayList)
                Assert.AreEqual (idx, candidates [cand_idx++]);
        }
예제 #7
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;
        }
예제 #8
0
 public static void GameManagerPreload(GameManager gm)
 {
     gm.LoadAssemblyGames (Defines.GAME_ASSEMBLY);
     gm.LoadVerbalAnalogies (System.IO.Path.Combine (Defines.DATA_DIR, Defines.VERBAL_ANALOGIES));
     gm.LoadGamesFromXml (System.IO.Path.Combine (Defines.DATA_DIR, Defines.GAMES_FILE));
     gm.LoadPlugins ();
 }
예제 #9
0
        public PdfExportDialog(GameManager manager, ITranslations translations)
            : base(translations, "PdfExportDialog.ui", "pdfexportbox")
        {
            pdfExporter = new PdfExporter (translations);
            this.manager = manager;
            games_spinbutton.Value = 10;
            checkbox_logic.Active = checkbox_calculation.Active = checkbox_verbal.Active = true;

            // Use defaults from Preferences
             	switch ((GameDifficulty) Preferences.Get <int> (Preferences.DifficultyKey)) {
            case GameDifficulty.Easy:
                rb_easy.Active = rb_easy.HasFocus = true;
                break;
            case GameDifficulty.Medium:
                rb_medium.Active = rb_medium.HasFocus = true;
                break;
            case GameDifficulty.Master:
                rb_master.Active = rb_master.HasFocus = true;
                break;
            }
            // File selection
            string def_file;
            def_file = System.IO.Path.Combine (
                Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments),
                // Translators: default file name used when exporting PDF files (keep the pdf extension please)
                Catalog.GetString ("games.pdf"));

            file = new BrowseFile (hbox_file, def_file, true);

            FileFilter[] filters = new FileFilter [2];
            filters[0] = new FileFilter ();
            filters[0].AddPattern ("*.pdf");
            filters[0].Name = Catalog.GetString ("PDF files");

            filters[1] = new FileFilter ();
            filters[1].AddPattern ("*.*");
            filters[1].Name = Catalog.GetString ("All files");

            file.Filters = filters;

            ListStore layout_store = new ListStore (typeof (string), typeof (int)); // DisplayName, index to array
            CellRenderer layout_cell = new CellRendererText ();
            layout_combo.Model = layout_store;
            layout_combo.PackStart (layout_cell, true);
            layout_combo.SetCellDataFunc (layout_cell, ComboBoxCellFunc);

            int [] per_side = pdfExporter.PagesPerSide;

            for (int i = 0; i < per_side.Length; i++)
                layout_store.AppendValues (per_side[i].ToString (), per_side[i]);

            // Default value
            TreeIter iter;
            bool more = layout_store.GetIterFirst (out iter);
            while (more)
            {
                if ((int) layout_store.GetValue (iter, COLUMN_VALUE) == DEF_SIDEVALUE) {
                    layout_combo.SetActiveIter (iter);
                    break;
                }
                more = layout_store.IterNext (ref iter);
            }
        }
예제 #10
0
        void GeneratePdf(GameSession.Types types, int num_games, int gamespage, GameDifficulty difficulty, bool colorblind, string filename)
        {
            Game [] games;
            GameManager gm;
            string msg;
            MessageType msg_type;

            games = new Game [num_games];
            gm = new GameManager ();
            gm.ColorBlind = colorblind;
            gm.Difficulty = difficulty;
            GtkClient.GameManagerPreload (gm);
            gm.GameType = types;

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

            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 ();
        }
예제 #11
0
 public void Construct()
 {
     RegisterDefaultServices ();
     manager = new GameManager ();
 }
예제 #12
0
        public void XmlGames()
        {
            GameManager manager = new GameManager ();
            manager.GameType = GameSession.Types.AllGames;
            manager.LoadGamesFromXml ("test_games.xml");

            Assert.AreEqual (3, manager.AvailableGames.Length);
            int logic_variants = 0;
            int logic_games = 0;

            foreach (GameManager.GameLocator locator in manager.AvailableGames)
            {
                if (locator.GameType != GameTypes.LogicPuzzle)
                    continue;

                if (locator.IsGame == true)
                    logic_games++;
                else
                    logic_variants++;

            }
            Assert.AreEqual (2, logic_games);
            Assert.AreEqual (1, logic_variants);
        }
예제 #13
0
        public void ResetAvailableGames()
        {
            GameManager manager = new GameManager ();
            manager.GameType = GameSession.Types.AllGames;
            manager.LoadAssemblyGames ("gbrainy.Games.dll");
            Assert.AreNotEqual (0, manager.AvailableGames.Length);

            manager.ResetAvailableGames ();
            Assert.AreEqual (0, manager.AvailableGames.Length);
        }
예제 #14
0
파일: gbrainy.cs 프로젝트: GNOME/gbrainy
        public static void GameManagerPreload(GameManager gm)
        {
            gm.LoadAssemblyGames (Defines.GAME_ASSEMBLY);
            gm.LoadVerbalAnalogies (System.IO.Path.Combine (Defines.DATA_DIR, Defines.VERBAL_ANALOGIES));
            gm.LoadGamesFromXml (System.IO.Path.Combine (Defines.DATA_DIR, Defines.GAMES_FILE));

            if (Preferences.Get <bool> (Preferences.LoadPlugginsKey))
            {
                gm.LoadPlugins ();
                pluggins_loaded = true;
            }
        }
예제 #15
0
        void BuildPlayList(string [] names)
        {
            Dictionary <string, int> dictionary;
            GameManager.GameLocator [] games;
            GameManager gm = new GameManager ();
            GtkClient.GameManagerPreload (gm);
            games = gm.AvailableGames;

            // Create a hash to map from game name to locator
            dictionary = new Dictionary <string, int> (games.Length);
            for (int i = 0; i < games.Length; i++)
            {
                if (games[i].IsGame == false)
                    continue;

                Game game = (Game) Activator.CreateInstance (games[i].TypeOf, true);
                game.Variant = games[i].Variant;

                try
                {
                    dictionary.Add (game.Name.ToLower (), i);
                }
                catch (Exception e)
                {
                    Console.WriteLine ("gbrainy. Error adding {0} {1}", game.Name, e.Message);
                }
            }

            List <int> list = new List <int> (names.Length);

            for (int i = 0; i < names.Length; i++)
            {
                try
                {
                    list.Add (dictionary [names [i].ToLower ()]);
                }
                catch (KeyNotFoundException)
                {
                    Console.WriteLine ("gbrainy. Game [{0}] not found", names [i]);
                }
            }

            play_list = list.ToArray ();
        }
예제 #16
0
        void BuildPlayList(string [] names)
        {
            List <int> list = new List <int> ();
            GameLocator [] games;
            GameManager gm = new GameManager ();
            GtkClient.GameManagerPreload (gm);
            games = gm.AvailableGames;

            for (int i = 0; i < games.Length; i++)
            {
                Game game = (Game) Activator.CreateInstance (games[i].TypeOf, true);
                game.Translations = Translations;
                game.Variant = games[i].Variant;

                try
                {
                    for (int n = 0; n < names.Length; n++)
                    {
                        if (String.Compare (game.Name, names [n], StringComparison.OrdinalIgnoreCase) == 0)
                            list.Add (i);
                    }

                }
                catch (Exception e)
                {
                    Console.WriteLine ("CommandLine.BuildPlayList. Error adding {0} {1}", game.Name, e.Message);
                }
            }

            play_list = list.ToArray ();
        }
예제 #17
0
        void GameList()
        {
            GameLocator [] games;
            GameManager gm = new GameManager ();

            GtkClient.GameManagerPreload (gm);
            games = gm.AvailableGames;

            Console.WriteLine (Catalog.GetString ("List of available games"));

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

                Game game = (Game) Activator.CreateInstance (games[i].TypeOf, true);
                game.Translations = Translations;
                game.Variant = games[i].Variant;
                Console.WriteLine (" {0}", game.Name);
            }
        }
예제 #18
0
        public CustomGameDialog(GameManager manager)
            : base("CustomGameDialog.ui", "customgame")
        {
            Game game;

            selection_done = false;
            this.manager = manager;
            games = manager.AvailableGames;

            drawing_area = new GameDrawingArea ();
            drawing_area.UseSolutionArea = false;
            preview_vbox.Add (drawing_area);
            drawing_area.Visible = true;
            treeview.HeadersClickable = true;

            // Column: Game Name
            TreeViewColumn name_column = new TreeViewColumn (Catalog.GetString("Game Name"),
                new CellRendererText(), "text", 0);

            name_column.Expand = true;
            name_column.Clickable = true;
            name_column.Clicked += delegate (object sender, EventArgs args)
            {
                Gtk.SortType order;
                Gtk.TreeViewColumn column = (Gtk.TreeViewColumn) sender;

                if (column.SortOrder == Gtk.SortType.Ascending)
                    order = Gtk.SortType.Descending;
                else
                    order = Gtk.SortType.Ascending;

                column.SortOrder = order;
                games_store.SetSortColumnId (COL_NAME, order);
            };

            treeview.AppendColumn (name_column);

            // Column: Type
            TreeViewColumn type_column = new TreeViewColumn (Catalog.GetString("Type"),
                new CellRendererText(), "text", 1);

            type_column.Expand = true;
            treeview.AppendColumn (type_column);
            type_column.Clickable = true;
            type_column.Clicked += delegate (object sender, EventArgs args)
            {
                Gtk.SortType order;
                Gtk.TreeViewColumn column = (Gtk.TreeViewColumn) sender;

                if (column.SortOrder == Gtk.SortType.Ascending)
                    order = Gtk.SortType.Descending;
                else
                    order = Gtk.SortType.Ascending;

                column.SortOrder = order;
                games_store.SetSortColumnId (COL_TYPE, order);
            };

            // Column: Selected
            CellRendererToggle toggle_cell = new CellRendererToggle();
            TreeViewColumn toggle_column = new TreeViewColumn(Catalog.GetString("Selected"),
                toggle_cell, "active", COL_ENABLED);
            toggle_cell.Activatable = true;
            toggle_cell.Toggled += OnActiveToggled;
            toggle_column.Expand = false;
            treeview.CursorChanged += OnCursorChanged;
            treeview.AppendColumn (toggle_column);

            if (games_store == null) {
                games_store = new ListStore (typeof(string), typeof (string), typeof(bool), typeof (Game), typeof (int));

                games_store.SetSortFunc (0, new Gtk.TreeIterCompareFunc (GameSort));
                games_store.SetSortColumnId (COL_TYPE, SortType.Ascending);

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

                    game = (Game) Activator.CreateInstance (games [i].TypeOf, true);
                    game.Variant = games [i].Variant;
                    type = GameTypesDescription.GetLocalized (game.Type);
                    games_store.AppendValues (game.Name, type, true, game, i);
                }
            }

            treeview.Model = games_store;
            game = (Game) Activator.CreateInstance (games [0].TypeOf, true);
            game.Variant = 0;
            game.Begin ();
            drawing_area.Drawable = game;
            drawing_area.Question = game.Question;
            treeview.ColumnsAutosize ();
        }