public void MakeMoveToNeigborTest_LocationWithPlayer() { var startLoc = new Location("Start location"); var neigLocWithPlayer = new Location("Neighbor location with neighbor"); var neigLocWithOutPlayer = new Location("Neighbor location with out neighbor"); startLoc.AddNeighbor(neigLocWithPlayer, Directions.North); startLoc.AddNeighbor(neigLocWithOutPlayer, Directions.South); MonsterOne.CurrentLocation = startLoc; MonsterOne.MakeMoveToNeighbor(); Assert.AreEqual(neigLocWithPlayer, MonsterOne.CurrentLocation); Assert.True(MonsterOne.IsAlive); MonsterOne.MakeMoveToNeighbor(); Assert.False(MonsterOne.IsAlive); }
public static ILocation CreateLocation(string name, string type) { var loc = new Location(name); switch (type) { case "NoDayLightWithLightSource": return new NoDayLightLocation(loc) { HasLightSource = true }; case "NoDayLightNoLightSource": return new NoDayLightLocation(loc) { HasLightSource = false }; break; case "WaterLocation": return new WaterLocation(loc); case "BoobyTrap": return new BoobyTrapLocation(loc); case "ExitLocation": return new BoobyTrapLocation(loc); default: Console.WriteLine("Type of the location is not correct."); return null; } }
/// <summary> /// This method reads the terrain from xml and forms the terrain using the methods in location class /// </summary> /// <param name="fileName"></param> public override void Construct(Terrain terrain, string fileName) { //empty the terrain ClearTerrain(terrain); using (XmlReader reader = XmlReader.Create(fileName)) { while (reader.Read()) { if (reader.IsStartElement()) { switch (reader.Name) { case "Location": ILocation iLoc; var name = reader["Name"]; var loc = new Location(name); var markedLoc = new MarkedLocation(loc); if (reader["ExitLocation"] == "true") { iLoc = new ExitLocation(markedLoc); } else { iLoc = markedLoc; } terrain.AddLocation(iLoc); break; } } } } using (XmlReader reader = XmlReader.Create(fileName)) { ILocation iLoc = null; while (reader.Read()) { if (reader.IsStartElement()) { switch (reader.Name) { case "Location": var name = reader["Name"]; iLoc = terrain.GetLocation(name); break; case "Neigbor": var directionStr = reader["Direction"]; if (reader.Read()) { var neigborLocName = reader.Value.Trim(); Directions direction; Enum.TryParse(directionStr, out direction); var neigborLocation = terrain.GetLocation(neigborLocName); if (neigborLocation == null) throw new Exception("There must be a location already defined by the name {0}" + neigborLocation); iLoc.AddNeighbor(terrain.GetLocation(neigborLocName), direction); } break; } } } } }