// Fetches a map from a map file and imports it into a 3 dimensional array public Sprite[,,] fetchMap(string mapID) { block_setup setup = new block_setup(); Sprite[,,] sprites = new Sprite[10, 10, 3]; StreamReader map1 = null; try { map1 = new StreamReader(path_map + mapID + ".csv"); Debug.WriteLine("No error for map path"); } catch (Exception ex) { Debug.WriteLine("Error whilst trying to access map: {0}", ex); } string[] row; for (int y = 9; y >= 0; y--) { row = map1.ReadLine().Split(','); for (int x = 0; x < row.Length; x++) { if (row[x] != "0") { Sprite.Block block = new Sprite.Block(setup.b(row[x])); block.xPos = x; block.yPos = y; block.zPos = 0; sprites[x, y, 0] = block; } } } map1.Close(); return(sprites); }
public Sprite[,,] Getmap(nfloat Height, nfloat Width, int mapnum) { block_setup setup = new block_setup(); fetch_data fetch = new fetch_data(); Sprite[,,] sprites = new Sprite[10, 10, 3]; StreamReader maps = null; try { maps = new StreamReader(fetch.Get_path_map() + "maps.csv"); Debug.WriteLine("No error for map path"); } catch (Exception ex) { Debug.WriteLine(ex); } string[] row; do { row = maps.ReadLine().Split(','); if (int.Parse(row[0]) == mapnum) { Sprite.Block block = new Sprite.Block(setup.b(row[3])); block.xPos = int.Parse(row[1]); block.yPos = int.Parse(row[2]); block.zPos = 0; block.spriteNode = SKSpriteNode.FromImageNamed(block.path); setup.setPos(ref block, ref sprites, Height, Width); } }while (int.Parse(row[0]) <= mapnum); maps.Close(); return(sprites); }
// Gets the map from the table and returns it in a Sprite array public Sprite[,,] Getmap(nfloat Height, nfloat Width, int mapnum) { block_setup setup = new block_setup(); Sprite[,,] sprites = new Sprite[10, 10, 3]; StreamReader maps = null; try { maps = new StreamReader(path_map + "maps.csv"); Debug.WriteLine("No error for map path"); } catch (Exception ex) { Debug.WriteLine("Failed to access maps directory: {0}", ex); } string[] row; maps.ReadLine(); try { do { row = maps.ReadLine().Split(','); if (int.TryParse(row[0], out int z) && int.Parse(row[0]) == mapnum) { Sprite.Block block = new Sprite.Block(setup.b(row[3])); block.xPos = int.Parse(row[1]); block.yPos = int.Parse(row[2]); block.zPos = 0; block.spriteNode = SKSpriteNode.FromImageNamed(block.path); setup.setPos(ref block, ref sprites, Height, Width); } }while (int.Parse(row[0]) <= mapnum); Debug.WriteLine("Fetched map from maps table without problem"); } catch (Exception ex) { Debug.WriteLine("Failed to fetch from maps table: {0}", ex); } maps.Close(); return(sprites); }
// Fetches a map file and imports it into a 3 dimensional array while instantiating the values public Sprite[,,] fetchMap(nfloat Height, nfloat Width, string mapID) { block_setup setup = new block_setup(); Sprite[,,] sprites = new Sprite[10, 10, 3]; StreamReader map1 = null; try { map1 = new StreamReader(path_map + mapID + ".csv"); Debug.WriteLine("No error for map path"); } catch (Exception ex) { Debug.WriteLine("Error whilst trying to access map: {0}", ex); } string[] row; for (int y = 9; y >= 0; y--) { row = map1.ReadLine().Split(','); for (int x = 0; x < row.Length; x++) { if (row[x] != "0") { Sprite.Block block = new Sprite.Block(setup.b(row[x])); block.xPos = x; block.yPos = y; block.zPos = 0; block.spriteNode = SKSpriteNode.FromImageNamed(block.path); setup.setPos(ref block, ref sprites, Height, Width); } } } map1.Close(); return(sprites); }