public void TestEmpty() { var dir = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "EmptyDir")); if (dir.Exists) { dir.Delete(true); } dir.Create(); var f = new WorldFactory() { ResourcesDirectory = dir.FullName }; f.Create(); var v = new WorldValidator(); v.Validate(f); Assert.IsEmpty(v.Errors.ToString()); Assert.IsEmpty(v.Warnings.ToString()); Assert.AreEqual(0, v.ErrorCount); Assert.AreEqual(0, v.WarningCount); }
public void TestCustomCSharpAction_InSeperateAssembly() { var old = Compiler.Instance.TypeFactory; try { // Setup the TypeFactory to use both the main Wanderer assembly and our assembly Compiler.Instance.TypeFactory = new TypeCollectionFactory(typeof(Compiler).Assembly, typeof(TestAction).Assembly); var blue = Compiler.Instance.Deserializer.Deserialize <ActionBlueprint>(yaml); var dir = Path.Combine(TestContext.CurrentContext.TestDirectory, "EmptyFolder"); Directory.CreateDirectory(dir); var wf = new WorldFactory() { ResourcesDirectory = dir }; var world = wf.Create(); var f = new ActionFactory(); var action = f.Create(world, world.Player, blue); Assert.IsInstanceOf(typeof(TestAction), action); } finally { Compiler.Instance.TypeFactory = old; } }
static async Task Main(string[] args) { Console.CancelKeyPress += (sender, eventArgs) => { eventArgs.Cancel = true; _cts.Cancel(); Console.WriteLine("Cancellation requested..."); }; //Create the random number generator var randomNumberGenerator = new RandomNumberGenerator(); //Create the world factory var worldFactory = new WorldFactory(randomNumberGenerator); Entity[] survivingEntities = null; for (int generationIndex = 0; generationIndex < 100; generationIndex++) { Console.WriteLine($"=== Generation {generationIndex} ==="); var parameters = new WorldCreationParameters { ExistingEntities = survivingEntities? .Select(e => e.Metadata) .ToArray(), NumberOfEntities = 1000, NumberOfInstructions = 8 }; //Create the world var world = worldFactory.Create(parameters); Console.WriteLine($"World created. Food location: ({world.WorldState.Food.X}, {world.WorldState.Food.Y})"); if (_cts.IsCancellationRequested) { Console.WriteLine("Cancelled."); return; } survivingEntities = await ExecuteGenerationAsync(world, _cts.Token); //Print out the survivors if (survivingEntities != null) { foreach (var aliveEntity in survivingEntities) { var distance = aliveEntity.StartLocation.GetDistance(aliveEntity.Location); Console.WriteLine($" Entity traveled {distance:0.00}: Gen [{aliveEntity.Metadata.Generation}]"); } } } }
public void TestYaml_ActorFiles() { var f = new WorldFactory() { ResourcesDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "Resources") }; f.Create(); }
public void WorldLoadedEvent() { World world = WorldFactory.Create(); world.LoadedEvent += new LoadedEventHandler <LoadedEventArgs <IWorld> >(DetectWorldEvent); world.Load(); bool found = worldLoadedDetected; worldLoadedDetected = false; Assert.AreEqual(true, found); }
public void Validate(WorldFactory worldFactory) { IWorld w; try { w = worldFactory.Create(); } catch (Exception e) { AddError("Error Creating World", e); return; } Validate(w); }
public MainWindowViewModel() { var randomNumberGenerator = new RandomNumberGenerator(); var parameters = new WorldCreationParameters { NumberOfEntities = 10 }; var factory = new WorldFactory(randomNumberGenerator); var world = factory.Create(parameters); World = new WorldViewModel(world); RunCommand = ReactiveCommand.Create(Run); }
public void TestCustomAction_Create() { var blue = Compiler.Instance.Deserializer.Deserialize <ActionBlueprint>(yaml); var dir = Path.Combine(TestContext.CurrentContext.TestDirectory, "EmptyFolder"); Directory.CreateDirectory(dir); var wf = new WorldFactory() { ResourcesDirectory = dir }; var world = wf.Create(); var f = new ActionFactory(); var action = f.Create(world, world.Player, blue); Assert.IsInstanceOf(typeof(TestAction), action); }
protected IRoom InARoom(out IWorld world) { var wf = new WorldFactory(); wf.ResourcesDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "Resources"); wf.SkipContent = true; world = wf.Create(); world.Population.Clear(); world.Relationships.Clear(); world.Factions.Clear(); world.RoomFactory.Blueprints.Clear(); world.ItemFactory.Blueprints.Clear(); world.ActorFactory.Blueprints.Clear(); world.Dialogue.AllDialogues.Clear(); var room = new Room("TestRoom", world, '-'); world.Map.Clear(); world.Map.Add(new Point3(0, 0, 0), room); return(room); }
public void NewGame() { try { var newWorld = _worldFactory.Create(); var dlg = new NewPlayerDialog(this, newWorld.Player, new AdjectiveFactory()); Application.Run(dlg); if (!dlg.Ok) { return; } SetWorld(newWorld); } catch (Exception e) { ShowException("Error Creating World", e); } }
public void TestWorldValidator_MissingDialogue() { var v = new WorldValidator(); var f = new WorldFactory { ResourcesDirectory = NormalResourcesDirectory }; var w = f.Create(); w.Dialogue.AllDialogues.Clear(); w.RoomFactory.Blueprints.Add(new RoomBlueprint() { Dialogue = new DialogueInitiation() { Next = Guid.NewGuid() } }); v.Validate(w); Assert.AreEqual(v.ErrorCount, 1); StringAssert.Contains("Could not find Dialogue", v.Errors.ToString()); }