public static GameMap LoadMap() { using var stream = new StreamReader("map.txt"); var firstLine = stream.ReadLine(); var firstLineSplit = firstLine.Split(' '); var width = int.Parse(firstLineSplit[0]); var height = int.Parse(firstLineSplit[1]); var map = new GameMap(width, height, CellType.Empty); for (var y = 0; y < height; y++) { var line = stream.ReadLine(); for (var x = 0; x < width; x++) { if (x < line.Length) { var cell = map.GetCell(x, y); switch (line[x]) { case ' ': { cell.CellType = CellType.Empty; break; } case '#': { cell.CellType = CellType.Wall; break; } case '.': { cell.CellType = CellType.Floor; break; } case 's': { cell.CellType = CellType.Floor; map.Skeleton = new Skeleton(cell); break; } case '@': { cell.CellType = CellType.Floor; map.Player = new Player(cell); break; } case 'k': { cell.CellType = CellType.Floor; map.Key = new Key(cell); break; } case 'w': { cell.CellType = CellType.Floor; map.Sword = new Sword(cell); break; } case 'a': { cell.CellType = CellType.CornerLeft; break; } case 'b': { cell.CellType = CellType.UpperFrame; break; } case 'c': { cell.CellType = CellType.CornerRight; break; } case 'd': { cell.CellType = CellType.RightSide; break; } case 'h': { cell.CellType = CellType.LeftSide; break; } case 'e': { cell.CellType = CellType.LeftDownCorn; break; } case 'g': { cell.CellType = CellType.DownRightCorn; break; } case 'f': { cell.CellType = CellType.DownFrame; break; } case 'i': { cell.CellType = CellType.Floor; map.Door = new Door(cell); break; } } } } } return(map); }
public static GameMap LoadMap() { using var stream = new StreamReader("map.txt"); var firstLine = stream.ReadLine(); var firstLineSplit = firstLine.Split(' '); var width = int.Parse(firstLineSplit[0]); var height = int.Parse(firstLineSplit[1]); var map = new GameMap(width, height, CellType.Empty); for (var y = 0; y < height; y++) { var line = stream.ReadLine(); for (var x = 0; x < width; x++) { if (x < line.Length) { var cell = map.GetCell(x, y); switch (line[x]) { case ' ': cell.CellType = CellType.Empty; break; case '#': cell.CellType = CellType.Wall; break; case '.': cell.CellType = CellType.Floor; break; case 's': cell.CellType = CellType.Floor; map.Skeleton = new Skeleton(cell); break; case '@': cell.CellType = CellType.Floor; map.Player = new Player(cell); break; case 'm': cell.CellType = CellType.Floor; map.Monster = new Monster(cell); break; case 't': cell.CellType = CellType.Floor; map.Sword = new Sword(cell); break; case 'k': cell.CellType = CellType.Floor; map.Key = new Key(cell); break; case 'd': cell.CellType = CellType.Floor; map.Door = new Door(cell); break; case 'i': cell.CellType = CellType.Floor; map.Key2 = new Key2(cell); break; case 'g': cell.CellType = CellType.Floor; map.Gun = new Gun(cell); break; case 'h': cell.CellType = CellType.Floor; map.Headmask = new Headmask(cell); break; case 'b': cell.CellType = CellType.Floor; map.Door2 = new Door2(cell); break; case 'c': cell.CellType = CellType.Floor; map.Crown = new Crown(cell); break; } } } } return(map); }
public static GameMap LoadMap() { int currentLevel = GameMap.level; var stream = new StreamReader($"map_{currentLevel}.txt"); var firstLine = stream.ReadLine(); var firstLineSplit = firstLine.Split(' '); var width = int.Parse(firstLineSplit[0]); var height = int.Parse(firstLineSplit[1]); var map = new GameMap(width, height, CellType.Empty); for (var y = 0; y < height; y++) { var line = stream.ReadLine(); for (var x = 0; x < width; x++) { if (x < line.Length) { var cell = map.GetCell(x, y); switch (line[x]) { case ' ': { cell.CellType = CellType.Empty; break; } case '#': { cell.CellType = CellType.Wall; break; } case 'g': cell.CellType = CellType.Grass; break; case 'w': cell.CellType = CellType.Water; break; case 't': cell.CellType = CellType.Tree; break; case '.': { cell.CellType = CellType.Floor; break; } case 'l': cell.CellType = CellType.Floor; GameMap.Actors.Add(new LinearMob(cell)); break; case 'n': { cell.CellType = CellType.Floor; GameMap.Actors.Add(new NormalMob(cell)); break; } case 'h': { cell.CellType = CellType.Floor; GameMap.Actors.Add(new ShootingMob(cell, 1, 0)); break; } case 'v': { cell.CellType = CellType.Floor; GameMap.Actors.Add(new ShootingMob(cell, 0, 1)); break; } case 'd': { cell.CellType = CellType.Floor; GameMap.Items.Add(new Door(cell)); break; } case '@': { cell.CellType = CellType.Floor; map.Player = new Player(cell); break; } case 'k': { cell.CellType = CellType.Floor; GameMap.Items.Add(new Key(cell)); break; } case 'e': { cell.CellType = CellType.Floor; GameMap.Items.Add(new NextMapExit(cell)); break; } case 'r': { cell.CellType = CellType.Floor; GameMap.Items.Add(new ReturnMapExit(cell)); break; } } } } } return(map); }
public static GameMap LoadMap(string _path, CodecoolQuestGame main) { using var stream = new StreamReader(_path); var firstLine = stream.ReadLine(); var firstLineSplit = firstLine.Split(' '); var width = int.Parse(firstLineSplit[0]); var height = int.Parse(firstLineSplit[1]); var map = new GameMap(width, height, CellType.Empty); for (var y = 0; y < height; y++) { var line = stream.ReadLine(); for (var x = 0; x < width; x++) { if (x < line.Length) { var cell = map.GetCell(x, y); switch (line[x]) { case ' ': { cell.CellType = CellType.Empty; cell.CanIMoveHere = false; break; } case '#': { cell.CellType = CellType.Wall; cell.CanIMoveHere = false; break; } case '.': { cell.CellType = CellType.Floor; cell.CanIMoveHere = true; break; } case 's': { cell.CellType = CellType.Floor; cell.CanIMoveHere = false; map.SetActor(new Skeleton(cell)); break; } case '@': { cell.CellType = CellType.Floor; cell.CanIMoveHere = true; map.Player = new Player(cell); break; } case 'k': { cell.CellType = CellType.Floor; cell.CanIMoveHere = true; Thing blueKey = new Key(cell, "blueKey", "blueKey"); map.SetThing(blueKey); break; } case 'b': { cell.CellType = CellType.Floor; cell.CanIMoveHere = true; Thing redKey = new Key(cell, "redKey", "redKey"); map.SetThing(redKey); break; } case 'd': { cell.CellType = CellType.Floor; Thing door = new Door(cell, new List <string>() { "blueKey" }, main); map.SetThing(door); break; } case 'X': { cell.CellType = CellType.Floor; Thing door = new Door(cell, new List <string>(), main, "exitDoor"); map.SetThing(door); break; } case 't': { cell.CellType = CellType.Floor; cell.CanIMoveHere = true; Thing sword = new Sword(cell); map.SetThing(sword); break; } case 'h': { cell.CellType = CellType.Floor; cell.CanIMoveHere = true; Thing heart = new Heart(cell); map.SetThing(heart); break; } case 'l': { cell.CellType = CellType.Hp; cell.CanIMoveHere = false; break; } case 'x': { cell.CellType = CellType.Floor; cell.CanIMoveHere = true; Torch torch = new Torch(cell); map.SetThing(torch); break; } case 'c': { cell.CellType = CellType.Floor; cell.CanIMoveHere = false; Cow cow = new Cow(cell); map.SetActor(cow); break; } case 'm': { cell.CellType = CellType.Floor; cell.CanIMoveHere = true; Thing meat = new Meat(cell); map.SetThing(meat); break; } case 'g': { cell.CellType = CellType.Floor; cell.CanIMoveHere = false; Ghost ghost = new Ghost(cell); map.SetActor(ghost); break; } } } } } return(map); }