private static void WalkTheDungeon(Game gameInstance) { Logger.Info("Walking the dungeon..."); var pathFinder = new AStarPathFinding(); var movementProfile = new HumanoidMovement(); var visibilityMap = new VisibilityMap(gameInstance.Terrain.Width, gameInstance.Terrain.Height, null, null); var walkableLocations = gameInstance.Terrain.WalkableLocations(movementProfile).ToList(); FloodFill.Fill(gameInstance.Terrain, visibilityMap, movementProfile, walkableLocations[Rng.Next(walkableLocations.Count - 1)]); var walkableUnseenLocations = GetWalkableUnseenLocations(gameInstance.Terrain, visibilityMap, movementProfile).ToList(); while (walkableUnseenLocations.Count > 0) { var closestExploredLocation = GetClosestExploredLocation(gameInstance.Terrain, visibilityMap, movementProfile, walkableUnseenLocations[Rng.Next(walkableUnseenLocations.Count - 1)]); var closestUnexploredLocation = GetClosestUnexploredLocation(gameInstance.Terrain, visibilityMap, movementProfile, closestExploredLocation.Value); var movementPath = pathFinder.FindPath(gameInstance.Terrain, new List <IActor>(), new DiggerMovement(), closestExploredLocation.Value, closestUnexploredLocation.Value); foreach (var node in movementPath) { gameInstance.Terrain[node.Location] = new Floor(); visibilityMap[node.Location].WasSeen = true; } visibilityMap[closestUnexploredLocation.Value].WasSeen = false; FloodFill.Fill(gameInstance.Terrain, visibilityMap, movementProfile, closestUnexploredLocation.Value); walkableUnseenLocations = GetWalkableUnseenLocations(gameInstance.Terrain, visibilityMap, movementProfile).ToList(); } //digger.VisibilityMap.UpdateVisibilityMap(gameInstance.Terrain, gameInstance.LightMap, digger.Location.Coordinate); //var command = digger.Intellect.GetNextAction(); //while (command is MoveCommand) //{ // var result = command.Execute(); // if ((!result.Success) && (command is MoveCommand)) // { // // The move action failed // // Ask the actor for a default action on bump // var defaultBumpAction = digger.Intellect.GetDefaultBumpAction((MoveCommand)command); // if (defaultBumpAction != null) // defaultBumpAction.Execute(); // } // digger.VisibilityMap.UpdateVisibilityMap(gameInstance.Terrain, gameInstance.LightMap, digger.Location.Coordinate); // command = digger.Intellect.GetNextAction(); //} //gameInstance.RemoveActor(digger); Logger.Info("Dungeon walk complete."); }
private static Game CreateGame() { Logger.Info("Creating new game..."); var game = new Game(); var humanoidMovement = new HumanoidMovement(); Logger.Info("Creating races..."); var human = new Race { Symbol = 'H', Material = new Flesh(), MovementProfile = humanoidMovement, FovProfile = new HumanoidFov() }; var dps = new Race { Symbol = 'D', Material = new Flesh(), MovementProfile = humanoidMovement, FovProfile = new NightVisionFov() }; var tank = new Race { Symbol = 'T', Material = new Flesh(), MovementProfile = humanoidMovement, FovProfile = new NightVisionFov() }; var dungeonGenerator = new DungeonGenerator { MaxSize = new Size(78, 78), MinSize = new Size(78, 78), CorridorGenerator = new CorridorGenerator { ChangeDirectionModifier = 30, DeadEndRemovalModifier = 50, SparsenessModifier = 70 }, RoomGenerator = new RoomGenerator { MaxNoOfRooms = 15, MinNoOfRooms = 10, MaxRoomSize = new Size(15, 15), MinRoomSize = new Size(10, 10) }, DoorGenerator = new DoorGenerator { MinDoorsPerRoom = 1, MaxDoorsPerRoom = 4, MaxDoorsPerWall = 1, MinDoorsPerWall = 1 } }; dungeonGenerator.Generate(game); List <Point> walkableLocations = game.Terrain.WalkableLocations(humanoidMovement).ToList(); Logger.Info("Creating player..."); var player = new Actor { Name = "Player", Damage = 5, Health = 10, Speed = 10, Race = human, LightSource = new LightSource { Attenuation = new AttenuationFunction { Constant = 1, Linear = 0.15f, Quadratic = 0 }, Colour = System.Drawing.Color.Gold, FovProfile = new TorchFov(), Location = new Location() } }; player.SetLocation(walkableLocations[Rng.Next(walkableLocations.Count - 1)]); var commandFactory = new CommandFactory(game); player.SetIntellect(new PlayerAI(commandFactory)); game.AddActor(player, true); Logger.Info("Creating monsters..."); var monsters = new List <IActor> { new Actor { Name = "Gary", Damage = 1, Health = 10, MaxHealth = 10, Speed = 10, Race = tank }, new Actor { Name = "William", Damage = 10, Health = 1, MaxHealth = 1, Speed = 10, Race = dps }, new Actor { Name = "Byron", Damage = 1, Health = 10, MaxHealth = 10, Speed = 10, Race = tank }, new Actor { Name = "Calvin", Damage = 10, Health = 1, MaxHealth = 1, Speed = 10, Race = dps }, new Actor { Name = "John", Damage = 1, Health = 10, MaxHealth = 10, Speed = 10, Race = tank }, new Actor { Name = "Eugene", Damage = 10, Health = 1, MaxHealth = 1, Speed = 10, Race = dps }, new Actor { Name = "Andreas", Damage = 1, Health = 10, MaxHealth = 10, Speed = 10, Race = tank }, new Actor { Name = "Fred", Damage = 10, Health = 1, MaxHealth = 1, Speed = 10, Race = dps } , new Actor { Name = "Katrina", Damage = 5, Health = 5, MaxHealth = 5, Speed = 10, Race = dps }, new Actor { Name = "Melissa", Damage = 5, Health = 5, MaxHealth = 5, Speed = 10, Race = tank }, new Actor { Name = "Isabel", Damage = 5, Health = 5, MaxHealth = 5, Speed = 10, Race = dps }, new Actor { Name = "Angela", Damage = 5, Health = 5, MaxHealth = 5, Speed = 10, Race = tank }, new Actor { Name = "Janet", Damage = 5, Health = 5, MaxHealth = 5, Speed = 10, Race = dps } }; foreach (IActor monster in monsters) { monster.SetLocation(walkableLocations[Rng.Next(walkableLocations.Count - 1)]); monster.SetIntellect(new HunterBrain()); game.AddActor(monster); } Logger.Info("Game created."); return(game); }