Tell me how to fix the position of the figures (the triangle and the square move along the console, when their coordinates match, you need to fix their position)? I think in a similar way:

1st figure

public void DrawRectangle() { for (int i = 0; i < size; i++) { Console.SetCursorPosition(x, y + i); Console.WriteLine("*"); Console.SetCursorPosition(x + i, y + size); Console.WriteLine("*"); Console.SetCursorPosition(x + size, y + i); Console.WriteLine("*"); Console.SetCursorPosition(x + i, y); Console.WriteLine("*"); int[,] array1 = new int[x, y]; } } 

2nd figure

 public void DrawTriangle() { for (int i = 0; i < size; i++) { Console.SetCursorPosition(x1, y1 + i); Console.WriteLine("*"); Console.SetCursorPosition(x1 + i, y1 + size); Console.WriteLine("*"); Console.SetCursorPosition(x1 + i, y1 + i); Console.WriteLine("*"); int[,] array = new int[x1,y1]; } } 

And checking for the coincidence of coordinates

  if(array == array1) { return; } 
  • How to understand the coordinates of the triangle and the square? In a sense, they intersect anywhere? - Anton Komyshan
  • @AntonKomyshan, yes - Julia Ponomareva

1 answer 1

You can instead of int[,] , operate with a higher-level representation as a Point from System.Drawing .

Accordingly, if you have a filled Point array, you can check for an intersection like this:

 using System.Drawing; // Не забудьте // Заполняете этот массив точками фигур. Point[] pointsRectangle = new Point[size]; Point[] pointsTrianglee = new Point[size]; // проверка if (pointsRectangle.Intersect(pointsTrianglee).Any()) { // } 

Intersect will return to you all the points whose coordinates coincide (Point override the Equals method - by this point the points are compared by the X and Y coordinates correctly). Well, Any returns true if there is at least one matching point.

  • And if simpler? - Julia Ponomareva
  • @JuliaPonomareva, and what you do not understand? What do the Intersect and Any methods do? or how to do it through for loops? You can cite your logic of figures so that you can bring the solution on your example, and that from the fact that now the question is difficult to give a clear answer. - Anton Komyshan
  • I am not familiar with these methods at all, but on the task I have to do it through for - Julia Ponomareva
  • The triangle moves to the right when you press the right arrow and up / down when you click on acc. keys, the square moves to the left when you press the left arrow, up / down - Julia Ponomareva
  • @JuliaPonomareva, The code that you gave is all the code that you have? - Anton Komyshan