Пример #1
0
 public void doAbout(AdventureGame g)
 {
     gameName.Text += g.Name;
     gameAuthor.Text += g.Author;
     descriptionTextBox.Text = g.Description;
     this.ShowDialog();
 }
Пример #2
0
        public Page getPageById(string id, AdventureGame g)
        {
            Page pa = null;
            foreach(Page p in g.Pages)
            {
                if(p.ID == id)
                {
                    pa = p;
                }
            }

            if(pa == null)
            {
                throw new Exception("Page with id \'" + id + "\' was not found.");
            }

            return pa;
        }
Пример #3
0
        public Page getPageById(string id, AdventureGame g)
        {
            Page pa = null;

            foreach (Page p in g.Pages)
            {
                if (p.ID == id)
                {
                    pa = p;
                }
            }

            if (pa == null)
            {
                throw new Exception("Page with id \'" + id + "\' was not found.");
            }

            return(pa);
        }
Пример #4
0
        public InvItem getInventoryItemById(string id, AdventureGame g)
        {
            Inventory i       = g.Inventories[0];
            InvItem   invitem = null;

            foreach (InvItem invi in i.InvItems)
            {
                if (invi.ID == id)
                {
                    invitem = invi;
                }
            }

            if (invitem == null)
            {
                throw new Exception("Inventory item with id \'" + id + "\' was not found.");
            }

            return(invitem);
        }
Пример #5
0
        public InvItem getInventoryItemById(string id, AdventureGame g)
        {
            Inventory i = g.Inventories[0];
            InvItem invitem = null;

            foreach(InvItem invi in i.InvItems)
            {
                if(invi.ID == id)
                {
                    invitem = invi;
                }
            }

            if(invitem == null)
            {
                throw new Exception("Inventory item with id \'" + id + "\' was not found.");
            }

            return invitem;
        }
Пример #6
0
        private void AGWindow_Load(object sender, EventArgs e)
        {
            string[] args = Environment.GetCommandLineArgs();
            if(args == null || args.Length <= 1)
            {
                try
                {
                    if (openAdventureGameDialog.ShowDialog() == DialogResult.OK)
                    {
                        //Let's load an adventure game
                        var AGserializer = new XmlSerializer(typeof(AdventureGame));

                        var reader = XmlReader.Create(openAdventureGameDialog.FileName);

                            var testGame = (AdventureGameReader.AdventureGame)AGserializer.Deserialize(reader);

                            //Load the first page
                            string firstPageId = testGame.FirstPage;
                            bool foundFirstPage = false;

                            foreach (Page p in testGame.Pages)
                            {
                                if (p.ID == firstPageId)
                                {
                                    //Load first page text
                                    pageText.Text = p.Text;
                                    actionBox.Items.Clear();

                                    //Populate action list box with actions from first page
                                    foreach (AGAction a in p.AGActions)
                                    {
                                        ListViewItem lvi = new ListViewItem(a.Text);
                                        lvi.Tag = a.ID;

                                        actionBox.Items.Add(lvi);
                                    }

                                    foundFirstPage = true;
                                    CurrentPage = firstPageId;

                                }
                            }

                            //If the first page wasn't found, throw an exception.
                            if (foundFirstPage == false)
                            {
                                throw new Exception("Could not find a page with an ID of \'" + testGame.FirstPage + "\'. Could not display first page.");
                            }

                            Game = testGame;
                            this.Text = Game.Name;
                            //We're done.

                    }
                }
                catch(Exception ex)
                {
                    Error er = new Error();

                    er.doErrorMsg("There was an error loading the adventure game.", ex);
                    if(er.ShowDialog() == DialogResult.Abort)
                    {
                        Application.Exit();
                    }
                }
            }
            else
            {
                try
                {

                        //Let's load an adventure game
                        var AGserializer = new XmlSerializer(typeof(AdventureGame));

                        var reader = XmlReader.Create(args[1]);

                        var testGame = (AdventureGameReader.AdventureGame)AGserializer.Deserialize(reader);

                        //Load the first page
                        string firstPageId = testGame.FirstPage;
                        bool foundFirstPage = false;

                        foreach (Page p in testGame.Pages)
                        {
                            if (p.ID == firstPageId)
                            {
                                //Load first page text
                                pageText.Text = p.Text;
                                actionBox.Items.Clear();
                                //Populate action list box with actions from first page
                                foreach (AGAction a in p.AGActions)
                                {
                                    ListViewItem lvi = new ListViewItem(a.Text);
                                    lvi.Tag = a.ID;

                                    actionBox.Items.Add(lvi);
                                }

                                foundFirstPage = true;
                                CurrentPage = firstPageId;

                            }
                        }

                        //If the first page wasn't found, throw an exception.
                        if (foundFirstPage == false)
                        {
                            throw new Exception("Could not find a page with an ID of \'" + testGame.FirstPage + "\'. Could not display first page.");
                        }

                        Game = testGame;

                        this.Text = Game.Name;
                        //We're done.

                    }

                catch (Exception ex)
                {
                    Error er = new Error();

                    er.doErrorMsg("There was an error loading the adventure game.", ex);
                    if (er.ShowDialog() == DialogResult.Abort)
                    {
                        Application.Exit();
                    }
                }
            }
        }