Last active
March 7, 2020 18:06
-
-
Save be7DOTis/ffcf45ad6a15b3650e76e0b849f8515b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void printGameGrid(List<Vector2Int> Path, SnakeGame Snake) | |
{ | |
string gridString = "\r\n"; | |
// Loop through the y axis backwaaards | |
for (int y = Snake.Size.y; y > 0 ; y--) | |
{ | |
// Loop through the x axis | |
for (int x = 0; x < Snake.Size.x; x++) | |
{ | |
// Retrieve the game grid content at the position [x,y] | |
SnakeGame.Cell cellContent = Snake[x, y]; | |
if (cellContent == SnakeGame.Cell.Snake) | |
{ | |
gridString = gridString + " S "; | |
} | |
else if (cellContent == SnakeGame.Cell.Food) | |
{ | |
gridString = gridString + " 0 "; | |
} | |
//Path and Food or Snake dont have mutually exlusive positions | |
else if (checkIfInPath(new Vector2Int(x, y), Path) && cellContent != SnakeGame.Cell.Snake) | |
{ | |
gridString = gridString + " X "; | |
} | |
else | |
{ | |
gridString = gridString + " + "; | |
} | |
} | |
gridString = gridString + "\r\n"; | |
} | |
Debug.Log(gridString); | |
} | |
bool checkIfInPath(Vector2Int location, List<Vector2Int> path) | |
{ | |
if (path != null) | |
{ | |
foreach (Vector2Int cellIndex in path) | |
{ | |
if (location == cellIndex) | |
{ | |
return true; | |
} | |
} | |
return false; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment