Exemplo n.º 1
0
        public void ModelFacade_DiscardItem()
        {
            PCModel         pcm        = gs.GetPCM();
            PlayerCharacter workingPC  = pcm.GetPC();
            Inventory       workingInv = pcm.GetInventory();

            Assert.IsTrue(workingInv.Contains(items[0]), "Inventory should contain Item 1");
            Assert.IsTrue(workingInv.Contains(items[2]), "Inventory should contain Item 3");
            Assert.IsTrue(workingInv.Contains(items[3]), "Inventory should contain Item 4");
            Assert.IsTrue(workingInv.Contains(items[5]), "Inventory should contain Item 6");
            Assert.IsTrue(workingInv.Contains(items[7]), "Inventory should contain Item 8");
            Assert.IsTrue(workingInv.Contains(items[21]), "Inventory should contain Item 22");
            Assert.IsTrue(workingInv.Contains(items[23]), "Inventory should contain Item 24");

            int invSlot = workingInv.GetInventorySlot(items[2]);

            Assert.IsTrue(mf.DiscardItem(gs, invSlot), "Should be possible to discard Item 3");
            Assert.IsFalse(workingInv.Contains(items[2]), "Inventory should not contain Item 3");

            invSlot = workingInv.GetInventorySlot(items[7]);
            Assert.IsTrue(workingInv.Contains(items[7]), "Inventory should contain Item 8");
            Assert.IsTrue(mf.DiscardItem(gs, invSlot), "Should be possible to discard Item 8");
            Assert.IsFalse(workingInv.Contains(items[7]), "Inventory should not contain Item 8");

            Assert.IsFalse(mf.DiscardItem(gs, 10), "Should not be possible to discard empty slot");
        }
Exemplo n.º 2
0
        public void ModelFacade_UseItem()
        {
            PCModel         pcm        = gs.GetPCM();
            PlayerCharacter workingPC  = pcm.GetPC();
            Inventory       workingInv = pcm.GetInventory();

            Assert.IsTrue(workingInv.Contains(items[21]), "Inventory should contain Item 22");
            Assert.IsTrue(workingInv.Contains(items[23]), "Inventory should contain Item 24");

            int invSlot = workingInv.GetInventorySlot(items[21]);

            Assert.AreEqual(80, workingPC.GetResource(PlayerCharacter.HEALTH), "Health should be 80");
            Assert.AreEqual(50, workingPC.GetResource(PlayerCharacter.HUNGER), "Hunger should be 50");
            Assert.AreEqual(60, workingPC.GetResource(PlayerCharacter.THIRST), "Thirst should be 60");
            Assert.AreEqual(70, workingPC.GetResource(PlayerCharacter.SANITY), "Sanity should be 70");

            Assert.IsTrue(mf.UseItem(gs, invSlot), "Item 22 should be used");

            Assert.AreEqual(90, workingPC.GetResource(PlayerCharacter.HEALTH), "Health should be 90");
            Assert.AreEqual(50, workingPC.GetResource(PlayerCharacter.HUNGER), "Hunger should stay the same");
            Assert.AreEqual(60, workingPC.GetResource(PlayerCharacter.THIRST), "Thirst should stay the same");
            Assert.AreEqual(70, workingPC.GetResource(PlayerCharacter.SANITY), "Sanity should stay the same");

            Assert.IsFalse(workingInv.Contains(items[21]), "Inventory should no longer contain Item 22");

            invSlot = workingInv.GetInventorySlot(items[23]);
            Assert.IsFalse(mf.UseItem(gs, invSlot), "Should not be possible to item 24 due to lack of prerequisites");
        }
Exemplo n.º 3
0
        public void PCModel_FullConstructor()
        {
            var pc  = pcm.GetPC();
            var inv = pcm.GetInventory();
            var ic  = pcm.GetItemCatalogue();

            Assert.AreEqual(80, pc.GetResource(PlayerCharacter.HEALTH), "Health Value Incorrect");
            Assert.AreEqual(50, pc.GetResource(PlayerCharacter.HUNGER), "Hunger Value Incorrect");
            Assert.AreEqual(60, pc.GetResource(PlayerCharacter.THIRST), "Sanity Value Incorrect");
            Assert.AreEqual(70, pc.GetResource(PlayerCharacter.SANITY), "Thirst Value Incorrect");

            Assert.IsTrue(inv.Contains(items[0]), "Inventory should have item1");
            Assert.IsTrue(inv.Contains(items[1]), "Inventory should have item2");
            Assert.IsTrue(inv.Contains(items[2]), "Inventory should have item3");
            Assert.IsFalse(inv.Contains(items[3]), "Inventory should not have item4");
            Assert.AreEqual(invStr, inv.ParseToString(), "Parsed Inventory should match");
        }
Exemplo n.º 4
0
        public void PCModel_StandardConstructor()
        {
            var pc  = std_pcm.GetPC();
            var inv = std_pcm.GetInventory();
            var ic  = std_pcm.GetItemCatalogue();

            Assert.AreEqual(100, pc.GetResource(PlayerCharacter.HEALTH), "Health Value Incorrect");
            Assert.AreEqual(100, pc.GetResource(PlayerCharacter.HUNGER), "Hunger Value Incorrect");
            Assert.AreEqual(100, pc.GetResource(PlayerCharacter.THIRST), "Sanity Value Incorrect");
            Assert.AreEqual(100, pc.GetResource(PlayerCharacter.SANITY), "Thirst Value Incorrect");

            Assert.AreEqual(itemStr1, ic.GetItem(1).ParseToString(), "Item 1 should be in the catalogue");
            Assert.AreEqual(itemStr2, ic.GetItem(2).ParseToString(), "Item 2 should be in the catalogue");
            Assert.AreEqual(itemStr3, ic.GetItem(3).ParseToString(), "Item 3 should be in the catalogue");
            Assert.AreEqual(itemStr4, ic.GetItem(4).ParseToString(), "Item 4 should be in the catalogue");
            Assert.AreEqual(null, ic.GetItem(5), "Item 5 should not be in the catalogue");
        }
Exemplo n.º 5
0
        public void MainController_WriteSaveData()
        {
            MainController mc = new MainController();

            Assert.IsTrue(mc.InitialiseGameFromSave(), "Save game should be succesfully initialized");
            GameState workingGS = mc.GetGameState();

            PCModel        workingPCM = workingGS.GetPCM();
            LocationModel  workingLM  = workingGS.GetLM();
            EventModel     workingEM  = workingGS.GetEM();
            DiscoveryModel workingDM  = workingGS.GetDM();

            Assert.IsTrue(mc.WriteSaveData(), "Save Data should be sucessfully written");

            FileReadWriter frw           = new FileReadWriter();
            String         pc            = frw.ReadSaveDataFile(FileReadWriter.PLAYER_CHARACTER);
            String         inventory     = frw.ReadSaveDataFile(FileReadWriter.INVENTORY);
            String         usedEvents    = frw.ReadSaveDataFile(FileReadWriter.USED_EVENTS);
            String         currentEvent  = frw.ReadSaveDataFile(FileReadWriter.CURRENT_EVENT);
            String         discovered    = frw.ReadSaveDataFile(FileReadWriter.DISCOVERED);
            String         visitedLocs   = frw.ReadSaveDataFile(FileReadWriter.VISITED);
            String         unvisitedLocs = frw.ReadSaveDataFile(FileReadWriter.UNVISISTED);
            String         currLoc       = frw.ReadSaveDataFile(FileReadWriter.CURRENT_LOCATION);
            String         currSLoc      = frw.ReadSaveDataFile(FileReadWriter.CURRENT_SUBLOCATION);

            String workingPC           = workingPCM.GetPC().ParseToString();
            String workingInventory    = workingPCM.GetInventory().ParseToString();
            String workingUsedEvents   = workingEM.ParseUsedEventsToString();
            String workingCurrentEvent = workingEM.ParseCurrentEventToString();
            String workingDiscovered   = workingDM.ParseDiscoveredToString();
            String workingVisited      = workingLM.ParseVisitedToString();
            String workingUnvisited    = workingLM.ParseUnvisitedToString();
            String workingCurrLocation = workingLM.ParseCurrLocationToString();
            String workingCurrSLoc     = workingLM.ParseCurrSubLocToString();

            Assert.AreEqual(workingPC, pc, "Saved PC should match");
            Assert.AreEqual(workingInventory, inventory, "Saved Inventory should match");
            Assert.AreEqual(workingUsedEvents, usedEvents, "Saved Used Events should match");
            Assert.AreEqual(workingCurrentEvent, currentEvent, "Saved Current events should match");
            Assert.AreEqual(workingDiscovered, discovered, "Saved Discovered should match");
            Assert.AreEqual(workingVisited, visitedLocs, "Saved Visited should match");
            Assert.AreEqual(workingUnvisited, unvisitedLocs, "Saved Unvisisted should match");
            Assert.AreEqual(workingCurrLocation, currLoc, "Saved Curr location should match");
            Assert.AreEqual(workingCurrSLoc, currSLoc, "Saved Curr Sublocation should match");
        }
Exemplo n.º 6
0
        public void ModelFacade_ItemUsable()
        {
            PCModel         pcm        = gs.GetPCM();
            PlayerCharacter workingPC  = pcm.GetPC();
            Inventory       workingInv = pcm.GetInventory();

            Assert.IsTrue(workingInv.Contains(items[21]), "Inventory should contain Item 22");
            Assert.IsTrue(workingInv.Contains(items[23]), "Inventory should contain Item 24");

            int invSlot = workingInv.GetInventorySlot(items[21]);

            Assert.IsTrue(mf.ItemUsable(gs, invSlot), "Item 22 should be usable");

            invSlot = workingInv.GetInventorySlot(items[23]);
            Assert.IsFalse(mf.ItemUsable(gs, invSlot), "Item 24 should not be usable");

            Assert.IsFalse(mf.ItemUsable(gs, 10), "Should not be possible to use empty slot");
        }
Exemplo n.º 7
0
        public void MainController_IntialiseGameFromSave()
        {
            //FileReadWriter frw = new FileReadWriter();
            //frw.WriteSaveDataFile(FileReadWriter.DIFFICULTY_CONTROLLER, dc.ParseToString());
            //frw.WriteSaveDataFile(FileReadWriter.PLAYER_CHARACTER, pc);
            //frw.WriteSaveDataFile(FileReadWriter.INVENTORY, inventory);
            //frw.WriteSaveDataFile(FileReadWriter.USED_EVENTS, usedEvents);
            //frw.WriteSaveDataFile(FileReadWriter.CURRENT_EVENT, currentEvent);
            //frw.WriteSaveDataFile(FileReadWriter.DISCOVERED, discovered);
            //frw.WriteSaveDataFile(FileReadWriter.VISITED, visitedLocs);
            //frw.WriteSaveDataFile(FileReadWriter.UNVISISTED, unvisitedLocs);
            //frw.WriteSaveDataFile(FileReadWriter.CURRENT_LOCATION, currLoc);
            //frw.WriteSaveDataFile(FileReadWriter.CURRENT_SUBLOCATION, currSLoc);
            MainController mc = new MainController();

            Assert.IsTrue(mc.InitialiseGameFromSave(), "Save game should be succesfully initialized");
            GameState workingGS = mc.GetGameState();

            PCModel        workingPCM = workingGS.GetPCM();
            LocationModel  workingLM  = workingGS.GetLM();
            EventModel     workingEM  = workingGS.GetEM();
            DiscoveryModel workingDM  = workingGS.GetDM();

            String workingPC           = workingPCM.GetPC().ParseToString();
            String workingInventory    = workingPCM.GetInventory().ParseToString();
            String workingUsedEvents   = workingEM.ParseUsedEventsToString();
            String workingCurrentEvent = workingEM.ParseCurrentEventToString();
            String workingDiscovered   = workingDM.ParseDiscoveredToString();
            String workingVisited      = workingLM.ParseVisitedToString();
            String workingUnvisited    = workingLM.ParseUnvisitedToString();
            String workingCurrLocation = workingLM.ParseCurrLocationToString();
            String workingCurrSLoc     = workingLM.ParseCurrSubLocToString();

            Assert.AreEqual(pc, workingPC, "PC should match");
            Assert.AreEqual(inventory, workingInventory, "Inventory should match");
            Assert.AreEqual(usedEvents, workingUsedEvents, "Used Events should match");
            Assert.AreEqual(currentEvent, workingCurrentEvent, "Current events should match");
            Assert.AreEqual(discovered, workingDiscovered, "Discovered should match");
            Assert.AreEqual(visitedLocs, workingVisited, "Visited should match");
            Assert.AreEqual(unvisitedLocs, workingUnvisited, "Unvisisted should match");
            Assert.AreEqual(currLoc, workingCurrLocation, "Curr location should match");
            Assert.AreEqual(currSLoc, workingCurrSLoc, "Curr Sublocation should match");
        }
Exemplo n.º 8
0
        public void ModelFacade_ScavengeSublocation()
        {
            LocationModel workingLM  = gs.GetLM();
            PCModel       pcm        = gs.GetPCM();
            Inventory     temp       = new Inventory(inventory);
            Inventory     workingInv = pcm.GetInventory();

            int oldTotal = 0;

            foreach (Item item in workingInv.GetInventory())
            {
                oldTotal += item.GetAmount();
            }

            Assert.AreEqual(workingInv.ParseToString(), temp.ParseToString(), "Inventory should match");
            Assert.IsFalse(workingLM.IsScavenged(), "Current sublocation should not be scavenged");
            Assert.IsFalse(workingInv.IsInventoryFull(), "Inventody should not be full");
            Assert.IsTrue(mf.ScavangeSubLocation(gs).Count > 0, "Scavenging should be succesful");
            Assert.IsTrue(workingLM.IsScavenged(), "Current sublocation should now be scavenged");
            Assert.AreNotEqual(workingInv.ParseToString(), temp.ParseToString(), "Inventory should have changed");

            int newTotal = 0;

            foreach (Item item in workingInv.GetInventory())
            {
                newTotal += item.GetAmount();
            }

            Assert.IsTrue(oldTotal < newTotal, "There should be more items in the inventory");
            var tempScav = mf.ScavangeSubLocation(gs);

            Assert.IsTrue(tempScav.Count == 0, "Scavenging should fail");

            oldTotal = newTotal;
            newTotal = 0;
            foreach (Item item in workingInv.GetInventory())
            {
                newTotal += item.GetAmount();
            }
            Assert.AreEqual(oldTotal, newTotal, "no new items should have been added");
        }
Exemplo n.º 9
0
        public void ModelFacade_ResolveEvent()
        {
            EventModel      em             = gs.GetEM();
            PCModel         pcm            = gs.GetPCM();
            PlayerCharacter workingPC      = pcm.GetPC();
            Inventory       workingInv     = pcm.GetInventory();
            int             optionSelected = 1;
            float           eventModifier  = 1.0f;

            Assert.AreEqual(80, workingPC.GetResource(PlayerCharacter.HEALTH), "Health should be 80");
            Assert.AreEqual(50, workingPC.GetResource(PlayerCharacter.HUNGER), "Hunger should be 50");
            Assert.AreEqual(60, workingPC.GetResource(PlayerCharacter.THIRST), "Thirst should be 60");
            Assert.AreEqual(70, workingPC.GetResource(PlayerCharacter.SANITY), "Sanity should be 70");

            Assert.IsFalse(workingInv.Contains(items[1]), "Inventory should contain Item 2");

            mf.ResolveEvent(gs, optionSelected, eventModifier);

            int newHealth     = workingPC.GetResource(PlayerCharacter.HEALTH);
            int currentHealth = newHealth;

            Assert.IsTrue(newHealth >= 90 && newHealth <= 100, "Health should be increased by somewhere between 10 to 20");
            Assert.IsTrue(workingInv.Contains(items[1]), "Inventory should contain Item 2");
            Assert.AreEqual(1, workingInv.GetAmount(items[1]), "Should be one of Item 2");

            optionSelected = 10;
            mf.ResolveEvent(gs, optionSelected, eventModifier);
            newHealth = workingPC.GetResource(PlayerCharacter.HEALTH);
            Assert.AreEqual(currentHealth, newHealth, "Health should be the same as you can't select a non existent option");
            Assert.IsTrue(workingInv.Contains(items[1]), "Inventory should contain Item 2");
            Assert.AreEqual(1, workingInv.GetAmount(items[1]), "Should only be one of Item 2");

            em.FetchSpecificEvent(100);
            mf.ResolveEvent(gs, optionSelected, eventModifier);
            newHealth = workingPC.GetResource(PlayerCharacter.HEALTH);
            Assert.AreEqual(currentHealth, newHealth, "Health should be the same as you can't select an option of a null event");
            Assert.IsTrue(workingInv.Contains(items[1]), "Inventory should contain Item 2");
            Assert.AreEqual(1, workingInv.GetAmount(items[1]), "Should only be one of Item 2");
        }
Exemplo n.º 10
0
        /// <summary>
        /// Scavenges a sublocation putting found items into the inventory of this PC
        /// </summary>
        /// <param name="gs">The game state to modify</param>
        /// <returns>List of scavenged items</returns>
        public List <Item> ScavangeSubLocation(GameState gs)
        {
            LocationModel lm             = gs.GetLM();
            PCModel       pcm            = gs.GetPCM();
            ItemCatalogue ic             = pcm.GetItemCatalogue();
            List <Item>   scavengedItems = new List <Item>();

            if (lm.IsScavenged() || pcm.GetInventory().IsInventoryFull())
            {
                return(scavengedItems);
            }
            List <Item> itemSelection = new List <Item>();

            for (int i = 0; i < 100; i++)
            {
                itemSelection.Add(ic.GetRandomItem());
            }
            scavengedItems = lm.Scavenge(itemSelection);
            foreach (Item item in scavengedItems)
            {
                pcm.ModifyInventory(item, item.GetAmount());
            }
            return(scavengedItems);
        }