Guest User

Untitled

a guest
Jan 23rd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. import info.gridworld.actor.Bug;
  2. /**
  3. * Write a description of class DancingBug here.
  4. *
  5. * @author (your name)
  6. * @version (a version number or a date)
  7. */
  8. public class DancingBug extends Bug{
  9. private int [] turns;
  10. private int steps;
  11. private int dances;
  12. public DancingBug(int [] turns){
  13. steps = 0;
  14. dances = 0;
  15. this.turns = turns;
  16. }
  17.  
  18. public void act(){
  19. if (dances < turns[steps]){ //if still needs to turn
  20. turn();
  21. dances++;
  22. }else{
  23. if(canMove()){
  24. move();
  25. }else{
  26. turn();
  27. turn();
  28. }
  29. steps++;
  30. dances = 0;
  31. }
  32.  
  33. if (steps == turns.length){
  34. steps = 0;
  35. }
  36. }
  37. }
Add Comment
Please, Sign In to add comment