Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace WindowsFormsApplication4 {
- public partial class Form1:Form {
- public bool imageLoaded = false;
- public Form1 () {
- InitializeComponent();
- }
- private void Form1_Load (Object sender,EventArgs e) {
- Debug("Please select an image");
- }
- private void button3_Click (Object sender,EventArgs e) {
- openFileDialog1.ShowDialog();
- try {
- pictureBox1.ImageLocation = openFileDialog1.FileName;
- imageLoaded = true;
- Debug("Image Loaded");
- Debug("Please select the begining of wall");
- } catch(Exception ex) {
- Debug("Error loading image:" + ex);
- }
- }
- int q = 1;
- int x, y;
- private void pictureBox1_Click (Object sender,EventArgs e) {
- if(imageLoaded) {
- var loc = pictureBox1.PointToClient(Cursor.Position);
- if(q==1) {
- Debug("You selected " + loc.X +" " + loc.Y);
- Debug("Please select the ending of wall");
- x=loc.X;
- y=loc.Y;
- q++;
- } else {
- Debug("You have created a wall from " + x +" " + y +" to " + loc.X +" " +loc.Y);
- listBox1.Items.Add(x+" "+y +"|" + loc.X + " "+loc.Y);
- q=1;
- DrawWall(x,y,loc.X,loc.Y,Color.Red);
- Debug("Please select the begining of wall");
- }
- }
- }
- public void Debug (string a) {
- console.Text += a + Environment.NewLine;
- console.SelectionStart = console.TextLength;
- console.ScrollToCaret();
- }
- private void listBox1_SelectedIndexChanged (Object sender,EventArgs e) {
- int x, y, xEnd, yEnd;
- for(int i = 0;i<listBox1.Items.Count;i++) {
- x = Convert.ToInt32(listBox1.Items[i].ToString().Split('|')[0].Split(' ')[0]);
- y = Convert.ToInt32(listBox1.Items[i].ToString().Split('|')[0].Split(' ')[1]);
- xEnd = Convert.ToInt32(listBox1.Items[i].ToString().Split('|')[1].Split(' ')[0]);
- yEnd = Convert.ToInt32(listBox1.Items[i].ToString().Split('|')[1].Split(' ')[1]);
- DrawWall(x,y,xEnd,yEnd,Color.Red);
- }
- try {
- x = Convert.ToInt32(listBox1.Items[listBox1.SelectedIndex].ToString().Split('|')[0].Split(' ')[0]);
- y = Convert.ToInt32(listBox1.Items[listBox1.SelectedIndex].ToString().Split('|')[0].Split(' ')[1]);
- xEnd = Convert.ToInt32(listBox1.Items[listBox1.SelectedIndex].ToString().Split('|')[1].Split(' ')[0]);
- yEnd = Convert.ToInt32(listBox1.Items[listBox1.SelectedIndex].ToString().Split('|')[1].Split(' ')[1]);
- DrawWall(x,y,xEnd,yEnd,Color.Yellow);
- Debug("You have selected the wall from " + x +" " + y +" to " + xEnd +" " + yEnd);
- } catch { };
- q=1;
- }
- private void button2_Click (Object sender,EventArgs e) {
- int x, y, xEnd, yEnd;
- if(listBox1.Items.Count >0 && listBox1.SelectedIndex != -1) {
- x = Convert.ToInt32(listBox1.Items[listBox1.SelectedIndex].ToString().Split('|')[0].Split(' ')[0]);
- y = Convert.ToInt32(listBox1.Items[listBox1.SelectedIndex].ToString().Split('|')[0].Split(' ')[1]);
- xEnd = Convert.ToInt32(listBox1.Items[listBox1.SelectedIndex].ToString().Split('|')[1].Split(' ')[0]);
- yEnd = Convert.ToInt32(listBox1.Items[listBox1.SelectedIndex].ToString().Split('|')[1].Split(' ')[1]);
- DrawWall(x,y,xEnd,yEnd,Color.Black);
- listBox1.Items.RemoveAt(listBox1.SelectedIndex);
- Debug("You have deleted the wall from " + x +" " + y +" to " + xEnd +" " + yEnd);
- }
- }
- private void button1_Click (Object sender,EventArgs e) {
- saveFileDialog1.Filter="Wall|.wall";
- saveFileDialog1.ShowDialog();
- string output = "";
- foreach(string s in listBox1.Items) {
- output+=s+Environment.NewLine;
- }
- System.IO.File.WriteAllText(saveFileDialog1.FileName,output);
- }
- private void button4_Click (Object sender,EventArgs e) {
- q=1;
- openFileDialog2.Filter="Walls|*.wall";
- openFileDialog2.ShowDialog();
- string a = System.IO.File.ReadAllText(openFileDialog2.FileName);
- foreach(string b in a.Split('\n')) {
- if(b!="")
- listBox1.Items.Add(b);
- }
- int x, y, xEnd, yEnd;
- for(int i = 0;i<listBox1.Items.Count;i++) {
- try {
- x = Convert.ToInt32(listBox1.Items[i].ToString().Split('|')[0].Split(' ')[0]);
- y = Convert.ToInt32(listBox1.Items[i].ToString().Split('|')[0].Split(' ')[1]);
- xEnd = Convert.ToInt32(listBox1.Items[i].ToString().Split('|')[1].Split(' ')[0]);
- yEnd = Convert.ToInt32(listBox1.Items[i].ToString().Split('|')[1].Split(' ')[1]);
- DrawWall(x,y,xEnd,yEnd,Color.Red);
- } catch {
- Debug("Error loading something in map");
- };
- }
- }
- public void DrawWall (float x,float y,float xEnd,float yEnd,Color c) {
- var DrawArea = (Bitmap)pictureBox1.Image;
- Graphics g;
- g = Graphics.FromImage(DrawArea);
- Pen mypen = new Pen(c);
- g.DrawLine(mypen,x,y,xEnd,yEnd);
- pictureBox1.Image = DrawArea;
- g.Dispose();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement