Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2014
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. a.
  2. private boolean hallIsClear() {
  3.     if (pos == hall.length - 1 && facingRight) {
  4.         return true;
  5.     }
  6.     else if (pos == 0 && !facingRight) {
  7.         return true;
  8.     }  
  9.     else {
  10.         return false;
  11.     }
  12.    
  13. b.
  14. private void move() {
  15.     if (hall[pos] > 0) {
  16.         hall[pos] -= 1;
  17.     }
  18.     if (hall[pos] == 0) {
  19.         if (!forwarMoveBlocked()) {
  20.             if (facingRight) {
  21.                 pos += 1;
  22.             }
  23.             else {
  24.                 pos -= 1;
  25.             }
  26.         else {
  27.             if (!facingRight) {
  28. facingRight == true;
  29.             else {
  30.                 !facingRight;
  31.  
  32. c.
  33. public int clearHall() {
  34.     int numMoves = 0;
  35.     while (!hallIsClear()) {
  36.         move();
  37.         numMoves++;
  38.     }
  39.     return numMoves;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement