-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUTIL.cs
More file actions
36 lines (32 loc) · 1.05 KB
/
UTIL.cs
File metadata and controls
36 lines (32 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
static class UTIL
{
public static int Distance(Field a, Field b)
{
return Math.Abs(a.X - b.X) + Math.Abs(a.X - b.X);
}
public static int Distance(Field a, (int X, int Y) b)
{
return Math.Abs(a.X - b.X) + Math.Abs(a.X - b.X);
}
public static bool CheckForInBound(int x, int y)
{
return x >= 0 && y >= 0 && x < GameBoard.width && y < GameBoard.height;
}
public static Field GetFurthestField(List<Field> fields)
{
bool toTheRight = Player.PlayDirection == 1;
int startIndex = toTheRight ? fields.Count - 1 : 0;
int target = toTheRight ? 0 : fields.Count - 1;
for(int i = startIndex; toTheRight && i >= 0 || !toTheRight && i <= fields.Count - 1; i+=Player.PlayDirection * -1)
{
if (fields[i].inRangeOfRecycler && fields[i].scrapAmount == 1)
continue;
return fields[i];
}
//FallBack
if (Player.PlayDirection == 1)
return fields[fields.Count - 1];
else
return fields[0];
}
}