private void LoadRoom(string path) { richTextBox1.Clear(); System.Xml.Serialization.XmlSerializer ax = default(System.Xml.Serialization.XmlSerializer); Stream txtReader = File.Open(path, FileMode.Open); //TextReader txtReader = File.OpenText(filePath); ax = new XmlSerializer(typeof(Map)); map = (Map)ax.Deserialize(txtReader); //Stream astream = this.GetType().Assembly.GetManifestResourceStream(filePath); richTextBox1.AppendText("<Map>" + Environment.NewLine); richTextBox1.AppendText("<Rows>" + Environment.NewLine); richTextBox1.AppendText("<Row>" + Environment.NewLine); richTextBox1.AppendText("<columns>" + Environment.NewLine); for (int r = 0; r <= map.rows.Count() - 1; r++) { Label21.Text = r.ToString(); for (int i = 0; i <= map.rows[r].columns.Length - 1; i++) { Label22.Text = i.ToString(); block[i, r] = Enum.GetName(typeof(Enumeration.TileType), map.rows[r].columns[i].tileType); //Load gate switch state if (block[i, r] == "gate" && map.rows[r].columns[i].state == Enumeration.StateTile.opened) switche[i, r] = "open"; else if (block[i, r] == "gate" && map.rows[r].columns[i].state == Enumeration.StateTile.closed) switche[i, r] = "closed"; //Load exit switch state if (block[i, r] == "exit" && map.rows[r].columns[i].state == Enumeration.StateTile.exit_close_left) switche[i, r] = "exit_close_left"; else if (block[i, r] == "exit" && map.rows[r].columns[i].state == Enumeration.StateTile.exit_close_right) switche[i, r] = "exit_close_right"; sprite[i, r] = Enum.GetName(typeof(Enumeration.SpriteType), map.rows[r].columns[i].spriteType); if (sprite[i, r] == "kid") { Player = new Sprite(0, Enumeration.SpriteType.kid, i, r); TextBox28.Text = Player.X.ToString(); TextBox29.Text = Player.Y.ToString(); } else if (sprite[i, r] == "guard") { Guard = new Sprite(guardcount, Enumeration.SpriteType.guard, i, r); TextBox30.Text = Guard.X.ToString(); TextBox31.Text = Guard.Y.ToString(); guardcount += 1; } item[i, r] = Enum.GetName(typeof(Enumeration.Items), map.rows[r].columns[i].item); richTextBox1.AppendText("<Column>" + Environment.NewLine); if ((sprite[r, i] != null)) { richTextBox1.AppendText("<spriteType>" + sprite[r, i] + "</spriteType>" + Environment.NewLine); } if ((item[r, i] != null)) { richTextBox1.AppendText("<item>" + item[r, i] + "</item>" + Environment.NewLine); } richTextBox1.AppendText("<tileType>" + block[r, i] + "</tileType>" + Environment.NewLine); richTextBox1.AppendText("</Column>" + Environment.NewLine); } } txtReader.Close(); richTextBox1.AppendText("</columns>" + Environment.NewLine); richTextBox1.AppendText("</Row>" + Environment.NewLine); richTextBox1.AppendText("</rows>" + Environment.NewLine); richTextBox1.AppendText("</Map>" + Environment.NewLine); Roomselected = true; }
private void pictureBox1_Click(object sender, EventArgs e) { if (mouseX >= 0) mMapX = mouseX; if (mouseY >= 0) mMapY = mouseY; if (selectedtile >= 0) { switch (selectedtile) { case 0: block[mMapX, mMapY] = "space"; break; case 1: block[mMapX, mMapY] = "floor"; break; case 2: block[mMapX, mMapY] = "torch"; break; case 3: block[mMapX, mMapY] = "loose"; break; case 4: block[mMapX, mMapY] = "spikes"; break; case 5: block[mMapX, mMapY] = "posts"; break; case 6: block[mMapX, mMapY] = "block"; break; case 7: block[mMapX, mMapY] = "mirror"; break; case 8: block[mMapX, mMapY] = "pressplate"; switche[mMapX, mMapY] = "open"; break; case 9: block[mMapX, mMapY] = "closeplate"; switche[mMapX, mMapY] = "open"; break; case 10: block[mMapX, mMapY] = "gate"; switche[mMapX, mMapY] = "open"; break; case 11: block[mMapX, mMapY] = "gate2"; switche[mMapX, mMapY] = "close"; break; case 12: block[mMapX, mMapY] = "chomper"; break; case 13: block[mMapX, mMapY] = "lava"; break; case 14: block[mMapX, mMapY] = "exit1"; switche[mMapX, mMapY] = "exit_close_left"; break; case 15: block[mMapX, mMapY] = "exit2"; switche[mMapX, mMapY] = "exit_close_right"; break; } } if (selectedsprite >= 0) { switch (selectedsprite) { case 0: sprite[mMapX, mMapY] = "nothing"; break; case 1: //Kid if (Player != null) { sprite[Player.X, Player.Y] = "nothing"; TextBox28.Text = mMapX.ToString(); TextBox29.Text = mMapY.ToString(); Player.X = Convert.ToInt32(TextBox28.Text); Player.Y = Convert.ToInt32(TextBox29.Text); sprite[mMapX, mMapY] = "kid"; } else { Player = new Sprite(1, Enumeration.SpriteType.kid, 0, 0); sprite[Player.X, Player.Y] = "nothing"; TextBox28.Text = mMapX.ToString(); TextBox29.Text = mMapY.ToString(); Player.X = Convert.ToInt32(TextBox28.Text); Player.Y = Convert.ToInt32(TextBox29.Text); sprite[mMapX, mMapY] = "kid"; } break; case 2: //Guard if (Guard != null) { sprite[Guard.X, Guard.Y] = "nothing"; TextBox28.Text = mMapX.ToString(); TextBox29.Text = mMapY.ToString(); Guard.X = Convert.ToInt32(TextBox28.Text); Guard.Y = Convert.ToInt32(TextBox29.Text); sprite[mMapX, mMapY] = "guard"; } else { Guard = new Sprite(guardcount, Enumeration.SpriteType.guard, 0, 0); sprite[Guard.X, Guard.Y] = "nothing"; TextBox28.Text = mMapX.ToString(); TextBox29.Text = mMapY.ToString(); Guard.X = Convert.ToInt32(TextBox28.Text); Guard.Y = Convert.ToInt32(TextBox29.Text); sprite[mMapX, mMapY] = "guard"; } break; case 3: //Skeleton if (Guard != null) { sprite[Guard.X, Guard.Y] = "nothing"; TextBox28.Text = mMapX.ToString(); TextBox29.Text = mMapY.ToString(); Guard.X = Convert.ToInt32(TextBox28.Text); Guard.Y = Convert.ToInt32(TextBox29.Text); sprite[mMapX, mMapY] = "skeleton"; } else { Guard = new Sprite(guardcount, Enumeration.SpriteType.skeleton, 0, 0); sprite[Guard.X, Guard.Y] = "nothing"; TextBox28.Text = mMapX.ToString(); TextBox29.Text = mMapY.ToString(); Guard.X = Convert.ToInt32(TextBox28.Text); Guard.Y = Convert.ToInt32(TextBox29.Text); sprite[mMapX, mMapY] = "skeleton"; } break; case 4: //Serpent if (Guard != null) { sprite[Guard.X, Guard.Y] = "nothing"; TextBox28.Text = mMapX.ToString(); TextBox29.Text = mMapY.ToString(); Guard.X = Convert.ToInt32(TextBox28.Text); Guard.Y = Convert.ToInt32(TextBox29.Text); sprite[mMapX, mMapY] = "serpent"; } else { Guard = new Sprite(guardcount, Enumeration.SpriteType.kid, 0, 0); sprite[Guard.X, Guard.Y] = "nothing"; TextBox28.Text = mMapX.ToString(); TextBox29.Text = mMapY.ToString(); Guard.X = Convert.ToInt32(TextBox28.Text); Guard.Y = Convert.ToInt32(TextBox29.Text); sprite[mMapX, mMapY] = "serpent"; } break; } } if (selecteditem >= 0) { switch (selecteditem) { case 0: item[mMapX, mMapY] = "nothing"; break; case 1: item[mMapX, mMapY] = "flaskbig"; break; case 2: item[mMapX, mMapY] = "flask"; break; case 3: item[mMapX, mMapY] = "sword"; break; } } }