备份CatanBuilding瘦身独立工程
This commit is contained in:
29
Assets/Scripts/HexGrid/Math/HexCoord.cs
Normal file
29
Assets/Scripts/HexGrid/Math/HexCoord.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
namespace HexGrid.Math
|
||||
{
|
||||
|
||||
public struct HexCoord {
|
||||
|
||||
public int q; // axial q(col)
|
||||
public int r; // axial r(row)
|
||||
public HexCoord(int q, int r) { this.q = q; this.r = r; }
|
||||
public static readonly HexCoord[] neighbors = {
|
||||
new HexCoord(+1, 0),
|
||||
new HexCoord(+1, -1),
|
||||
new HexCoord(0, -1),
|
||||
new HexCoord(-1, 0),
|
||||
new HexCoord(-1, +1),
|
||||
new HexCoord(0, +1)
|
||||
};
|
||||
public HexCoord Neighbor(int i) => new HexCoord(q + neighbors[i].q, r + neighbors[i].r);
|
||||
|
||||
public override bool Equals(object obj) {
|
||||
if (!(obj is HexCoord)) return false;
|
||||
HexCoord o = (HexCoord)obj;
|
||||
return q == o.q && r == o.r;
|
||||
}
|
||||
//??
|
||||
public override int GetHashCode() => q * 73856093 ^ r * 19349663;
|
||||
public override string ToString() => $"({q},{r})";
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user