Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import info.gridworld.actor.Bug;
- /**
- * Write a description of class DancingBug here.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- public class DancingBug extends Bug{
- private int [] turns;
- private int steps;
- private int dances;
- public DancingBug(int [] turns){
- steps = 0;
- dances = 0;
- this.turns = turns;
- }
- public void act(){
- if (dances < turns[steps]){ //if still needs to turn
- turn();
- dances++;
- }else{
- if(canMove()){
- move();
- }else{
- turn();
- turn();
- }
- steps++;
- dances = 0;
- }
- if (steps == turns.length){
- steps = 0;
- }
- }
- }
Add Comment
Please, Sign In to add comment