Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class OrdnungMussSein extends BouncerApp {
- @Override
- public void bounce() {
- loadMap("Cleanup");
- cleanThemAll();
- }
- private void cleanThemAll () {
- for (int i=0; i < 8; i++) {
- walkingRight();
- walkingLeft();
- }
- }
- /*Method: walking
- **
- * Combines the searching task with changing of search-row
- */
- private void walkingRight() {
- searchingAndCleaningRight();
- changeLineRight();
- }
- private void walkingLeft() {
- searchingAndCleaningLeft();
- changeLineLeft();
- }
- /*Method: searchingAndCleaning
- **
- * Cleans the red tiles while moving through the lines
- */
- private void searchingAndCleaningRight () {
- while (bouncer.canMoveForward()) {
- redToWhite();
- bouncer.move();
- }
- }
- private void searchingAndCleaningLeft () {
- while (bouncer.canMoveForward()) {
- redToWhite();
- bouncer.move();
- }
- }
- /*Method: changeLine
- **
- * Changes the line which bouncer searches for red tiles.
- */
- private void changeLineRight() {
- while (bouncer.canNotMoveForward()) {
- turningRight();
- bouncer.move();
- if (bouncer.canNotMoveLeft()) {
- turningRight();
- }
- else {
- passingHurdlesRight();
- while (bouncer.canMoveForward()) {
- bouncer.move();
- redToWhite();
- }
- }
- redToWhite();
- }
- }
- private void changeLineLeft(){
- while (bouncer.canNotMoveForward()){
- bouncer.turnLeft();
- bouncer.move();
- if (bouncer.canNotMoveRight()) {
- bouncer.turnLeft();
- }
- else {
- passingHurdlesLeft();
- while (bouncer.canMoveForward()) {
- bouncer.move();
- redToWhite();
- }
- }
- redToWhite();
- }
- }
- /*Method: passingHurdlesRight
- **
- * Allows bouncer to pass obstacles coming from the left.
- */
- private void passingHurdlesRight () {
- bouncer.turnLeft();
- bouncer.move();
- bouncer.move();
- bouncer.turnLeft();
- bouncer.move();
- turningRight();
- }
- /*Method: passingHurdlesRight
- **
- * Allows bouncer to pass obstacles coming from the right.
- */
- private void passingHurdlesLeft () {
- turningRight();
- bouncer.move();
- bouncer.move();
- turningRight();
- bouncer.move();
- bouncer.turnLeft();
- }
- /*Method: turningRight
- **
- * Turns bouncer three times. Can be used to turn him to the right side.
- */
- private void turningRight (){
- for (int i=0; i < 3; i++){
- bouncer.turnLeft();}
- }
- /*Method: redToWhite
- **
- * Turns red fields into white ones.
- */
- private void redToWhite () {
- if (bouncer.isOnFieldWithColor(FieldColor.RED)) {
- bouncer.paintField(FieldColor.WHITE);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement