public Door(Cell cell, List <string> allowKeys, CodecoolQuestGame main, string subtype = "door") : base(cell) { _allowKeys = allowKeys; cell.CanIMoveHere = false; Subtype = subtype; Main = main; }
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); }