//button event for deleting all object from gamefield private void buttonNew_MouseClick(object sender, MouseEventArgs e) { DialogResult result = MessageBox.Show("Are you sure you want to delete all objects?", "Delete objects", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { ObstacleList.Clear(); } }
private void GameInit() { p_Brid.Location = new Point(108, 161); timer_BirdMovingTrail.Enabled = false; Score = 0; l_Score.Text = ""; lock (ObstacleList) { for (int i = 0; i < ObstacleList.Count; i++) { this.Controls.Remove(ObstacleList[i]); } ObstacleList.Clear(); } }
//opening the dialogs for choosing an existing level private void loadLevel() { OpenFileDialog BrowseFile = new OpenFileDialog(); BrowseFile.Filter = "XML Files (*.xml)|*.xml"; BrowseFile.FilterIndex = 0; BrowseFile.DefaultExt = "xml"; if (BrowseFile.ShowDialog() == System.Windows.Forms.DialogResult.OK) { ObstacleList.Clear(); doc = new XmlDocument(); try { doc.Load(BrowseFile.FileName); } catch (Exception e) { MessageBox.Show("Level Could't be read please check your file. Error: " + e, "Information", MessageBoxButtons.OK, MessageBoxIcon.Error); } XmlNodeList xmlnode; xmlnode = doc.GetElementsByTagName("object"); for (int i = 0; i < xmlnode.Count; i++) { string name = xmlnode[i].ChildNodes.Item(0).InnerText; int xaxis = Convert.ToInt32(xmlnode[i].ChildNodes.Item(1).InnerText); int yaxis = Convert.ToInt32(xmlnode[i].ChildNodes.Item(2).InnerText); string speed = xmlnode[i].ChildNodes.Item(3).InnerText; //adding the objects to the object list switch (name) { case "tree": Tree tree = new Tree(xaxis, yaxis); ObstacleList.Add(tree); Console.WriteLine("Tree added to list."); break; case "sandbag": Sandbag sandbag = new Sandbag(xaxis, yaxis); ObstacleList.Add(sandbag); Console.WriteLine("Tree added to list."); break; case "mine": Mine mine = new Mine(xaxis, yaxis); ObstacleList.Add(mine); Console.WriteLine("Tree added to list."); break; case "mud": Mud mud = new Mud(xaxis, yaxis); ObstacleList.Add(mud); Console.WriteLine("Tree added to list."); break; case "finish": Finish finish = new Finish(xaxis, yaxis); ObstacleList.Add(finish); Console.WriteLine("Tree added to list."); break; case "missilelauncher": ObstacleList.Add(new Missilelauncher(xaxis, yaxis)); Console.WriteLine("Missilelauncher added to list."); break; default: break; } } } }
/// <summary> /// The load obstacles. /// </summary> /// <param name="ObstacleList">The obstacle list.</param> /// <remarks></remarks> public void LoadObstacles(ref List <SceneryInfo> ObstacleList) { if (ObstacleList == null) { ObstacleList = new List <SceneryInfo>(); } else { ObstacleList.Clear(); } map.OpenMap(MapTypes.Internal); // Lists all Obstacles for (int i = 0; i < map.MapHeader.fileCount; i++) { if (map.MetaInfo.TagType[i] == "scnr") { Meta m = new Meta(map); // Base address of SCNR tag, offset of Crate Palette pointer (+816) map.BR.BaseStream.Position = map.MetaInfo.Offset[i] + 816; int chunkCount = map.BR.ReadInt32(); int chunkOffset = map.BR.ReadInt32() - map.SecondaryMagic; // Crate (Obstacle) Palette Objects for (int a = 0; a < chunkCount; a++) { SceneryInfo Obstacle = new SceneryInfo(); // The Palette Chunk # Obstacle.ScenPalNumber = a; // Each chunk is 40 bytes apart map.BR.BaseStream.Position = chunkOffset + a * 40; char[] tagName = map.BR.ReadChars(4); Obstacle.ScenTagNumber = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32()); if (Obstacle.ScenTagNumber != -1) { // Retrieve the Model HLMT tag from the Scenery tag (+56) map.BR.BaseStream.Position = map.MetaInfo.Offset[Obstacle.ScenTagNumber] + 56; Obstacle.HlmtTagNumber = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32()); // Base address of HLMT tag, offset of MODE pointer (+4) map.BR.BaseStream.Position = map.MetaInfo.Offset[Obstacle.HlmtTagNumber] + 4; Obstacle.ModelTagNumber = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32()); m.ReadMetaFromMap(Obstacle.ModelTagNumber, false); Obstacle.Model = new ParsedModel(ref m); ParsedModel.DisplayedInfo.LoadDirectXTexturesAndBuffers(ref device, ref Obstacle.Model); string[] s = map.FileNames.Name[Obstacle.ScenTagNumber].Split('\\'); Obstacle.Name = s[s.Length - 1]; Obstacle.TagPath = map.FileNames.Name[Obstacle.ScenTagNumber]; Obstacle.TagType = map.MetaInfo.TagType[Obstacle.ScenTagNumber]; ObstacleList.Add(Obstacle); } } break; } } map.CloseMap(); }