marclundgren
3/20/2013 - 10:46 PM

restroomEtiquette.js

function restroomEtiquette(you, restroom) {
  var toilet = restroom.toilet,
      urinal = restroom.urinal;

  while (true) {
    if (you.needToGo === 1) {
      if (you.urinalsOkay && restroom.urinalAvailable()) {
        you.evacuate();

        urinal.flush();

        if (you.madeMess) {
          you.cleanUp();
        }

        break;
      }
      else if (restroom.stallAvailable()) {
        if (you.positionPref === 'stand') {
          toilet.liftSeat(); // yes you
        }

        you.evacuate();

        // if (toilet.yellowLetItMellow) {
        //   toilet.flush();
        // }
        toilet.flush();

        if (you.madeMess) {
          you.cleanUp();
        }

        break;
      }
      else {
        you.dance();

        continue; // you'll have to wait
      }
    }
    else if (you.needToGo === 2) {
      if (restroom.stallAvailable()) {
        you.evacuate();

        toilet.flush();

        if (you.madeMess) {
          you.cleanUp();
        }

        break;
      }
      else {
        you.dance();

        continue; // you'll have to wait
      }
    }
    else if (you.needToGo === 3) {
      if (restroom.stallAvailable()) {
        you.evacuate();

        toilet.flush();

        if (you.madeMess) {
          you.cleanUp();
        }
        else {
          you.cleanUp(); // yes you did
        }

        break;
      }
      else {
        you.dance();

        continue; // you'll have to wait
      }
    }
    else {
      you.hurryHome();

      break;
    }
  }

  // if (me.handsSoiled) {
  //   me.washHands();
  // }
  me.washHands(); // you never know
}