private void cvsMainScreen_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { Point p = e.GetPosition(cvsMainScreen); CPoint2i pixelPos = new CPoint2i((int)p.X, (int)p.Y); CPoint2i mapPos = CLevelUtils.GetTileCoordinatesFromPixel(pixelPos); if (FloorWallToggleRadio.IsChecked == true) { if (currentLevel.GetTileType(mapPos.X, mapPos.Y) == eTileType.Wall) { currentLevel.SetTileType(mapPos.X, mapPos.Y, eTileType.Floor); } else if (currentLevel.GetTileType(mapPos.X, mapPos.Y) == eTileType.Floor) { currentLevel.SetTileType(mapPos.X, mapPos.Y, eTileType.Wall); } } else if (PlayerRadio.IsChecked == true && (currentLevel.GetTileType(mapPos.X, mapPos.Y) == eTileType.Floor)) { currentLevel.StartPosition = mapPos; } else if (EnemyRadio.IsChecked == true && (currentLevel.GetTileType(mapPos.X, mapPos.Y) == eTileType.Floor)) { //Fill In here } else if (GoalRadio.IsChecked == true && (currentLevel.GetTileType(mapPos.X, mapPos.Y) == eTileType.Floor)) { currentLevel.GoalPosition = mapPos; } else if (WallRadio.IsChecked == true && (currentLevel.GetTileType(mapPos.X, mapPos.Y) == eTileType.Floor)) { currentLevel.SetTileType(mapPos.X, mapPos.Y, eTileType.Wall); } else if (FloorRadio.IsChecked == true && (currentLevel.GetTileType(mapPos.X, mapPos.Y) == eTileType.Wall)) { currentLevel.SetTileType(mapPos.X, mapPos.Y, eTileType.Floor); } else if (FireRadio.IsChecked == true && (currentLevel.GetTileType(mapPos.X, mapPos.Y) == eTileType.Floor)) { //Fill In here } reRender(); }
/// <summary> /// This function imports the level from the given directory. It is assumed /// the text file containing the level is called Level.txt. /// </summary> /// <param name="directory">The directory the level is stored in.</param> /// <returns>The loaded level.</returns> public static CLevel ImportLevel(string directory) { ////////////////////////////////////////////////////// // Create an instance of a level to populate. CLevel ret = new CLevel(); using (StreamReader fs = new StreamReader(directory + "\\Level.txt")) { /////////////////////////////////////////////////////////// // Read in the dimensions of the level. string strDimY = Regex.Match(fs.ReadLine(), @"\d+").Value; int DimY = int.Parse(strDimY); string strDimX = Regex.Match(fs.ReadLine(), @"\d+").Value; int DimX = int.Parse(strDimX); /////////////////////////////////////////////////////////// // Size the level. ret.Resize(DimX, DimY); /////////////////////////////////////////////////////////// // Read in each tile type. for (int y = 0; y < DimY; y++) { string strRow = fs.ReadLine(); for (int x = 0; x < DimX; x++) { if (strRow[x] == 'F') { ret.SetTileType(x, y, eTileType.Floor); } else { ret.SetTileType(x, y, eTileType.Wall); } } } ///////////////////////////////////////////////////////////// // Get the player start position. string strIn = fs.ReadLine(); string[] bits = strIn.Split(','); ret.StartPosition = new CPoint2i(int.Parse(Regex.Match(bits[0], @"\d+").Value), int.Parse(Regex.Match(bits[1], @"\d+").Value)); ////////////////////////////////////////////////////////////// // Get the goal position. strIn = fs.ReadLine(); bits = strIn.Split(','); ret.GoalPosition = new CPoint2i(int.Parse(Regex.Match(bits[0], @"\d+").Value), int.Parse(Regex.Match(bits[1], @"\d+").Value)); ////////////////////////////////////////////////////////////// // Get the time available. ret.Time = int.Parse(Regex.Match(fs.ReadLine(), @"\d+").Value); ////////////////////////////////////////////////////////////// // Get the number of enemies in the level. int numEnemies = int.Parse(Regex.Match(fs.ReadLine(), @"\d+").Value); ret.EnemyPositions.Capacity = numEnemies; /////////////////////////////////////////////////////////////// // Read in each enemy from the level. for (int i = 0; i < numEnemies; i++) { strIn = fs.ReadLine(); bits = strIn.Split(','); ret.EnemyPositions.Add(new CPoint2i(int.Parse(Regex.Match(bits[0], @"\d+").Value), int.Parse(Regex.Match(bits[1], @"\d+").Value))); } ////////////////////////////////////////////////////////////// // Read in the fire locations. int numFire = int.Parse(Regex.Match(fs.ReadLine(), @"\d+").Value); ret.FirePositions.Capacity = numFire; for (int i = 0; i < numFire; i++) { strIn = fs.ReadLine(); bits = strIn.Split(','); ret.FirePositions.Add(new CPoint2i(int.Parse(Regex.Match(bits[0], @"\d+").Value), int.Parse(Regex.Match(bits[1], @"\d+").Value))); } } ///////////////////////////////////////////////////////// // return the level. return(ret); }