Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. @Override
  2. public void step() {
  3.  
  4. if (askedToGo != null) {
  5.  
  6. Position thisPos = owner.getPosition(this);
  7. Position lclNextPos = thisPos.moveDirection(askedToGo);
  8.  
  9. if (owner.canGo(lclNextPos)) {
  10. IBDObject nextSquare = owner.get(lclNextPos);
  11. if (nextSquare instanceof BDDiamond)
  12. diamondCnt++;
  13. if (nextSquare instanceof BDBug)
  14. kill();
  15. if (nextSquare instanceof BDRock) {
  16. nextSquare = new BDRock(owner);
  17. BDRock rock = (BDRock) owner.get(lclNextPos);
  18. if (rock.push(askedToGo)){
  19. prepareMoveWithTry(lclNextPos);
  20. }
  21. else return;
  22. }
  23. prepareMoveWithTry(lclNextPos);
  24. }
  25. askedToGo = null;
  26. }
  27. super.step();
  28. }
  29. //Hjelpemetode slik at step() blir noe kortere grunnet try/catch rundt prepareMove()
  30. private void prepareMoveWithTry(Position pos) {
  31. try {
  32. prepareMove(pos);
  33. } catch (IllegalMoveException e) {
  34. e.printStackTrace();
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement