properly handle non-rectangular input string[]s
GitOrigin-RevId: eb580f2e9c5a6d93827982240fd295ba30fdb0c4
This commit is contained in:
parent
f58faa0b9f
commit
9a1c6646dd
@ -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,41 +111,44 @@ 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;
|
||||
switch (worldDesc[j][i]) {
|
||||
case '=':
|
||||
terrain = Terrain.Grass;
|
||||
break;
|
||||
case '<':
|
||||
terrain = Terrain.GrassL;
|
||||
break;
|
||||
case '>':
|
||||
terrain = Terrain.GrassR;
|
||||
break;
|
||||
case '.':
|
||||
terrain = Terrain.Rock;
|
||||
break;
|
||||
case '[':
|
||||
terrain = Terrain.RockL;
|
||||
break;
|
||||
case ']':
|
||||
terrain = Terrain.RockR;
|
||||
break;
|
||||
case '~':
|
||||
terrain = Terrain.Water;
|
||||
break;
|
||||
case 'X':
|
||||
terrain = Terrain.Block;
|
||||
break;
|
||||
case ' ':
|
||||
default:
|
||||
terrain = Terrain.Empty;
|
||||
break;
|
||||
Terrain terrain = Terrain.Empty;
|
||||
if (i < worldDesc[j].Length) {
|
||||
switch (worldDesc[j][i]) {
|
||||
case '=':
|
||||
terrain = Terrain.Grass;
|
||||
break;
|
||||
case '<':
|
||||
terrain = Terrain.GrassL;
|
||||
break;
|
||||
case '>':
|
||||
terrain = Terrain.GrassR;
|
||||
break;
|
||||
case '.':
|
||||
terrain = Terrain.Rock;
|
||||
break;
|
||||
case '[':
|
||||
terrain = Terrain.RockL;
|
||||
break;
|
||||
case ']':
|
||||
terrain = Terrain.RockR;
|
||||
break;
|
||||
case '~':
|
||||
terrain = Terrain.Water;
|
||||
break;
|
||||
case 'X':
|
||||
terrain = Terrain.Block;
|
||||
break;
|
||||
case ' ':
|
||||
default:
|
||||
terrain = Terrain.Empty;
|
||||
break;
|
||||
}
|
||||
}
|
||||
var position = new Rectangle(i * TileSize, j * TileSize, TileSize, TileSize);
|
||||
tiles[i, j] = new Tile(texture, terrain, position);
|
||||
|
Loading…
Reference in New Issue
Block a user