public void LoadPrototypeAndPlaceMonster() { string monsterJson = "{\"SpriteId\": \"ASSASSIN\", \"Description\": \"Assassin\", \"Health\": 5, \"BaseAtk\": 17, \"BaseDef\": 6, \"BaseDmg\": 15 }"; MonsterFactory.AddPrototype("TEST1", JsonConvert.DeserializeObject <JObject>(monsterJson)); var testMonster = MonsterFactory.CreateMonster(null, OpenDungeon, "TEST1", new XY(3, 3)); // Test in dungeon Assert.Contains(testMonster, OpenDungeon.Actors, "Monster not added"); // Test valid results Assert.AreEqual("ASSASSIN", testMonster.SpriteId, "SpriteID not set correctly"); Assert.AreEqual(5, testMonster.MaxHealth, "Health not set correctly"); Assert.AreEqual(17, testMonster.BaseAtk, "BaseAtk not set correctly"); Assert.AreEqual(6, testMonster.BaseDef, "BaseDef not set correctly"); Assert.AreEqual(15, testMonster.BaseDmg, "BaseDmg not set correctly"); }
public static void Valid() { var path = Path.Combine( TestContext.CurrentContext.TestDirectory, @"data\monsters.json"); // Following is copied almost verbatim from Game.cs // Load the data from Monsters.Json into the Monster Factory using (var monsterFileReader = new System.IO.StreamReader(path)) { var monsterFileText = monsterFileReader.ReadToEnd(); var deserializedMonsterPrototypes = JsonConvert.DeserializeObject <Dictionary <String, JObject> >(monsterFileText); foreach (var prototype in deserializedMonsterPrototypes) { MonsterFactory.AddPrototype(prototype.Key, prototype.Value); } } // If we're here - it's valid! }