private void addBulletToolStripMenuItem_Click(object sender, EventArgs e) { Model.BulletGift bullet = new Model.BulletGift(); bullets.Add(bullet); MessageBox.Show("Please Select Bullet " + bullets.Count + " Position:", "Bomb " + bullets.Count + " Position", MessageBoxButtons.OK); choosingBullet = true; }
public void OpenMap(string fileName) { // open saved map FileStream fileStream = new FileStream(fileName, FileMode.Open); XmlTextReader reader = new XmlTextReader(fileStream); int row = -1; int col = -1; // parse file and read each node while (reader.Read()) { if (reader.NodeType.ToString() == "Element") { // element node if (reader.Name == "LVMap") { // header node map_name = reader.GetAttribute("MapName"); map_width = Convert.ToInt32(reader.GetAttribute("MapWidth")); map_height = Convert.ToInt32(reader.GetAttribute("MapHeight")); tile_width = Convert.ToInt32(reader.GetAttribute("TileWidth")); tile_height = Convert.ToInt32(reader.GetAttribute("TileHeight")); tbMapName.Text = map_name; nudMapWidth.Value = map_width; nudMapHeight.Value = map_height; nudTileWidth.Value = tile_width; nudTileHeight.Value = tile_height; map = new int[map_width, map_height]; // initialized _map for (int x = 0; x < map_width; x++) for (int y = 0; y < map_height; y++) map[x, y] = -1; } else if (reader.Name == "Player") { int playerX = Convert.ToInt32(reader.GetAttribute("PlayerX")); int playerY = Convert.ToInt32(reader.GetAttribute("PlayerY")); if (playerX > 0 && playerY > 0) { player.StartPoint = new Point(playerX, playerY); playerCount = 1; } } else if (reader.Name == "Monster") { Model.Monster monster = new Model.Monster(); int startX = Convert.ToInt32(reader.GetAttribute("startX")); int startY = Convert.ToInt32(reader.GetAttribute("startY")); int endX = Convert.ToInt32(reader.GetAttribute("endX")); int endY = Convert.ToInt32(reader.GetAttribute("endY")); if (startX > 0 && startY > 0 && endX > 0 && endY > 0) { //monstersCount = Convert.ToInt32(reader.GetAttribute("id")); monster.StartPoint = new Point(startX, startY); monster.EndPoint = new Point(endX, endY); } monsters.Add(monster); } else if (reader.Name == "Bomb") { Model.Bomb bomb = new Model.Bomb(); int XX = Convert.ToInt32(reader.GetAttribute("X")); int YY = Convert.ToInt32(reader.GetAttribute("Y")); if (XX > 0 && YY > 0) { bomb.StartPoint = new Point(XX, YY); } bombs.Add(bomb); } else if (reader.Name == "Coin") { Model.CoinGift coin = new Model.CoinGift(); int XX = Convert.ToInt32(reader.GetAttribute("X")); int YY = Convert.ToInt32(reader.GetAttribute("Y")); if (XX > 0 && YY > 0) { coin.StartPoint = new Point(XX, YY); } coins.Add(coin); } else if (reader.Name == "Bullet") { Model.BulletGift bullet = new Model.BulletGift(); int XX = Convert.ToInt32(reader.GetAttribute("X")); int YY = Convert.ToInt32(reader.GetAttribute("Y")); if (XX > 0 && YY > 0) { bullet.StartPoint = new Point(XX, YY); } bullets.Add(bullet); } else if (reader.Name == "Row") { row = Convert.ToInt32(reader.GetAttribute("Position")); } else if (reader.Name == "Column") { col = Convert.ToInt32(reader.GetAttribute("Position")); } } else if (reader.NodeType.ToString() == "Text") { map[col, row] = int.Parse(reader.Value); } } reader.Close(); ClearSelectedTile(); backup_map.SetMap(map_width, map_height, tile_width, tile_height, map, false); }
public void OpenMap(string fileName) { // open saved map FileStream fileStream = new FileStream(fileName, FileMode.Open); XmlTextReader reader = new XmlTextReader(fileStream); int row = -1; int col = -1; // parse file and read each node while (reader.Read()) { if (reader.NodeType.ToString() == "Element") { // element node if (reader.Name == "LVMap") { // header node map_name = reader.GetAttribute("MapName"); map_width = Convert.ToInt32(reader.GetAttribute("MapWidth")); map_height = Convert.ToInt32(reader.GetAttribute("MapHeight")); tile_width = Convert.ToInt32(reader.GetAttribute("TileWidth")); tile_height = Convert.ToInt32(reader.GetAttribute("TileHeight")); tbMapName.Text = map_name; nudMapWidth.Value = map_width; nudMapHeight.Value = map_height; nudTileWidth.Value = tile_width; nudTileHeight.Value = tile_height; map = new int[map_width, map_height]; // initialized _map for (int x = 0; x < map_width; x++) { for (int y = 0; y < map_height; y++) { map[x, y] = -1; } } } else if (reader.Name == "Player") { int playerX = Convert.ToInt32(reader.GetAttribute("PlayerX")); int playerY = Convert.ToInt32(reader.GetAttribute("PlayerY")); if (playerX > 0 && playerY > 0) { player.StartPoint = new Point(playerX, playerY); playerCount = 1; } } else if (reader.Name == "Monster") { Model.Monster monster = new Model.Monster(); int startX = Convert.ToInt32(reader.GetAttribute("startX")); int startY = Convert.ToInt32(reader.GetAttribute("startY")); int endX = Convert.ToInt32(reader.GetAttribute("endX")); int endY = Convert.ToInt32(reader.GetAttribute("endY")); if (startX > 0 && startY > 0 && endX > 0 && endY > 0) { //monstersCount = Convert.ToInt32(reader.GetAttribute("id")); monster.StartPoint = new Point(startX, startY); monster.EndPoint = new Point(endX, endY); } monsters.Add(monster); } else if (reader.Name == "Bomb") { Model.Bomb bomb = new Model.Bomb(); int XX = Convert.ToInt32(reader.GetAttribute("X")); int YY = Convert.ToInt32(reader.GetAttribute("Y")); if (XX > 0 && YY > 0) { bomb.StartPoint = new Point(XX, YY); } bombs.Add(bomb); } else if (reader.Name == "Coin") { Model.CoinGift coin = new Model.CoinGift(); int XX = Convert.ToInt32(reader.GetAttribute("X")); int YY = Convert.ToInt32(reader.GetAttribute("Y")); if (XX > 0 && YY > 0) { coin.StartPoint = new Point(XX, YY); } coins.Add(coin); } else if (reader.Name == "Bullet") { Model.BulletGift bullet = new Model.BulletGift(); int XX = Convert.ToInt32(reader.GetAttribute("X")); int YY = Convert.ToInt32(reader.GetAttribute("Y")); if (XX > 0 && YY > 0) { bullet.StartPoint = new Point(XX, YY); } bullets.Add(bullet); } else if (reader.Name == "Row") { row = Convert.ToInt32(reader.GetAttribute("Position")); } else if (reader.Name == "Column") { col = Convert.ToInt32(reader.GetAttribute("Position")); } } else if (reader.NodeType.ToString() == "Text") { map[col, row] = int.Parse(reader.Value); } } reader.Close(); ClearSelectedTile(); backup_map.SetMap(map_width, map_height, tile_width, tile_height, map, false); }