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 WindowsFormsApplication6
- {
- public partial class Form1x : Form
- {
- CCircleStorage UsuallyStorage = new CCircleStorage();
- CCircleStorage PaintedStorage = new CCircleStorage();
- float DeltaX = 0;
- float DeltaY = 0;
- int IndMov = 0;
- bool isClicked = false;
- int Connect = 0;
- bool Vision;
- public Form1x()
- {
- InitializeComponent();
- pic.Invalidate();
- }
- private void Form1_MouseClick(object sender, MouseEventArgs e)
- {
- ;
- }
- private void Form1x_Paint(object sender, PaintEventArgs e)
- {
- ;
- }
- private void pic_Click(object sender, EventArgs e)
- {
- ;
- }
- private void pic_MouseClick(object sender, MouseEventArgs e)
- {
- //int j = 0;
- if (e.Button == System.Windows.Forms.MouseButtons.Right)
- {
- int j = 0;
- for (; j < UsuallyStorage.Counter; j++)
- {
- if (UsuallyStorage.GetCCircle(j) != null)
- if ((e.X - UsuallyStorage.GetCCircle(j).X) * (e.X - UsuallyStorage.GetCCircle(j).X) + (e.Y - UsuallyStorage.GetCCircle(j).Y) * (e.Y - UsuallyStorage.GetCCircle(j).Y) < UsuallyStorage.GetCCircle(j).Radius * UsuallyStorage.GetCCircle(j).Radius)
- {
- foreach(int Neigh in UsuallyStorage.GetCCircle(j).Neighbours)
- {
- UsuallyStorage.GetCCircle(Neigh).Neighbours.Remove(j);
- }
- if (UsuallyStorage.GetCCircle(j).Selected)
- Connect--;
- button1.Visible = false;
- Vision = false;
- label1.Visible = false;
- label2.Visible = false;
- label1.Text = "";
- UsuallyStorage.DeleteCCircle(j);
- pic.Invalidate();
- break;
- }
- }
- }
- else
- {
- timer1.Enabled = true;
- int j = 0;
- // bool flag = true;
- for (; j < UsuallyStorage.Counter; j++)
- {
- if (UsuallyStorage.GetCCircle(j) != null)
- {
- if ((e.X - UsuallyStorage.GetCCircle(j).X) * (e.X - UsuallyStorage.GetCCircle(j).X) + (e.Y - UsuallyStorage.GetCCircle(j).Y) * (e.Y - UsuallyStorage.GetCCircle(j).Y) < UsuallyStorage.GetCCircle(j).Radius * UsuallyStorage.GetCCircle(j).Radius)
- {
- UsuallyStorage.GetCCircle(j).DoSelect();
- if (UsuallyStorage.GetCCircle(j).Selected)
- Connect++;
- else
- Connect--;
- if (Connect == 1)
- {
- button1.Visible = true;
- label1.Visible = true;
- label2.Visible = true;
- //Vision = true;
- }
- else
- {
- button1.Visible = false;
- Vision = false;
- label1.Visible = false;
- label2.Visible = false;
- label1.Text = "";
- }
- if (Connect == 2)
- {
- Connect = 0;
- int k = 0;
- for (; k < UsuallyStorage.Counter; k++)
- {
- if (UsuallyStorage.GetCCircle(k) != null)
- if (UsuallyStorage.GetCCircle(k).Selected)
- {
- UsuallyStorage.GetCCircle(k).DoSelect();
- break;
- }
- }
- int l = UsuallyStorage.Counter;
- for (; l > 0; l--)
- {
- if (UsuallyStorage.GetCCircle(l) != null)
- if (UsuallyStorage.GetCCircle(l).Selected)
- {
- UsuallyStorage.GetCCircle(k).DoSelect();
- break;
- }
- }
- if (!UsuallyStorage.GetCCircle(k).Neighbours.Contains(l))
- {
- UsuallyStorage.GetCCircle(k).AddNeighbour(l);
- UsuallyStorage.GetCCircle(k).Neighbours.Sort();
- }
- UsuallyStorage.GetCCircle(k).DoSelect();
- if (!UsuallyStorage.GetCCircle(l).Neighbours.Contains(k))
- {
- UsuallyStorage.GetCCircle(l).AddNeighbour(k);
- UsuallyStorage.GetCCircle(l).Neighbours.Sort();
- }
- UsuallyStorage.GetCCircle(l).DoSelect();
- }
- //flag = false;
- break;
- }
- }
- }/*
- if (flag)
- {
- CCircle tmp = new CCircle(e.X, e.Y);
- int index = UsuallyStorage.AddToStorage(tmp);
- }*/
- }
- }
- private void pic_Paint(object sender, PaintEventArgs e)
- {
- e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
- for (int i = 0; i < UsuallyStorage.Counter; i++)
- {
- CCircle a = UsuallyStorage.GetCCircle(i);
- if (a != null)
- {
- Pen myPen;
- myPen = new System.Drawing.Pen(System.Drawing.Color.Black);
- foreach (int neighbour in a.Neighbours)
- {
- CCircle tmp=UsuallyStorage.GetCCircle(neighbour);
- if (tmp!=null)
- e.Graphics.DrawLine(myPen, new Point((int)a.X, (int)a.Y), new Point((int)tmp.X, (int)tmp.Y));
- }
- // a.Paint(e.Graphics);
- }
- }
- for (int i = 0; i < UsuallyStorage.Counter; i++)
- if (UsuallyStorage.GetCCircle(i) != null)
- {
- UsuallyStorage.GetCCircle(i).Paint(e.Graphics, i, Vision);
- }
- }
- private void pic_MouseDown(object sender, MouseEventArgs e)
- {
- int j = 0;
- for (; j < UsuallyStorage.Counter; j++)
- {
- if (UsuallyStorage.GetCCircle(j) != null)
- {
- if ((e.X - UsuallyStorage.GetCCircle(j).X) * (e.X - UsuallyStorage.GetCCircle(j).X) + (e.Y - UsuallyStorage.GetCCircle(j).Y) * (e.Y - UsuallyStorage.GetCCircle(j).Y) < UsuallyStorage.GetCCircle(j).Radius * UsuallyStorage.GetCCircle(j).Radius)
- {
- UsuallyStorage.GetCCircle(j).DoMove();
- isClicked = true;
- DeltaX=e.X-UsuallyStorage.GetCCircle(j).X;
- DeltaY = e.Y - UsuallyStorage.GetCCircle(j).Y;
- IndMov = j;
- break;
- }
- }
- }
- }
- private void pic_MouseUp(object sender, MouseEventArgs e)
- {
- if (UsuallyStorage.GetCCircle(IndMov) != null)
- {
- UsuallyStorage.GetCCircle(IndMov).DoMove();
- isClicked = false;
- // UsuallyStorage.GetCCircle(IndMov).DoSelect();
- }
- }
- private void pic_MouseMove(object sender, MouseEventArgs e)
- {
- if (isClicked && UsuallyStorage.GetCCircle(IndMov)!=null)
- {
- UsuallyStorage.GetCCircle(IndMov).ChangeCenter(e.X - DeltaX, e.Y - DeltaY);
- pic.Refresh();
- }
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- pic.Invalidate();
- }
- private bool MasCheck (int[] array, int k)
- {
- for (int i = 0; i < array.Length; i++)
- if (array[i] == k)
- return true;
- return false;
- }
- private void pic_MouseDoubleClick(object sender, MouseEventArgs e)
- {
- CCircle tmp = new CCircle(e.X, e.Y);
- int index = UsuallyStorage.AddToStorage(tmp);
- }
- private void Deep(int i, SortedSet<int> resArray)// ______________________________________________________________________________________________________________________________________________________________
- {
- Stack<int> myStack = new Stack<int>();
- myStack.Push(i);
- int walkN = 0;
- while (myStack.Count != 0)
- {
- int tmp = myStack.Pop();
- if (!resArray.Contains(tmp))
- {
- resArray.Add(tmp);
- UsuallyStorage.GetCCircle(tmp).ChangeNumero(walkN + 1);
- label1.Text += (tmp + 1).ToString() + " ";
- foreach (int nei in UsuallyStorage.GetCCircle(tmp).Neighbours)
- {
- if (!resArray.Contains(nei))
- {
- myStack.Push(nei);
- }
- }
- walkN++;
- }
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- Vision = true;
- for (int q=0; q < UsuallyStorage.Counter; q++)
- if (UsuallyStorage.GetCCircle(q) != null)
- UsuallyStorage.GetCCircle(q).ChangeNumero(-1);
- int i = 0;
- for (; i < UsuallyStorage.Counter; i++)
- if (UsuallyStorage.GetCCircle(i) != null)
- if (UsuallyStorage.GetCCircle(i).Selected)
- break;
- /* int[] resArray = new int[UsuallyStorage.Counter];
- for (int c = 0; c < UsuallyStorage.Counter; c++)
- {
- resArray[c] = -1;
- }*/
- SortedSet<int> resArray=new SortedSet<int>();
- Deep(i, resArray);
- }
- }
- class CCircle
- {
- protected float x;
- protected float y;
- protected float radius;
- protected bool selected;
- protected bool moving;
- protected List<int> neighbours;
- protected String numero;
- public CCircle() { this.x = 0; this.y = 0; this.radius = 30; this.selected = false; moving = false; neighbours = new List<int>(); numero = ""; }
- public CCircle(float x, float y, float radius = 30)
- {
- this.x = x;
- this.y = y;
- this.radius = radius;
- this.selected = false;
- moving = false;
- neighbours = new List<int>();
- numero = "";
- }
- public CCircle(CCircle a)
- {
- this.x = a.x;
- this.y = a.y;
- this.radius = a.radius;
- neighbours = new List<int>();
- numero = "";
- }
- public void DoSelect()
- {
- this.selected = !this.selected;
- }
- public void DoMove()
- {
- this.moving = !this.moving;
- }
- virtual public void Paint(Graphics formGraphics, int numb, bool flag=false)
- {
- string drawString = (numb+1).ToString();
- System.Drawing.Font drawFont = new System.Drawing.Font("Arial", 16);
- System.Drawing.Font numeroFont = new System.Drawing.Font("Arial", 12);
- System.Drawing.SolidBrush textBrush = new System.Drawing.SolidBrush(System.Drawing.Color.White);
- System.Drawing.SolidBrush numeroBrush = new System.Drawing.SolidBrush(System.Drawing.Color.White);
- System.Drawing.SolidBrush indexBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Violet);
- if (!Selected)
- {
- System.Drawing.Brush myBrush;
- myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black);
- formGraphics.FillEllipse(myBrush, x - radius, y - radius, radius * 2, radius * 2);
- formGraphics.DrawString(drawString, drawFont, textBrush, x-10, y-10);
- if (flag)
- {
- formGraphics.FillEllipse(indexBrush,x - 40, y + 10, 40, 40);
- formGraphics.DrawString(numero, numeroFont, numeroBrush, x - 28, y+22);
- }
- }
- else
- {
- System.Drawing.Brush myBrush;
- myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Violet);
- formGraphics.FillEllipse(myBrush, x - radius, y - radius, radius * 2, radius * 2);
- formGraphics.DrawString(drawString, drawFont, textBrush, x-10, y-10);
- if (flag)
- {
- formGraphics.FillEllipse(indexBrush, x - 40, y + 10, 40, 40);
- formGraphics.DrawString(numero, numeroFont, numeroBrush, x - 28, y+22);
- }
- }
- }
- public float X { get { return this.x; } }
- public float Y { get { return this.y; } }
- public float Radius { get { return this.radius; } }
- public bool Selected { get { return this.selected; } }
- public bool Moving { get { return this.moving; } }
- public List<int> Neighbours { get { return this.neighbours; } }
- public void ChangeCenter (float NX, float NY)
- {
- this.x = NX;
- this.y = NY;
- }
- public void ChangeNumero(int a)
- {
- String tmp = a.ToString();
- this.numero = tmp;
- }
- public void AddNeighbour (int x)
- {
- neighbours.Add(x);
- }
- }
- class CCircleStorage
- {
- private CCircle[] a;
- private int counter { get; set; }
- public CCircleStorage()
- {
- a = new CCircle[10];
- counter = 10;
- for (int i = 0; i < 10; i++)
- a[i] = null;
- }
- public CCircleStorage(int b)
- {
- this.a = new CCircle[b];
- counter = b;
- for (int i = 0; i < 10; i++)
- a[i] = null;
- }
- public int Counter { get { return this.counter; } }
- public void AddToPosition(CCircle v1, int pos)
- {
- if (pos > counter - 1)
- return;
- a[pos] = v1;
- }
- public bool FreeCheck()
- {
- for (int i = 0; i < counter; i++)
- {
- if (a[i] == null)
- return true;
- }
- return false;
- }
- public void AddPlaces(int k)
- {
- CCircle[] new_a = new CCircle[counter + k];
- int i = 0;
- for (; i < counter; i++)
- new_a[i] = a[i];
- for (; i < k; i++)
- new_a[i] = null;
- a = new_a;
- counter += k;
- return;
- }
- public CCircle GetCCircle(int k)
- {
- if (!(k > counter - 1))
- return a[k];
- else
- return null;
- }
- public void DeleteCCircle(int k)
- {
- if (!(k > counter - 1))
- a[k] = null;
- else
- return;
- }
- public int AddToStorage(CCircle v1)
- {
- for (int i = 0; i < counter; i++)
- {
- if (a[i] == null)
- {
- a[i] = v1;
- return i;
- }
- }
- AddPlaces(1);
- AddToPosition(v1, counter - 1);
- return counter - 1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment