private void pbCamvas_MouseDown(object sender, MouseEventArgs e) { //invoked when mouse button is pressed //this function draws obstacles on the GUI on mouse press if (IsInside(e.X, e.Y, Constants.start)) { timer.Start(); hover = Value.Start; } else if (IsInside(e.X, e.Y, Constants.finish)) { timer.Start(); hover = Value.Finish; } else if (hover == Value.Empty) { if (Constants.drawTriangle) { world.FillTriangle(e.X, e.Y, Convert.ToInt32(tbSize.Text), Value.Obstacle); } else if (Constants.drawSquare) { world.FillRectangle(e.X, e.Y, Convert.ToInt32(tbSize.Text), Value.Obstacle); } } }
private void button2_Click(object sender, EventArgs e) { /* * Function Loads data form a file and Updates the GUI * Called when the load button is pressed */ OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.InitialDirectory = "~"; openFileDialog1.Filter = "csv files (*.csv)|*.csv|All files (*.*)|*.*"; openFileDialog1.FilterIndex = 2; openFileDialog1.RestoreDirectory = true; if (openFileDialog1.ShowDialog() == DialogResult.OK) { try { using (StreamReader sr = new StreamReader(openFileDialog1.FileName)) { world = new ArrayGraphics(pbCamvas.Size.Width, pbCamvas.Size.Height); string[] line = sr.ReadLine().Split(','); world.FillRectangle(Convert.ToInt32(line[0]), Convert.ToInt32(line[1]), Convert.ToInt32(line[2]), Value.Start); Constants.start.X = Convert.ToInt32(line[0]); Constants.start.Y = Convert.ToInt32(line[1]); Constants.start.Width = Convert.ToInt32(line[2]); Constants.start.Height = Convert.ToInt32(line[2]); line = sr.ReadLine().Split(','); world.FillRectangle(Convert.ToInt32(line[0]), Convert.ToInt32(line[1]), Convert.ToInt32(line[2]), Value.Finish); Constants.finish.X = Convert.ToInt32(line[0]); Constants.finish.Y = Convert.ToInt32(line[1]); Constants.finish.Width = Convert.ToInt32(line[2]); Constants.finish.Height = Convert.ToInt32(line[2]); while (!sr.EndOfStream) { string[] ln = sr.ReadLine().Split(','); if (Convert.ToInt32(ln[3]) == 0) { world.FillRectangle(Convert.ToInt32(ln[0]), Convert.ToInt32(ln[1]), Convert.ToInt32(ln[2]), Value.Obstacle); //adding the obstacles to state space } else { world.FillTriangle(Convert.ToInt32(ln[0]), Convert.ToInt32(ln[1]), Convert.ToInt32(ln[2]), Value.Obstacle); //adding the obstacles to state space } } } } catch (Exception ex) { MessageBox.Show("File Loaded "); } pbCamvas.Invalidate(); } }