Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace Lines
- {
- class Wave
- {
- private int[][] mas;
- private Point start;
- private Point finish;
- private Size size;
- private List<Point> short_path = new List<Point>();
- public Wave(int[][] mas_1, Point start_1, Point finish_1)
- {
- mas = mas_1;
- start = finish_1;
- finish = start_1;
- size = new Size(mas.Length, mas.First().Length);
- MessageBox.Show(mas[start.X][start.Y].ToString());
- }
- public void SetParameters(int[][] mas_1, Point start_1, Point finish_1)
- {
- mas = mas_1;
- start = finish_1;
- finish = start_1;
- size = new Size(mas.Length, mas[0].Length);
- }
- public Point[] GetPath()
- {
- for (int i = -1; NextStep(i); ++i) ;
- return short_path.ToArray();
- }
- private bool NextStep(int step)
- {
- for (int i = 0; i != size.Width; ++i)
- {
- for (int j = 0; j != size.Height; ++j)
- {
- if (mas[i][j] == -2)
- {
- short_path.Add(new Point(i, j));
- for (; step != -3; --step)
- {
- if (short_path.Last().X != 0)
- if (mas[short_path.Last().X - 1][short_path.Last().Y] == step)
- short_path.Add(new Point(short_path.Last().X - 1, short_path.Last().Y));
- if (short_path.Last().Y != size.Width - 1)
- if (mas[short_path.Last().X][short_path.Last().Y + 1] == step)
- short_path.Add(new Point(short_path.Last().X, short_path.Last().Y + 1));
- if (short_path.Last().X != size.Height - 1)
- if (mas[short_path.Last().X + 1][short_path.Last().Y] == step)
- short_path.Add(new Point(short_path.Last().X + 1, short_path.Last().Y));
- if (short_path.Last().Y != 0)
- if (mas[short_path.Last().X][short_path.Last().Y - 1] == step)
- short_path.Add(new Point(short_path.Last().X, short_path.Last().Y - 1));
- }
- return false;
- }
- if (mas[i][j] == step)
- {
- if (i != 0)
- if (mas[i - 1][j] == 0)
- mas[i - 1][j] = step + 1;
- if (j != size.Width - 1)
- if (mas[i][j + 1] == 0)
- mas[i][j + 1] = step + 1;
- if (i != size.Height - 1)
- if (mas[i + 1][j] == 0)
- mas[i + 1][j] = step + 1;
- if (j != 0)
- if (mas[i][j - 1] == 0)
- mas[i][j - 1] = step + 1;
- }
- }
- }
- return false;
- }
- }
- }
Add Comment
Please, Sign In to add comment