PuzzleGame/PuzzleGameProject/Assets/Scripts/DungeonGenerator/Point.cs

25 lines
No EOL
741 B
C#

using System;
namespace DungeonGenerator
{
public struct Point
{
public int X { get; }
public int Y { get; }
public Point(int x, int y) {
X = x;
Y = y;
}
public override bool Equals(object obj) => obj is Point p && X == p.X && Y == p.Y;
public override int GetHashCode() => HashCode.Combine(X, Y);
public override string ToString() => $"({X}, {Y})";
public static Point operator +(Point a, Point b) => new Point(a.X + b.X, a.Y + b.Y);
public static Point operator -(Point a, Point b) => new Point(a.X - b.X, a.Y - b.Y);
public int ManhattanDistance(Point other) => Math.Abs(X - other.X) + Math.Abs(Y - other.Y);
}
}