private bool RunTownMap(EncounterProg encounter, PlayerToken player, TownMap townMap, TownMapTile currentTownMapTile, ExitTile endTile) { endTile.Position[0] = 1; endTile.Position[1] = 1; player.Position[0] = 1; player.Position[1] = 2; townMap.SetEntityPosition(player); int[] exitTilePos = new int[2] { 1, 1 }; townMap.SetTilePosition(exitTilePos, ExitTile.Value); townMap.BuildMapDisplay(); List <ICharacter> townEntityPile = new List <ICharacter>(); townEntityPile.Add(player); List <Tile> townSpecialTilePile = new List <Tile>() { endTile, new InnTile() { Position = townMap.FindPosition(InnTile.Value) } }; AddEntitiesAndTilesToMap(townMap, townSpecialTilePile, townEntityPile); var song = new Playable(new MusicPlayer(), Track.Town); song.Play(); bool nextMap = RunMapGameLoop(townMap, townEntityPile, townSpecialTilePile, encounter); ClearMap(townMap, townEntityPile); song.Stop(); player.Position[0] = currentTownMapTile.Position[0]; player.Position[1] = currentTownMapTile.Position[1] + 1; return(nextMap); }
/// <summary> /// Runs the logic around the game loop /// </summary> /// <param name="difficulty">Difficulty of the game</param> /// <param name="newPlayer">The current player</param> /// <returns>Whether or not the game will continue</returns> public void RunMapGame() { EncounterProg encounter = new EncounterProg(); encounter.RunCharacterCreation(); Random randomNumberSeed = new Random(); bool newMap = true; int height = 8, width = 20; while (newMap) { PlayerToken player = new PlayerToken(encounter); Console.WriteLine("Loading New Map..."); Console.WriteLine("This may take up to 60 seconds..."); Map map = new Map(width, height); TownMap townMap = new TownMap(width, height); Dictionary <int, CaveMap> caveMapStorage = new Dictionary <int, CaveMap>(); List <Tile> specialTilePile = new List <Tile>(); int randomSeed = randomNumberSeed.Next(_currentLevel - 1, _currentLevel + 2); if (_currentLevel == 1) { randomSeed = randomNumberSeed.Next(0, 3); } else if (_currentLevel == 2) { randomSeed = randomNumberSeed.Next(1, 3); } for (int i = 0; i < randomSeed; i++) { double randomWidthSeed = randomNumberSeed.Next(2, 4); double randomHeightSeed = randomNumberSeed.Next(1, 1); CaveMap caveMap = new CaveMap((int)(width / (randomWidthSeed)), (int)(height / (randomHeightSeed))); CaveTile caveTile = new CaveTile(); caveTile.AssociationNum = i + 1; specialTilePile.Add(caveTile); caveMapStorage.Add(i + 1, caveMap); } TownMapTile currentTownMapTile = new TownMapTile(); ExitTile endTile = new ExitTile(); endTile.Position = new int[2]; currentTownMapTile.Position = FindTileOrEntitySpawn.StartingPostion(map, currentTownMapTile); specialTilePile.Add(currentTownMapTile); specialTilePile.Add(endTile); List <ICharacter> entityPile = new List <ICharacter>(); randomSeed = randomNumberSeed.Next(_currentLevel, _currentLevel * 5); bool isTownMap = true; bool isCaveMap = true; while ((isTownMap || isCaveMap) && newMap) { newMap = RunWorldMap(encounter, player, map, specialTilePile, randomSeed, endTile, entityPile); isTownMap = false; isCaveMap = false; foreach (Tile tile in specialTilePile) { if (tile.GetType() == typeof(CaveTile) && IsColliding.IsCurrentlyColliding(tile, player)) { newMap = RunCaveMap(encounter, player, caveMapStorage, endTile, tile); isCaveMap = true; } else if (tile.GetType() == typeof(TownMapTile) && IsColliding.IsCurrentlyColliding(currentTownMapTile, player)) { encounter.TownReplenish(); newMap = RunTownMap(encounter, player, townMap, currentTownMapTile, endTile); isTownMap = true; } } } width += 10; height += 2; if (width == 100) { newMap = false; } _currentLevel++; } Console.WriteLine("Game Over"); }