pull Width and Height into properties

GitOrigin-RevId: fe969e51cd393ff350f57acc38cc416954d57252
This commit is contained in:
Colin McMillen 2020-01-25 11:26:47 -05:00
parent 16062f65c3
commit 7e8e5c3e6d

View File

@ -82,12 +82,10 @@ namespace SemiColinGames {
class World {
public const int TileSize = 16;
readonly int width;
readonly int height;
readonly List<Tile> tiles = new List<Tile>();
public int Width { get; }
public int Height { get; }
public int Width { get; private set; }
public int Height { get; private set; }
readonly string worldString = @"
@ -109,11 +107,11 @@ namespace SemiColinGames {
public World(Texture2D texture) {
string[] worldDesc = worldString.Split('\n');
width = worldDesc.AsQueryable().Max(a => a.Length);
height = worldDesc.Length;
Debug.WriteLine("world size: {0}x{1}", width, height);
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
Width = worldDesc.AsQueryable().Max(a => a.Length);
Height = worldDesc.Length;
Debug.WriteLine("world size: {0}x{1}", Width, Height);
for (int j = 0; j < Height; j++) {
for (int i = 0; i < Width; i++) {
Terrain terrain = Terrain.Empty;
if (i < worldDesc[j].Length) {
switch (worldDesc[j][i]) {
@ -141,7 +139,6 @@ namespace SemiColinGames {
case 'X':
terrain = Terrain.Block;
break;
case ' ':
default:
terrain = Terrain.Empty;
break;