I am using this code to start a class ZigZagBug in a "game"
known as GridWorld. We use this in our Programming class right now.
Anyway, my code does what it is supposed to do, I know what the lines do, but
how can I describe them with comments?
Here is the code.
import info.gridworld.actor.Bug; public class ZigZagBug extends Bug { int counter = 1; public ZigZagBug(){ turn(); } public void act(){ if(canMove()){ //This gets the adjacent location, of the direction that the bug is facing. //IE - Faces Right-North, the next location is the location directly in front of what the bug faces. moveTo(getLocation().getAdjacentLocation(getDirection())); setDirection(getDirection() + 90 + ((counter++)%2 * 180)); }else{ //If the bug cannot move, it turns 180 degrees and then moves again. setDirection(getDirection() + 180); } } }
Now, what is..
This for?
int counter = 1;
And this for?
setDirection(getDirection() + 90 + ((counter++)%2 * 180));