Beispiel #1
0
 public PuzzleMap(Puzzle owner)
 {
     puzzle = owner;
     map = new SokobanMap();
     solutions = new List<Solution>();
     isMasterMap = null;
 }
Beispiel #2
0
        /// <summary>
        /// Strong Construction. Start a 'Normal' game
        /// <see cref="Init"/>, then <see cref="InitFX"/>, then <see cref="StartRender"/>
        /// </summary>
        /// <param name="aMap">Puzzle to play</param>
        public GameUI(Puzzle aPuzzle, PuzzleMap aMap, ISoundSubSystem sfx)
            : base(aPuzzle, aMap.Map)
        {
            solution = null;
            puzzleMap = aMap;

            initType = InitTypes.NewGame;

            GameCoords = new GameCoords(this);
            StepCurrent = 0;

            ResourceManager = ResourceFactory.Singleton.GetInstance("Default.GameTiles");
            GameCoords.GlobalTileSize = new SizeInt(32, 32);

            nodes = new List<NodeBase>();
            nodesToRemove = new List<NodeBase>();
            nodesToAdd = new List<NodeBase>();

            // I would like to move this somewhere else
            sound = sfx;
            sfxWelcome = sound.GetHandle("Welcome.wav");
            sfxUndo = sound.GetHandle("sound40.wav");
            sfxRestart = sound.GetHandle("sound31.wav");

            // Add blank bookmarks
            Add((Bookmark)null);
            Add((Bookmark)null);
            Add((Bookmark)null);
            Add((Bookmark)null);
            Add((Bookmark)null);
        }
Beispiel #3
0
        /// <summary>
        /// Strong Construction. Start a 'Normal' game
        /// <see cref="Init"/>, then <see cref="InitFX"/>, then <see cref="StartRender"/>
        /// </summary>
        /// <param name="aMap">Puzzle to play</param>
        public GameUI(Puzzle aPuzzle, PuzzleMap aMap, ISoundSubSystem sfx)
            : base(aPuzzle, aMap.Map)
        {
            solution = null;
            puzzleMap = aMap;

            initType = InitTypes.NewGame;

            GameCoords = new GameCoords(this);
            StepCurrent = 0;

            ResourceFactory = ResourceController.Singleton.GetInstance("Default.GameTiles");
            GameCoords.GlobalTileSize = new SizeInt(48, 48);

            nodes = new List<NodeBase>();
            nodesToRemove = new List<NodeBase>();
            nodesToAdd = new List<NodeBase>();

            // I would like to move this somewhere else
            sound = sfx;

            // Add blank bookmarks
            Add((Bookmark)null);
            Add((Bookmark)null);
            Add((Bookmark)null);
            Add((Bookmark)null);
            Add((Bookmark)null);
        }
Beispiel #4
0
 public PuzzleMap(PuzzleMap clone)
 {
     puzzle = clone.puzzle;
     map = new SokobanMap(clone.map);
     solutions = new List<Solution>(clone.solutions);
     details = new GenericDescription(clone.details);
     rating = clone.rating;
     mapID = clone.mapID;
     isMasterMap = clone.IsMasterMap;
 }
Beispiel #5
0
        /// <summary>
        /// Strong Construction
        /// </summary>
        /// <param name="aMap"></param>
        public Game(Puzzle aPuzzle, SokobanMap aMap)
        {
            if (aMap == null) throw new ArgumentNullException("aPuzzle");
            StringCollection sc = null;
            if (!aMap.isValid(out sc)) throw new Exception(sc[0]);

            puzzle = aPuzzle;
            startPuzzle = aMap;
            current = new SokobanMap(StartPuzzle);
            moves = new Stack<Move>();

            stats = new Stats();
            stats.Start = DateTime.MinValue;
            stats.End = DateTime.MinValue;

            bookmarks = new List<Bookmark>();
        }
        protected override void ExecuteImplementation(CommandInstance<ExplorerItem> instance)
        {
            ItemPuzzle puz = instance.Context[0] as ItemPuzzle;
            if (puz != null)
            {
                Puzzle cloned = new Puzzle(puz.DomainData.Library);
                cloned.PuzzleID = puz.DomainData.Library.IdProvider.GetNextIDString("P{0}");
                cloned.Category = puz.DomainData.Category;
                cloned.Details = new GenericDescription(puz.DomainData.Details);
                cloned.MasterMap = new PuzzleMap(cloned);
                cloned.MasterMap.Details = new GenericDescription(puz.DomainData.MasterMap.Details);
                cloned.MasterMap.MapID = puz.DomainData.Library.IdProvider.GetNextIDString("M{0}");
                cloned.MasterMap.Map = new SokobanMap(puz.DomainData.MasterMap.Map);
                puz.DomainData.Library.Puzzles.Add(cloned);

                Controller.Explorer.Refresh();
            }
        }
        public static HtmlBuilder Report(Puzzle puzzle, StaticImage drawing)
        {
            HtmlBuilder sb = new HtmlBuilder();

            sb.AddSection(puzzle.Details.Name);
            sb.Add("<table class=\"tableformat\"><tr><td>");

            GenericDescription desc = new GenericDescription(puzzle.Details);
            desc.Name = null; // so that the H1 tag is not generated here
            sb.Add(Report(desc));
            if (puzzle.Category != null) sb.AddLabel("Category", puzzle.Category.Details.Name);
            sb.AddLabel("Order", puzzle.Order.ToString());
            sb.AddLabel("Rating", puzzle.Rating);
            sb.AddLabel("PuzzleID", puzzle.PuzzleID);
            sb.AddLabel("Size", "{0}x{1}, {2} crates, {3} floor space",
                puzzle.MasterMap.Map.Size.X,
                puzzle.MasterMap.Map.Size.Y,
                puzzle.MasterMap.Map.Count(Cell.Crate),
                puzzle.MasterMap.Map.Count(Cell.Floor)
                );

            if (puzzle.HasAlternatives)
            {
                sb.AddLabel("Alternatives", puzzle.Alternatives.Count.ToString());
            }

            sb.Add("</td><td>");

            if (drawing != null)
            {
                sb.Add(puzzle.MasterMap, drawing.Draw(puzzle.MasterMap.Map), null);
            }

            sb.Add("</td></tr></table>");

            return sb;
        }
Beispiel #8
0
        private void ProcessBlock(Library lib, List<string> block)
        {
            if (block.Count < 3) return;// Skip

            int order = 0;
            try
            {
                order = int.Parse(block[0].Remove(0, 2).Trim());
            }
            catch(Exception)
            {
                // Nothing
            }

            string name = block[1].Trim();
            if (name.Length == 0) name = namer.MakeName();

            Puzzle puz = new Puzzle(lib);
            puz.Details.Name = name;
            puz.Details.Description = "";
            puz.Category = lib.CategoryTree.Root.Data;
            puz.Order = lib.Puzzles.Count + 1;
            puz.PuzzleID = lib.IdProvider.GetNextIDString("P{0}");

            block.RemoveAt(0);
            block.RemoveAt(0);

            puz.MasterMap = new PuzzleMap(puz);
            puz.MasterMap.MapID = puz.Library.IdProvider.GetNextIDString("M{0}");
            puz.MasterMap.Map = new SokobanMap();
            puz.MasterMap.Map.SetFromStrings(block.ToArray(), "v# $.*@+");
            puz.Rating = PuzzleAnalysis.CalcRating(puz.MasterMap.Map).ToString("0.0");

            // Cleanup
            puz.MasterMap.Map.ApplyVoidCells();

            lib.Puzzles.Add(puz);
        }
Beispiel #9
0
        /// <summary>
        /// Start the game
        /// </summary>
        /// <param name="puzzle"></param>
        /// <param name="map"></param>
        public void StartGameSolution(Puzzle puzzle, PuzzleMap map, Solution solution)
        {
            try
            {
                puzzleMap = map;
                gameUI = new GameUI(puzzle, map, solution);
                gameUI.OnExit += new EventHandler(gameUI_OnExit);
                gameUI.OnGameWin += new EventHandler<NotificationEvent>(gameUI_OnGameWin);
                Game_Resize(null, null);
                timerAnimation.Enabled = true;

                gameUI.StartSolution();
            }
            catch (Exception ex)
            {
                HandleGameException("During Game Startup", ex);
            }
        }
Beispiel #10
0
        /// <summary>
        /// Start the game
        /// </summary>
        /// <param name="puzzle"></param>
        /// <param name="map"></param>
        public void StartGame(Puzzle puzzle, PuzzleMap map)
        {
            try
            {
                puzzleMap = map;
                gameUI = new GameUI(puzzle, map, new WindowsSoundSubSystem());
                gameUI.OnExit += new EventHandler(gameUI_OnExit);
                gameUI.OnGameWin += new EventHandler<NotificationEvent>(gameUI_OnGameWin);
                gameUI.OnGameEvents += new EventHandler<NotificationEvent>(gameUI_OnGameEvents);

                Game_Resize(null, null);
                timerAnimation.Enabled = true;

                gameUI.Start();
            }
            catch (Exception ex)
            {
                HandleGameException("During Game Startup", ex);
            }
        }
Beispiel #11
0
        public GenericDescription Consolidate(Puzzle puzzle)
        {
            GenericDescription res = new GenericDescription(puzzle.Details);
            if (string.IsNullOrEmpty(res.Name)) res.Name = details.Name;
            if (string.IsNullOrEmpty(res.Description)) res.Description = details.Description;
            if (string.IsNullOrEmpty(res.Comments)) res.Comments = details.Comments;
            if (res.Author == null)
            {
                res.Author = details.Author;
            }
            else
            {
                if (string.IsNullOrEmpty(res.Author.Name)) res.Author.Name = details.Author.Name;
            }
            if (!res.DateSpecified && details.DateSpecified)
            {
                res.DateSpecified = true;
                res.Date = details.Date;
            }

            return res;
        }
Beispiel #12
0
 /// <summary>
 /// Get the next puzzle
 /// </summary>
 /// <param name="puzzle"></param>
 /// <returns>null mean nothing next</returns>
 public Puzzle Next(Puzzle puzzle)
 {
     SortByOrder();
     int idx = puzzles.IndexOf(puzzle);
     idx ++;
     if (idx < puzzles.Count - 1) return puzzles[idx];
     return null;
 }
 private string BuildDescription(Puzzle puzzle)
 {
     return string.Format("{0}, {1} crates, {2} solutions. {3}",
         puzzle.MasterMap.Map.Size,
         puzzle.MasterMap.Map.Count(Cell.Crate),
         puzzle.MasterMap.Solutions.Count,
         puzzle.Rating);
 }
        protected override void ExecuteImplementation(CommandInstance<ExplorerItem> instance)
        {
            ItemCategory category = instance.Context[0] as ItemCategory;
            if (category != null)
            {
                // Create a new puzzle with a valid number etc.
                Puzzle newPuz = new Puzzle(Controller.Current);
                newPuz.PuzzleID = Controller.Current.IdProvider.GetNextIDString("P{0}");
                newPuz.Details = new GenericDescription();
                newPuz.Details.Name = string.Format("New Puzzle #{0}", Controller.Current.Puzzles.Count+1);
                newPuz.Category = category.DomainData;
                newPuz.MasterMap = new PuzzleMap(newPuz);
                newPuz.MasterMap.MapID = Controller.Current.IdProvider.GetNextIDString("M{0}");

                Controller.Current.Puzzles.Add(newPuz);

                // Refresh the UI model to updated domain data
                category.SyncDomain();

                // Refresh enture tree
                Controller.Explorer.SyncUI();
            }
        }
Beispiel #15
0
        protected override Library ImportImplementation(string FileName)
        {
            SokoSolve.Core.Model.Library lib = new SokoSolve.Core.Model.Library(Guid.NewGuid());

            XmlDocument import = new XmlDocument();

            import.Load(FileName);
            lib.Details = new GenericDescription();

            if (import.DocumentElement.LocalName != "SokobanLevels")
                throw new Exception("Expected node 'SokobanLevels'");

            if (import.DocumentElement["Title"] != null)
            {
                lib.Details.Name = import.DocumentElement["Title"].InnerText;
            }

            if (import.DocumentElement["Description"] != null)
            {
                lib.Details.Description = import.DocumentElement["Description"].InnerText;
            }

            if (import.DocumentElement["Email"] != null)
            {
                if (lib.Details.Author == null) lib.Details.Author = new GenericDescriptionAuthor();

                lib.Details.Author.Email = import.DocumentElement["Email"].InnerText;
            }

            if (import.DocumentElement["Url"] != null)
            {
                if (lib.Details.Author == null) lib.Details.Author = new GenericDescriptionAuthor();

                lib.Details.Author.Homepage = import.DocumentElement["Url"].InnerText;
            }

            lib.Categories.Root.Data.Details = new GenericDescription(lib.Details);

            if (import.DocumentElement["LevelCollection"] != null)
            {
                lib.Details.License = import.DocumentElement["LevelCollection"].GetAttribute("Copyright");

                XmlElement xmlLevelCollection = (XmlElement)import.DocumentElement["LevelCollection"];
                int levelcount = 1;
                foreach (XmlElement xmlLevel in xmlLevelCollection.ChildNodes)
                {
                    if (xmlLevel.LocalName == "Level")
                    {
                        Puzzle newPuzzle = new Puzzle(lib);
                        newPuzzle.PuzzleID = lib.IdProvider.GetNextIDString("P{0}");
                        newPuzzle.Details = new GenericDescription();
                        newPuzzle.Details.Name = string.Format("Puzzle No. {0}", lib.Puzzles.Count);
                        newPuzzle.Details.Description = string.Format("Imported SLV puzzle");
                        newPuzzle.Category = lib.Categories.Root.Data;
                        newPuzzle.Order = levelcount++;

                        PuzzleMap newMap = new PuzzleMap(newPuzzle);
                        newMap.MapID = lib.IdProvider.GetNextIDString("M{0}");
                        newPuzzle.Maps.Add(newMap);

                        List<string> rows = new List<string>();
                        foreach (XmlElement xmlRow in xmlLevel.ChildNodes)
                        {
                            rows.Add(xmlRow.InnerText);
                        }
                        newMap.Map = new SokobanMap();
                        newMap.Map.setFromStrings(rows.ToArray(), "?# $.*@+");

                        newMap.Map.ApplyVoidCells();

                        lib.Puzzles.Add(newPuzzle);
                    }
                }
            }

            return lib;
        }
 int SortRating(Puzzle lhs, Puzzle rhs)
 {
     return lhs.AutomatedRating.CompareTo(rhs.AutomatedRating);
 }
 int SortOrder(Puzzle lhs, Puzzle rhs)
 {
     return lhs.Order.CompareTo(rhs.Order);
 }
 int SortName(Puzzle lhs, Puzzle rhs)
 {
     return lhs.Details.Name.CompareTo(rhs.Details.Name);
 }
Beispiel #19
0
        /// <summary>
        /// Set the HTML
        /// </summary>
        private void InitHTML()
        {
            StringBuilder html = new StringBuilder(File.ReadAllText(FileManager.getContent("$html/Welcome.html")));

            XmlProvider prov = new XmlProvider();
            Core.Model.Library lib = prov.Load(ProfileController.Current.LibraryLastFile);

            HtmlBuilder leftpane = new HtmlBuilder();
            HtmlBuilder rightpane = new HtmlBuilder();
            Current = lib.GetPuzzleByID(ProfileController.Current.LibraryLastPuzzle);
            if (Current == null)
            {
                ProfileController.Current.LibraryLastPuzzle = lib.Puzzles[0].PuzzleID;
                Current = lib.Puzzles[0];
            }

            if (Current != null)
            {
                leftpane.AddSection(null);
                HtmlReporter.Report(leftpane, Current.Library.Details);

                rightpane.AddLine("{0}/{1} '<b>{2}</b>'", Current.Order, Current.Library.Puzzles.Count, Current.Details.Name);
                rightpane.Add("<a href=\"app://Puzzle/{0}\">", Current.PuzzleID);
                rightpane.Add(Current.MasterMap, DrawingHelper.DrawPuzzle(Current.MasterMap), null);
                rightpane.Add("</a>");
                rightpane.AddLine("<br/><i>Click to play...</i>");

            }
            else
            {
                // Library has no puzzles
            }

            html = html.Replace("[Details]", leftpane.GetHTMLBody());
            html = html.Replace("[Image]", rightpane.GetHTMLBody());
            html = html.Replace("[BASEHREF]", FileManager.getContent("$html"));
            html = html.Replace("[USERNAME]", ProfileController.Current.UserName);
            htmlView.SetHTML(html.ToString());
        }
        private void CreateNewPuzzle(ExplorerItem current, Category category)
        {
            Puzzle newPuz = new Puzzle(Controller.Current);
            newPuz.PuzzleID = Controller.Current.IdProvider.GetNextIDString("P{0}");
            newPuz.Details = ProfileController.Current.GenericDescription;
            newPuz.Details.Name = string.Format("New Puzzle #{0}", Controller.Current.Puzzles.Count + 1);
            newPuz.Category = category;
            newPuz.MasterMap = new PuzzleMap(newPuz);
            newPuz.MasterMap.MapID = Controller.Current.IdProvider.GetNextIDString("M{0}");
            newPuz.Order = Controller.Current.Puzzles.Count + 1;

            newPuz.MasterMap.Map.SetFromStrings(StringHelper.Split(Clipboard.GetText(), "\n"), SokobanMap.InternetChars);

            Controller.Current.Puzzles.Add(newPuz);

            // Refresh the UI model to updated domain data
            current.SyncDomain();

            // Refresh enture tree
            Controller.Explorer.SyncUI();

            Controller.Explorer.UpdateSelection(current);
        }
Beispiel #21
0
        /// <summary>
        /// Playback a solution in the game client
        /// </summary>
        /// <param name="puzzle"></param>
        /// <param name="map"></param>
        /// <param name="solution"></param>
        /// <param name="returnMode"></param>
        public void StartGameSolution(Puzzle puzzle, PuzzleMap map, Solution solution, Modes returnMode)
        {
            Mode = Modes.Game;
            if (gameControl != null)
            {
                gameControl.ReturnMode = returnMode;

                ProfileController.Current.LibraryLastPuzzle = puzzle.PuzzleID;
                gameControl.StartGameSolution(puzzle, map, solution);
            }
        }
        public void Select(Puzzle puzzle)
        {
            foreach (ListViewItem item in listViewPuzzles.Items)
            {
                Puzzle puz = item.Tag as Puzzle;
                if (puz != null && puz == puzzle)
                {
                    if (UseCheckBoxes)
                    {
                        item.Checked = true;
                    }
                    else
                    {
                        item.Selected = true;
                    }

                }
            }
        }
        private XmlElement CreatePuzzle(Puzzle puzzle)
        {
            XmlElement xml = report.CreateElement("div");

            xml.AppendChild(CreateContentTag("h3", string.Format("#{0} - {1}", puzzle.Order, puzzle.Details.Name)));

            //=======================
            XmlElement table = report.CreateElement("table");
            table.SetAttribute("class", "tableinfo");

            if (puzzle.Details.DateSpecified)
                table.InnerXml += string.Format("<tr><th>{0}</th><td>{1}</td></tr>", "Created", puzzle.Details.Date);

            if (!string.IsNullOrEmpty(puzzle.Details.Description))
            table.InnerXml +=
                string.Format("<tr><th>{0}</th><td>{1}</td></tr>", "Description", puzzle.Details.Description);

            if (puzzle.Details.Author != null)
            {
                if (!string.IsNullOrEmpty(puzzle.Details.Author.Name))
                table.InnerXml +=
                    string.Format("<tr><th>{0}</th><td>{1}</td></tr>", "Author", puzzle.Details.Author.Name);
            if (!string.IsNullOrEmpty(puzzle.Details.Author.Email))
                table.InnerXml +=
                    string.Format("<tr><th>{0}</th><td>{1}</td></tr>", "Email", puzzle.Details.Author.Email);
            if (!string.IsNullOrEmpty(puzzle.Details.Author.Homepage))
                table.InnerXml +=
                    string.Format("<tr><th>{0}</th><td>{1}</td></tr>", "Web", puzzle.Details.Author.Homepage);
            }

            if (!string.IsNullOrEmpty(puzzle.Details.License))
                table.InnerXml += string.Format("<tr><th>{0}</th><td>{1}</td></tr>", "License", puzzle.Details.License);

            if (!string.IsNullOrEmpty(puzzle.Details.Comments))
                table.InnerXml += string.Format("<tr><th>{0}</th><td>{1}</td></tr>", "Comments", puzzle.Details.Comments);

            table.InnerXml += string.Format("<tr><th>{0}</th><td>{1}</td></tr>", "Rating", puzzle.Rating);

            table.InnerXml += string.Format("<tr><td colspan=\"2\"><pre>{0}</pre></td></tr>", puzzle.MasterMap.Map.ToString());

            //=======================

            XmlElement img = null;
            switch(OptionImages)
            {
                case(Images.Full) :

                    Image pic = staticImage.Draw(puzzle.MasterMap.Map);
                    string picFileName = string.Format("{0}-{1}.png", library.LibraryID, puzzle.PuzzleID);
                    string picFullFileName = directory + "\\" + picFileName;
                    pic.Save(picFullFileName);

                    img = report.CreateElement("img");
                    img.SetAttribute("src", picFileName);
                    img.SetAttribute("alt", "Puzzle" + puzzle.Details.Name);
                    break;

                case (Images.TableCell):
                    img = CreateTableCellImage(puzzle);
                    break;
            }

            XmlElement tableformat = report.CreateElement("table");
            tableformat.SetAttribute("class", "tableformat");
            tableformat.InnerXml = "<tr><td></td><td></td></tr>";
            tableformat.ChildNodes[0].ChildNodes[0].AppendChild(table);
            if (img != null)
            {
                tableformat.ChildNodes[0].ChildNodes[1].AppendChild(img);
            }

            xml.AppendChild(tableformat);

            if (puzzle.MasterMap.HasSolution)
            {
                foreach (Solution solution in puzzle.MasterMap.Solutions)
                {
                    xml.AppendChild(CreateSolution(solution));
                }
            }

            if (puzzle.HasAlternatives)
            {
                xml.AppendChild(CreateContentTag("h4", "Alternatives"));
            }

            return xml;
        }
        private XmlElement CreateTableCellImage(Puzzle puzzle)
        {
            XmlElement xmlTable = report.CreateElement("table");
            xmlTable.SetAttribute("class", "tablepuzzle");

            for (int ccy = 0; ccy < puzzle.MasterMap.Map.Size.Y; ccy++)
            {
                XmlElement tr = report.CreateElement("tr");
                for(int ccx=0; ccx<puzzle.MasterMap.Map.Size.X; ccx++)
                {
                    XmlElement td = report.CreateElement("td");

                    XmlElement img = report.CreateElement("img");
                    img.SetAttribute("alt", "");
                    img.SetAttribute("src", GetImageURL(puzzle.MasterMap.Map[ccx,ccy]));
                    td.AppendChild(img);

                    tr.AppendChild(td);
                }

                xmlTable.AppendChild(tr);
            }

            return xmlTable;
        }
Beispiel #25
0
        /// <summary>
        /// Strong Construction. Replay a solution
        /// </summary>
        /// <param name="aPuzzle"></param>
        /// <param name="aMap"></param>
        /// <param name="aSolution"></param>
        public GameUI(Puzzle aPuzzle, PuzzleMap aMap, Solution aSolution)
            : base(aPuzzle, aMap.Map)
        {
            solution = aSolution;
            puzzleMap = aMap;

            initType = InitTypes.SolutionReplay;

            GameCoords = new GameCoords(this);
            StepCurrent = 0;

            ResourceManager = ResourceFactory.Singleton.GetInstance("Default.GameTiles");
            GameCoords.GlobalTileSize = new SizeInt(32, 32);

            nodes = new List<NodeBase>();
            nodesToRemove = new List<NodeBase>();
            nodesToAdd = new List<NodeBase>();
        }
        private void CreateNewPuzzle(ExplorerItem current, Category category)
        {
            Puzzle newPuz = new Puzzle(Controller.Current);
            newPuz.PuzzleID = Controller.Current.IdProvider.GetNextIDString("P{0}");
            newPuz.Details = ProfileController.Current.GenericDescription;
            newPuz.Details.Name = string.Format("New Puzzle #{0}", Controller.Current.Puzzles.Count+1);
            newPuz.Category = category;
            newPuz.MasterMap = new PuzzleMap(newPuz);
            newPuz.MasterMap.MapID = Controller.Current.IdProvider.GetNextIDString("M{0}");
            newPuz.Order = Controller.Current.Puzzles.Count + 1;

            Controller.Current.Puzzles.Add(newPuz);

            // Refresh the UI model to updated domain data
            current.SyncDomain();

            // Refresh enture tree
            Controller.Explorer.SyncUI();
        }