Advertisement
powerofsoul

Untitled

Oct 23rd, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.06 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace WindowsFormsApplication4 {
  12.     public partial class Form1:Form {
  13.         public bool imageLoaded = false;
  14.         public Form1 () {
  15.             InitializeComponent();
  16.         }
  17.  
  18.         private void Form1_Load (Object sender,EventArgs e) {
  19.             Debug("Please select an image");
  20.         }
  21.  
  22.         private void button3_Click (Object sender,EventArgs e) {
  23.             openFileDialog1.ShowDialog();
  24.             try {
  25.                 pictureBox1.ImageLocation = openFileDialog1.FileName;
  26.                 imageLoaded = true;
  27.                 Debug("Image Loaded");
  28.                 Debug("Please select the begining of wall");
  29.             } catch(Exception ex) {
  30.                 Debug("Error loading image:" + ex);
  31.             }
  32.         }
  33.         int q = 1;
  34.         int x, y;
  35.         private void pictureBox1_Click (Object sender,EventArgs e) {
  36.             if(imageLoaded) {
  37.                 var loc = pictureBox1.PointToClient(Cursor.Position);
  38.  
  39.                 if(q==1) {
  40.                     Debug("You selected " + loc.X +" " + loc.Y);
  41.                     Debug("Please select the ending of wall");
  42.                     x=loc.X;
  43.                     y=loc.Y;
  44.                     q++;
  45.                 } else {
  46.                     Debug("You have created a wall from " + x +" " + y +" to " + loc.X +" " +loc.Y);
  47.                     listBox1.Items.Add(x+" "+y +"|" + loc.X + " "+loc.Y);
  48.                     q=1;
  49.                     DrawWall(x,y,loc.X,loc.Y,Color.Red);
  50.                     Debug("Please select the begining of wall");
  51.                 }
  52.             }
  53.         }
  54.  
  55.         public void Debug (string a) {
  56.             console.Text += a + Environment.NewLine;
  57.             console.SelectionStart = console.TextLength;
  58.             console.ScrollToCaret();
  59.         }
  60.  
  61.         private void listBox1_SelectedIndexChanged (Object sender,EventArgs e) {
  62.             int x, y, xEnd, yEnd;
  63.             for(int i = 0;i<listBox1.Items.Count;i++) {
  64.                 x = Convert.ToInt32(listBox1.Items[i].ToString().Split('|')[0].Split(' ')[0]);
  65.                 y = Convert.ToInt32(listBox1.Items[i].ToString().Split('|')[0].Split(' ')[1]);
  66.                 xEnd = Convert.ToInt32(listBox1.Items[i].ToString().Split('|')[1].Split(' ')[0]);
  67.                 yEnd = Convert.ToInt32(listBox1.Items[i].ToString().Split('|')[1].Split(' ')[1]);
  68.                 DrawWall(x,y,xEnd,yEnd,Color.Red);
  69.             }
  70.             try {
  71.                 x = Convert.ToInt32(listBox1.Items[listBox1.SelectedIndex].ToString().Split('|')[0].Split(' ')[0]);
  72.                 y = Convert.ToInt32(listBox1.Items[listBox1.SelectedIndex].ToString().Split('|')[0].Split(' ')[1]);
  73.                 xEnd = Convert.ToInt32(listBox1.Items[listBox1.SelectedIndex].ToString().Split('|')[1].Split(' ')[0]);
  74.                 yEnd = Convert.ToInt32(listBox1.Items[listBox1.SelectedIndex].ToString().Split('|')[1].Split(' ')[1]);
  75.                 DrawWall(x,y,xEnd,yEnd,Color.Yellow);
  76.                 Debug("You have selected the wall from " + x +" " + y +" to " + xEnd +" " + yEnd);
  77.             } catch { };
  78.  
  79.             q=1;
  80.         }
  81.  
  82.         private void button2_Click (Object sender,EventArgs e) {
  83.             int x, y, xEnd, yEnd;
  84.             if(listBox1.Items.Count >0 && listBox1.SelectedIndex != -1) {
  85.                 x = Convert.ToInt32(listBox1.Items[listBox1.SelectedIndex].ToString().Split('|')[0].Split(' ')[0]);
  86.                 y = Convert.ToInt32(listBox1.Items[listBox1.SelectedIndex].ToString().Split('|')[0].Split(' ')[1]);
  87.                 xEnd = Convert.ToInt32(listBox1.Items[listBox1.SelectedIndex].ToString().Split('|')[1].Split(' ')[0]);
  88.                 yEnd = Convert.ToInt32(listBox1.Items[listBox1.SelectedIndex].ToString().Split('|')[1].Split(' ')[1]);
  89.                 DrawWall(x,y,xEnd,yEnd,Color.Black);
  90.                 listBox1.Items.RemoveAt(listBox1.SelectedIndex);
  91.                 Debug("You have deleted the wall from " + x +" " + y +" to " + xEnd +" " + yEnd);
  92.             }
  93.        
  94.         }
  95.  
  96.         private void button1_Click (Object sender,EventArgs e) {
  97.             saveFileDialog1.Filter="Wall|.wall";
  98.             saveFileDialog1.ShowDialog();
  99.             string output = "";
  100.             foreach(string s in listBox1.Items) {
  101.                 output+=s+Environment.NewLine;
  102.             }
  103.             System.IO.File.WriteAllText(saveFileDialog1.FileName,output);
  104.         }
  105.  
  106.         private void button4_Click (Object sender,EventArgs e) {
  107.             q=1;
  108.             openFileDialog2.Filter="Walls|*.wall";
  109.             openFileDialog2.ShowDialog();
  110.             string a = System.IO.File.ReadAllText(openFileDialog2.FileName);
  111.             foreach(string b in a.Split('\n')) {
  112.                 if(b!="")
  113.                 listBox1.Items.Add(b);
  114.             }
  115.                
  116.             int x, y, xEnd, yEnd;
  117.             for(int i = 0;i<listBox1.Items.Count;i++) {
  118.                 try {
  119.                     x = Convert.ToInt32(listBox1.Items[i].ToString().Split('|')[0].Split(' ')[0]);
  120.                     y = Convert.ToInt32(listBox1.Items[i].ToString().Split('|')[0].Split(' ')[1]);
  121.                     xEnd = Convert.ToInt32(listBox1.Items[i].ToString().Split('|')[1].Split(' ')[0]);
  122.                     yEnd = Convert.ToInt32(listBox1.Items[i].ToString().Split('|')[1].Split(' ')[1]);
  123.                     DrawWall(x,y,xEnd,yEnd,Color.Red);
  124.                 } catch {
  125.                     Debug("Error loading something in map");
  126.                         };
  127.             }
  128.         }
  129.  
  130.         public void DrawWall (float x,float y,float xEnd,float yEnd,Color c) {
  131.             var DrawArea = (Bitmap)pictureBox1.Image;
  132.             Graphics g;
  133.             g = Graphics.FromImage(DrawArea);
  134.             Pen mypen = new Pen(c);
  135.             g.DrawLine(mypen,x,y,xEnd,yEnd);
  136.             pictureBox1.Image = DrawArea;
  137.             g.Dispose();
  138.         }
  139.  
  140.  
  141.     }
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement