Browse Source

properly handle non-rectangular input string[]s

GitOrigin-RevId: eb580f2e9c
master
Colin McMillen 4 years ago
parent
commit
9a1c6646dd
  1. 9
      Shared/World.cs

9
Shared/World.cs

@ -1,7 +1,7 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
namespace SemiColinGames {
enum Terrain {
@ -111,12 +111,14 @@ namespace SemiColinGames {
"...................................................................] [.............] [..............................................................] [......................................................." };
public World(Texture2D texture) {
width = worldDesc[0].Length;
width = worldDesc.AsQueryable().Max(a => a.Length);
height = worldDesc.Length;
Debug.WriteLine("world size: {0}x{1}", width, height);
tiles = new Tile[width, height];
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
Terrain terrain;
Terrain terrain = Terrain.Empty;
if (i < worldDesc[j].Length) {
switch (worldDesc[j][i]) {
case '=':
terrain = Terrain.Grass;
@ -147,6 +149,7 @@ namespace SemiColinGames {
terrain = Terrain.Empty;
break;
}
}
var position = new Rectangle(i * TileSize, j * TileSize, TileSize, TileSize);
tiles[i, j] = new Tile(texture, terrain, position);
}

Loading…
Cancel
Save