// Konstruktor public clsMap(int CellCountX, int CellCountY) { this.CellCountX = CellCountX; this.CellCountY = CellCountY; // Liste mit den einzelnen Feldern erstellen for (int x = 0; x < CellCountX; x++) { for (int y = 0; y < CellCountY; y++) { clsMapCell MapCell = new Map.clsMapCell(this, x, y); MapCells.Add(MapCell); } } }
public Problem(string[] mapStringLines) { this.MapCells = new List <List <MapCell> >(); this.CartCoords = new List <Coordinates>(); int rowNum = 0; foreach (var line in mapStringLines) { var mapLine = new List <MapCell>(); int colNum = 0; foreach (var segment in line) { switch (segment) { case '|': mapLine.Add(new MapCell(TrackShape.Vertical, null)); break; case '-': mapLine.Add(new MapCell(TrackShape.Horizontal, null)); break; case '/': mapLine.Add(new MapCell(TrackShape.UpRightLeftDown, null)); break; case '\\': mapLine.Add(new MapCell(TrackShape.UpLeftRightDown, null)); break; case '+': mapLine.Add(new MapCell(TrackShape.Intersection, null)); break; case '<': mapLine.Add(new MapCell(TrackShape.Horizontal, new Cart(Direction.Left, 0))); CartCoords.Add(new Coordinates(colNum, rowNum)); break; case '>': mapLine.Add(new MapCell(TrackShape.Horizontal, new Cart(Direction.Right, 0))); CartCoords.Add(new Coordinates(colNum, rowNum)); break; case '^': mapLine.Add(new MapCell(TrackShape.Vertical, new Cart(Direction.Up, 0))); CartCoords.Add(new Coordinates(colNum, rowNum)); break; case 'v': mapLine.Add(new MapCell(TrackShape.Vertical, new Cart(Direction.Down, 0))); CartCoords.Add(new Coordinates(colNum, rowNum)); break; case ' ': mapLine.Add(new MapCell(TrackShape.Empty, null)); break; } colNum++; } rowNum++; MapCells.Add(mapLine); } }