-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
70b0dfc
commit fbdaad4
Showing
1 changed file
with
189 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
//This class creates methods to govern the basic movements of the robot. | ||
//Created 02/08/2016 by Trevor B. (PPCG user Eridan) | ||
|
||
import kareltherobot.*; | ||
|
||
public class Commands extends Robot | ||
{ | ||
private int xcoord; | ||
private int ycoord; | ||
private Direction dir; | ||
private int beeperCount; | ||
|
||
public Commands(int street, int avenue, Direction direction, int beepers) | ||
{ | ||
super(street, avenue, direction, beepers); | ||
|
||
xcoord=avenue; | ||
ycoord=street; | ||
dir=direction; | ||
beeperCount=beepers; | ||
} | ||
|
||
//MOVEMENT | ||
|
||
public void move(int count) | ||
{ | ||
for(int i=0;i<count;i++) | ||
{ | ||
super.move(); | ||
} | ||
|
||
if(facingNorth()) | ||
{ | ||
ycoord+=count; | ||
} | ||
else if(facingSouth()) | ||
{ | ||
ycoord-=count; | ||
} | ||
else if(facingEast()) | ||
{ | ||
xcoord+=count; | ||
} | ||
else if(facingWest()) | ||
{ | ||
xcoord-=count; | ||
} | ||
} | ||
|
||
public void move() | ||
{ | ||
move(1); | ||
} | ||
|
||
public void turnLeft(int count) | ||
{ | ||
for(int i=0;i<count;i++) | ||
{ | ||
super.turnLeft(); | ||
} | ||
} | ||
|
||
public void turnLeft() | ||
{ | ||
turnLeft(1); | ||
} | ||
|
||
public void turnRight() | ||
{ | ||
turnLeft(3); | ||
} | ||
|
||
public void turnAround() | ||
{ | ||
turnLeft(2); | ||
} | ||
|
||
//DIRECTIONS | ||
|
||
public void faceNorth() | ||
{ | ||
while(!facingNorth()) | ||
{ | ||
turnLeft(); | ||
} | ||
dir=North; | ||
} | ||
|
||
public void faceSouth() | ||
{ | ||
while(!facingSouth()) | ||
{ | ||
turnLeft(); | ||
} | ||
dir=South; | ||
} | ||
|
||
public void faceEast() | ||
{ | ||
while(!facingEast()) | ||
{ | ||
turnLeft(); | ||
} | ||
dir=East; | ||
} | ||
|
||
public void faceWest() | ||
{ | ||
while(!facingWest()) | ||
{ | ||
turnLeft(); | ||
} | ||
dir=West; | ||
} | ||
|
||
//GOTO | ||
|
||
public void goTo(int xdest,int ydest) | ||
{ | ||
int xdiff=xdest-xcoord; | ||
int ydiff=ydest-ycoord; | ||
|
||
if(xdiff>0) | ||
{ | ||
faceEast(); | ||
} | ||
else | ||
{ | ||
faceWest(); | ||
} | ||
move(xdiff); | ||
|
||
if(ydiff>0) | ||
{ | ||
faceNorth(); | ||
} | ||
else | ||
{ | ||
faceSouth(); | ||
} | ||
move(ydiff); | ||
} | ||
|
||
//BEEPER MANAGEMENT | ||
|
||
public void putBeeper(int count) | ||
{ | ||
for(int i=0;i<count;i++) | ||
{ | ||
super.putBeeper(); | ||
} | ||
beeperCount-=1; | ||
} | ||
|
||
public void putBeeper() | ||
{ | ||
putBeeper(1); | ||
} | ||
|
||
public void pickBeeper(int count) | ||
{ | ||
for(int i=0;i<count;i++) | ||
{ | ||
super.pickBeeper(); | ||
} | ||
beeperCount+=1; | ||
} | ||
|
||
public void pickBeeper() | ||
{ | ||
pickBeeper(1); | ||
} | ||
|
||
public void putAllBeepers() | ||
{ | ||
while(anyBeepersInBeeperBag()) | ||
{ | ||
putBeeper(); | ||
} | ||
} | ||
|
||
public void pickAllBeepers() | ||
{ | ||
while(nextToABeeper()) | ||
{ | ||
pickBeeper(); | ||
} | ||
} | ||
} |