CheckerboardKarel

CheckerboardKarel - if(leftIsClear()) turnLeft();...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
/* * File: CheckerboardKarel.java * ---------------------------- * When you finish writing it, the CheckerboardKarel class should draw * a checkerboard using beepers, as described in Assignment 1. You * should make sure that your program works for all of the sample * worlds supplied in the starter folder. */ import stanford.karel.*; public class CheckerboardKarel extends SuperKarel { public void run(){ putBeeper(); if(frontIsClear()) while(frontIsClear()) { if(frontIsClear()) move(); handleWallsAndMove(); } // When only one column is present else oneColumn(); } private void climbEast(){ turnLeft(); if(frontIsClear()){ move1StepPutBeeper(); turnLeft(); } } private void climbWest(){ turnRight(); if(frontIsClear()){ move1StepPutBeeper(); turnRight(); } } private void climbEastForOddRowNumber(){
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: if(leftIsClear()) turnLeft(); if(frontIsClear()){ move(); turnLeft(); if(frontIsClear()) move1StepPutBeeper(); } } private void move1StepPutBeeper() { move(); putBeeper(); } private void handleWallsAndMove(){ if(frontIsClear()){ move1StepPutBeeper(); // When odd row no -- two steps are taken and wall is encountered if(frontIsBlocked()) climbEastForOddRowNumber(); } // When even row no - one step is taken and wall is encountered else if(leftIsClear()&&facingEast()) climbEast(); else if(rightIsClear()&&facingWest()) climbWest(); } private void oneColumn(){ if(leftIsClear()) turnLeft(); while(frontIsClear()) { if(frontIsClear()) move(); if(frontIsClear()) move1StepPutBeeper(); } } }...
View Full Document

This note was uploaded on 10/25/2010 for the course CS 106A at Stanford.

Page1 / 2

CheckerboardKarel - if(leftIsClear()) turnLeft();...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online