Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Graphics;
- using System.Runtime.InteropServices;
- namespace IcyTD
- {
- class Level
- {
- // Funktionierend
- int[,] map = new int[,]
- {
- {0,0,1,0,0,0,0,0,},
- {0,0,1,1,0,0,0,0,},
- {0,0,0,1,1,0,0,0,},
- {0,0,0,0,1,0,0,0,},
- {0,0,0,1,1,0,0,0,},
- {0,0,1,1,0,0,0,0,},
- {0,0,1,0,0,0,0,0,},
- {0,0,1,1,1,1,1,1,},
- };
- /* Meine Methode mit Fehler:
- int[,] iMap;
- public Level(int iLevel)
- {
- iMap = ReadLevel(iLevel);
- }*/
- public List<Texture2D> tileTextures = new List<Texture2D>();
- public void AddTexture(Texture2D texture)
- {
- tileTextures.Add(texture);
- }
- public int Width
- {
- get { return iMap.GetLength(1); }
- }
- public int Height
- {
- get { return iMap.GetLength(0); }
- }
- public void Draw(SpriteBatch batch)
- {
- for (int x = 0; x < Width; x++)
- {
- for (int y = 0; y < Height; y++)
- {
- int textureIndex = iMap[y, x];
- if (textureIndex == -1) continue;
- Texture2D texture = tileTextures[textureIndex];
- batch.Draw(texture, new Rectangle(x * 16, y * 16, 16, 16), Color.White);
- }
- }
- }
- private int[,] ReadLevel(int iLevel)
- {
- string iFileName = "Level\\" + iLevel.ToString() + ".txt";
- string[] sTempStringArray;
- string[,] sTempMap;
- int[,] iTempMap;
- List<String> lTempList = new List<String>();
- String lLines = String.Empty;
- StreamReader lStreamReader = null;
- if (File.Exists(iFileName))
- {
- lStreamReader = new StreamReader(iFileName, Encoding.UTF7);
- while ((lLines = lStreamReader.ReadLine()) != null)
- {
- lTempList.Add(lLines);
- }
- }
- lStreamReader.Close();
- sTempMap = new string[lTempList.Count, (lTempList[0].Length - 1) / 2 + 1];
- iTempMap = new int[lTempList.Count, (lTempList[0].Length - 1) / 2 + 1];
- for (int i = 0; i < lTempList.Count; i++)
- {
- sTempStringArray = lTempList[i].Split(',');
- for (int j = 0; j < sTempStringArray.Length; j++)
- {
- sTempMap[i, j] = sTempStringArray[j];
- }
- }
- for (int i = 0; i < lTempList.Count; i++)
- {
- for (int j = 0; j < (lTempList[0].Length - 1) / 2 + 1; j++)
- {
- iTempMap[i, j] = Convert.ToInt32(sTempMap[i, j]);
- }
- }
- return iTempMap;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement