public static GameMap LoadMap() { string dir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); StreamReader stream = new StreamReader(dir + @"\Resources\map.txt"); string firstline = stream.ReadLine(); string[] firstline_split = firstline.Split(' '); int width = int.Parse(firstline_split[0]); int height = int.Parse(firstline_split[1]); GameMap map = new GameMap(width, height, CellType.EMPTY); for (int y = 0; y < height; y++) { string line = stream.ReadLine(); for (int x = 0; x < width; x++) { if (x < line.Length) { Cell 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; new Skeleton(cell); break; } case '@': { cell.CellType = CellType.FLOOR; map.Player = new Player(cell); break; } } } } } return(map); }
public Cell GetNeighbor(int dx, int dy) { return(gameMap.GetCell(X + dx, Y + dy)); }
public Cell GetNeighbor(int dx, int dy) { return(_gameMap.GetCell(X + dx, Y + dy) ?? this); }
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; new Skeleton(cell); break; } case '@': { cell.CellType = CellType.Floor; map.Player = new Player(cell); break; } case 'k': { cell.CellType = CellType.Floor; new Key(cell); break; } case 't': { cell.CellType = CellType.Floor; new Sword(cell); break; } case 'm': { cell.CellType = CellType.Floor; new Monster(cell); break; } case 'g': { cell.CellType = CellType.Floor; new Gun(cell); break; } case 'd': { cell.CellType = CellType.Floor; new Door(cell); break; } case 'h': { cell.CellType = CellType.Floor; new Headmask(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 '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 Cell GetTheNeighbouringCell(int dx, int dy) { return(_gameMap.GetCell(X + dx, Y + dy) ?? this); }
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); }