int _dx, _dy; //position on map public Map(char[,] _map, int left, int top) { map = _map; _left = left; _top = top; _dx = _left; _dy = _top; _width = map.GetLength(0); _height = map.GetLength(1); _tiles = new MapTile[_width, _height]; for (int y = 0; y < _height; y++) { for (int x = 0; x < _width; x++) { switch (map[x,y]) { case '.': { _tiles[x, y] = new MapTile(x, y, _left, _top, StringName.TILE_DESC_FLOOR, tileType.T_FLOOR, '.'); break; } case '#': { _tiles[x, y] = new MapTile(x, y, _left, _top, StringName.TILE_DESC_WALL, tileType.T_WALL, '#'); break; } case '+': { _tiles[x, y] = new MapTile(x, y, _left, _top, StringName.TILE_DESC_CLOSED_DOOR, tileType.T_CLOSEDDOOR, '+'); break; } case '/': { _tiles[x, y] = new MapTile(x, y, _left, _top, StringName.TILE_DESC_OPEN_DOOR, tileType.T_OPENDOOR, '/'); break; } default: { _tiles[x, y] = new MapTile(x, y, _left, _top, StringName.TILE_DESC_EMPTY, tileType.T_EMPTY, ' '); break; } } } } Console.ForegroundColor = ConsoleColor.White; }
public Map(string path) { _left = 1; _top = 5; _dx = _left; _dy = _top; string line; int count = 0; StreamReader mapFile = new StreamReader(path); int mapWidth = 0, mapHeight = 0; while ((line = mapFile.ReadLine()) != null) { if (count == 0) { mapWidth = Convert.ToInt16(line); } else if (count == 1) { mapHeight = Convert.ToInt16(line); map = new char[mapWidth, mapHeight]; _tiles = new MapTile[mapWidth, mapHeight]; } else { char[] mp = new char[line.Length]; mp = line.ToCharArray(); for (int i = 0; i < line.Length; i++) { map[i,count-2] = mp[i]; switch (mp[i]) { case '.': { _tiles[i, count - 2] = new MapTile(i, count - 2, _left, _top, StringName.TILE_DESC_FLOOR, tileType.T_FLOOR, '.'); break; } case '#': { _tiles[i, count - 2] = new MapTile(i, count - 2, _left, _top, StringName.TILE_DESC_WALL, tileType.T_WALL, '#'); break; } case '+': { _tiles[i, count - 2] = new MapTile(i, count - 2, _left, _top, StringName.TILE_DESC_CLOSED_DOOR, tileType.T_CLOSEDDOOR, '+'); break; } case '/': { _tiles[i, count - 2] = new MapTile(i, count - 2, _left, _top, StringName.TILE_DESC_OPEN_DOOR, tileType.T_OPENDOOR, '/'); break; } default: { _tiles[i, count - 2] = new MapTile(i, count - 2, _left, _top, StringName.TILE_DESC_EMPTY, tileType.T_EMPTY, ' '); break; } } } } count++; } _width = map.GetLength(0); _height = map.GetLength(1); //floorTile = _tiles[character.getOldTop() - _dy, character.getOldLeft() - _dx]; Console.ForegroundColor = ConsoleColor.White; }
public void redrawTile(MapTile tile) { int left, top; left = tile.getX(); top = tile.getY(); Console.SetCursorPosition(left + _dx , top + _dy); Console.ForegroundColor = tile.getTileColor(); Console.Write(tile.visual); }
public void draw(Object character) { if (!character.isSeen()) { //if tile is seen but object not draw tile floorTile = _tiles[character.getX() - _dx, character.getY() - _dy]; if (floorTile.isSeen()) { redrawTile(floorTile); Game.GC.Buffer.WriteToBuffer(character.getX(), character.getY(), floorTile.MapTileToCChar()); } return; } //get tile under character int left = character.getOldLeft(); int top = character.getOldTop(); floorTile = _tiles[left - _dx, top - _dy]; //draw previous tile if nothing is there if (floorTile._objects.Count == 0 && floorTile.isSeen()) { Console.ForegroundColor = floorTile.getTileColor(); Console.SetCursorPosition(left, top); Console.Write(_tiles[left - _dx, top - _dy].visual); //Game.GC.Buffer.WriteToBuffer(left, top, _tiles[left - _dx, top - _dy].visual); Game.GC.Buffer.WriteToBuffer(left, top, floorTile.MapTileToCChar()); } //draw character if has been seen and it's on tile that has been seen left = character.getX(); top = character.getY(); int oleft = character.getOldLeft(); int otop = character.getOldTop(); floorTile = _tiles[left - _dx, top - _dy]; if (floorTile.isSeen()) { //if (left != oleft || top != otop) //{ CChar c = new CChar(); character.showObject(); c.c = character.getVisual(); c.fc = character.getColor(); //Game.GC.Buffer.WriteToBuffer(left, top, character.getVisual()); Game.GC.Buffer.WriteToBuffer(left, top, c); //} } //set cursor under character Console.SetCursorPosition(character.getX(), character.getY()); }