Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace ConsoleApp2
- {
- class Program
- {
- static Cell[,] map = new Cell[10, 10];
- static List<Cell> ClosedList = new List<Cell>();
- static void Main(string[] args)
- { int start_x = int.Parse(Console.ReadLine());
- int start_y = int.Parse(Console.ReadLine());
- int end_x = int.Parse(Console.ReadLine());
- int end_y = int.Parse(Console.ReadLine());
- Cell start_cell = map[start_x, start_y];
- Cell end_cell = map[end_x, end_y];
- for (int i = 0; i < 10; i++)
- {
- for (int j = 0; j < 10; j++)
- {
- map[j, i] = new Cell('#', ConsoleColor.White);
- Cell k = map[j, i];
- k.H = Math.Abs(j - end_x) + Math.Abs(i - end_y);
- }
- }
- Cell[] er = GetNearby(9, 9);
- foreach (var u in er)
- {
- u.IsLocked = true;
- }
- //PutBlocks(3);
- Render();
- Console.ReadLine();
- }
- static void Render()
- {
- for (int i = 0; i < 10; i++)
- {
- for (int j = 0; j < 10; j++)
- {
- Cell cell = map[j, i];
- Console.SetCursorPosition(j, i);
- if (cell.IsLocked)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- }
- else if (cell.IsPath)
- {
- Console.ForegroundColor = ConsoleColor.Yellow;
- }
- else
- {
- Console.ForegroundColor = cell.Color;
- }
- Console.Write(cell.Symbol);
- }
- }
- }
- static void FindPath(int x1, int y1, int x2, int y2)
- {
- List<Cell> OpenList = new List<Cell>(GetNearby(x1,y1));
- List<Cell> ClosedList = new List<Cell>();
- OpenList.AddRange(GetNearby(x1, y1));
- OpenList.Remove(map[x1, y1]);
- ClosedList.Add(map[x1, y1]);
- Cell start = map[x1, y1];
- start.IsPath= true;
- }
- static void PutBlocks (int number)
- {
- Random rand = new Random();
- int x = rand.Next(4, 7);
- int y = rand.Next(2, 6);
- Cell k = map[x,y];
- k.IsLocked = true;
- for (int i = 0; i < number; i++)
- {
- Cell ki = map[x, y + i];
- ki.IsLocked = true;
- }
- }
- static Cell[] GetNearby(int x , int y)
- {
- List<Cell> NearbyCell = new List<Cell>();
- int xi = 0, yi = 0;
- Cell StartPoint = map[x, y];
- if (StartPoint.IsLocked)
- {
- Console.WriteLine("не та точка");
- }
- else
- {
- for (xi = x - 1; xi <= x + 1; xi++)
- {
- for (yi = y - 1; yi <= y + 1; yi++)
- {
- if (xi < 0 || yi < 0 || xi > 9 || yi > 9)
- {
- continue;
- }
- else
- {
- Cell k = map[xi, yi];
- if (k.IsLocked == false)
- {
- k = map[xi, yi];
- k.Parent = map[x, y];
- NearbyCell.Add(k);
- }
- }
- }
- }
- }
- return NearbyCell.ToArray();
- }
- }
- class Cell
- {
- public int F, G, H;
- public char Symbol = '@';
- public ConsoleColor Color;
- public bool IsLocked = false;
- public bool IsPath = false;
- public Cell Parent;
- public Cell(char symbol, ConsoleColor color)
- {
- Symbol = symbol;
- Color = color;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement