Пример #1
0
        public void ItemCatalogue_CheckStringIsValid()
        {
            String itemStr1           = "ID:1,Name:TestItem,Amount:1,Description:test item 1,ActiveEffect,PassiveEffect,Requirements";
            String itemStr2           = "ID:2,Name:TestItem,Amount:1,Description:test item 2,ActiveEffect,PassiveEffect,Requirements";
            String itemStr3           = "ID:3,Name:TestItem,Amount:1,Description:test item 3,ActiveEffect,PassiveEffect,Requirements";
            String invalidItem1       = "ID:-1,Name:TestItem,Amount:1,Description:test item -1,ActiveEffect,PassiveEffect,Requirements";
            String invalidItemAmount1 = "ID:4,Name:TestItem,Amount:2,Description:test item 4,ActiveEffect,PassiveEffect,Requirements";

            String expected    = ItemCatalogue.TAG + ";" + itemStr1 + ";" + itemStr2 + ";" + itemStr3;
            String nonUniqueID = ItemCatalogue.TAG + ";" + itemStr1 + ";" + itemStr2 + ";" + itemStr3 + ";" + itemStr1;

            Assert.IsTrue(ItemCatalogue.IsValidItemCatalogue(ItemCatalogue.TAG), "empty catalogue should be valid");
            Assert.IsTrue(ItemCatalogue.IsValidItemCatalogue(expected), "Standard catalogue should be valid");
            Assert.IsFalse(ItemCatalogue.IsValidItemCatalogue(ItemCatalogue.TAG + ";"), "if an catalogue has items it should have at least one item");
            Assert.IsFalse(ItemCatalogue.IsValidItemCatalogue("NotaCatalogue;" + itemStr1), "Not an catalogue should be invalid");
            Assert.IsFalse(ItemCatalogue.IsValidItemCatalogue(";" + itemStr1), "No Tag should be invalid");
            Assert.IsFalse(ItemCatalogue.IsValidItemCatalogue(ItemCatalogue.TAG + itemStr1), "No # should be invalid");
            Assert.IsFalse(ItemCatalogue.IsValidItemCatalogue(ItemCatalogue.TAG + ";" + invalidItem1), "Invalid item means invalid catalogue");
            Assert.AreEqual(ItemCatalogue.IsValidItemCatalogue(ItemCatalogue.TAG + ";" + invalidItem1), Item.IsValidItem(invalidItem1), "Invalid item should match invalid catalogue");
            Assert.IsFalse(ItemCatalogue.IsValidItemCatalogue(ItemCatalogue.TAG + ";" + invalidItemAmount1), "Catalogue Items should only have amount of 1");
            Assert.IsFalse(ItemCatalogue.IsValidItemCatalogue(nonUniqueID), "Each ID should be unique");
        }
Пример #2
0
        public MainWindow()
        {
            InitializeComponent();

            activeEffectsList = new BindingList <string>();
            BindingSource activeSource = new BindingSource();

            activeSource.DataSource = activeEffectsList;
            activeSelect.DataSource = activeSource;

            String aes = ReadFile("activeEffects.txt");

            if (aes != "")
            {
                String[] aesElem = aes.Split('^');
                for (int i = 1; i < aesElem.Length; i++)
                {
                    activeEffectsList.Add(aesElem[i]);
                }
            }


            passiveEffectsList = new BindingList <string>();
            BindingSource passiveSource = new BindingSource();

            passiveSource.DataSource = passiveEffectsList;
            passiveSelect.DataSource = passiveSource;

            String pes = ReadFile("passiveEffects.txt");

            if (pes != "")
            {
                String[] pesElem = pes.Split('^');
                for (int i = 1; i < pesElem.Length; i++)
                {
                    passiveEffectsList.Add(pesElem[i]);
                }
            }

            itemActiveList = new BindingList <string>();
            BindingSource itemActiveSource = new BindingSource();

            itemActiveSource.DataSource = itemActiveList;
            activeEffects.DataSource    = itemActiveSource;

            itemPassiveList = new BindingList <string>();
            BindingSource itemPassiveSource = new BindingSource();

            itemPassiveSource.DataSource = itemPassiveList;
            passiveEffects.DataSource    = itemPassiveSource;

            requirementsList = new BindingList <int>();
            BindingSource requirementsSource = new BindingSource();

            requirementsSource.DataSource = requirementsList;
            requirements.DataSource       = requirementsSource;

            resources = new List <String>();
            resources.Add(PlayerCharacter.HEALTH);
            resources.Add(PlayerCharacter.HUNGER);
            resources.Add(PlayerCharacter.THIRST);
            resources.Add(PlayerCharacter.SANITY);

            activeResource.DataSource  = resources;
            passiveResource.DataSource = resources;
            eventResource.DataSource   = resources;

            iconList      = new SortedList <string, Image>();
            iconFileNames = new BindingList <string>();
            BindingSource fileNameSource = new BindingSource();

            fileNameSource.DataSource = iconFileNames;
            iconSelect.DataSource     = fileNameSource;

            DirectoryInfo dir = new DirectoryInfo(@"C:\Items\");

            FileInfo[] imageFiles = dir.GetFiles("*.png");
            for (int i = 0; i < imageFiles.Length; i++)
            {
                Image image = Image.FromFile(@"C:\Items\" + imageFiles[i].Name);
                iconList.Add(imageFiles[i].Name, image);
                iconFileNames.Add(imageFiles[i].Name);
            }

            itemList = new SortedList <int, Item>();

            String filename = "itemCatalogue.txt";
            String file     = ReadFile(filename);

            if (ItemCatalogue.IsValidItemCatalogue(file))
            {
                itemCatalogue = new ItemCatalogue(file);
            }
            else
            {
                itemCatalogue = new ItemCatalogue("");
            }

            foreach (Item item in itemCatalogue.GetItems())
            {
                itemList.Add(item.GetID(), item);
            }

            itemCatList = new BindingList <string>();
            BindingSource itemCatListSource = new BindingSource();

            itemCatListSource.DataSource  = itemCatList;
            itemCatalogueList.DataSource  = itemCatListSource;
            eventItemCatalogue.DataSource = itemCatListSource;
            itemResource.DataSource       = itemCatListSource;

            foreach (Item item in itemCatalogue.GetItems())
            {
                itemCatList.Add(String.Format("{0}:{1}", item.itemID, item.name));
            }


            prEffectsList   = new BindingList <String>();
            itemEffectsList = new BindingList <string>();

            BindingSource prEffectListSource = new BindingSource();

            prEffectListSource.DataSource = prEffectsList;
            prEffectSelect.DataSource     = prEffectListSource;

            BindingSource itemEffectListSource = new BindingSource();

            itemEffectListSource.DataSource = itemEffectsList;
            itemEffectSelect.DataSource     = itemEffectListSource;
            String ies = ReadFile("itemEffects.txt");

            if (ies != "")
            {
                String[] iesElem = ies.Split('^');
                for (int i = 1; i < iesElem.Length; i++)
                {
                    itemEffectsList.Add(iesElem[i]);
                }
            }

            String pres = ReadFile("prEffects.txt");

            if (pres != "")
            {
                String[] presElem = pres.Split('^');
                for (int i = 1; i < presElem.Length; i++)
                {
                    prEffectsList.Add(presElem[i]);
                }
            }


            sel_ItemEffectsList = new BindingList <String>();
            sel_PREffectsList   = new BindingList <String>();

            BindingSource sel_pr = new BindingSource();

            sel_pr.DataSource    = sel_PREffectsList;
            prEffects.DataSource = sel_pr;

            BindingSource sel_item = new BindingSource();

            sel_item.DataSource    = sel_ItemEffectsList;
            itemEffects.DataSource = sel_item;

            optionsList = new BindingList <String>();

            BindingSource optionsSource = new BindingSource();

            optionsSource.DataSource = optionsList;
            options.DataSource       = optionsSource;

            String eventFilename = "eventCatalogue.txt";
            String eventfile     = ReadFile(eventFilename);

            if (EventCatalogue.IsValidEventCatalogue(eventfile))
            {
                eventCatalogue = new EventCatalogue(eventfile);
            }
            else
            {
                eventCatalogue = new EventCatalogue("");
            }

            eventCat = new BindingList <String>();
            foreach (Event ev in eventCatalogue.GetEvents())
            {
                eventCat.Add(ev.GetEventID() + ":" + ev.GetEventText());
            }

            BindingSource eventCatSource = new BindingSource();

            eventCatSource.DataSource        = eventCat;
            eventCreatorCatalogue.DataSource = eventCatSource;
        }