Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Just press ctrl+f and type in #.#.#
- ---------------------------
- 2.1.1
- // The Starting Function
- function start() {
- gotoBall();
- returnSpot();
- }
- // Function To Goto Ball
- function gotoBall(){
- turnLeft();
- fourMove();
- turnRight();
- move();
- move();
- takeBall();
- }
- // Function To Return Back
- function returnSpot(){
- turnAround();
- move();
- move();
- turnLeft();
- fourMove();
- turnLeft();
- putBall();
- }
- // Function To Move Four Times
- function fourMove(){
- move();
- move();
- move();
- move();
- }
- ---------------------------
- 2.1.2
- /* This program will have Karel run around the racetrack
- * 8 times. */
- function start() {
- tennisBalls();
- }
- function goAround(){
- while (noBallsPresent()){
- move();
- if (frontIsBlocked()){
- tennisBalls();
- turnLeft();
- move();
- }
- }
- }
- function tennisBalls(){
- for (var i = 0; i < 32; i++) {
- while(frontIsClear()) {
- move();
- }
- putBall();
- turnLeft();
- }
- }
- ---------------------------
- 2.1.3
- // Main starting function.
- function start() {
- while(frontIsClear()) {
- buildTower();
- turnAround();
- climbDown();
- move();
- if(frontIsClear()) {
- move();
- }
- }
- if(frontIsBlocked()) {
- turnAround();
- if(frontIsClear()) {
- move();
- }
- if(noBallsPresent()) {
- turnAround();
- if(frontIsClear()) {
- move();
- }
- buildTower();
- turnAround();
- climbDown();
- }
- if(ballsPresent()) {
- turnAround();
- if(frontIsClear()) {
- move();
- }
- }
- if(frontIsClear()) {
- turnAround();
- move();
- }
- }
- if(notFacingEast()) {
- turnAround();
- }
- }
- function buildTower() {
- putBall();
- turnLeft();
- move();
- putBall();
- move();
- putBall();
- }
- function climbDown() {
- move();
- move();
- turnLeft();
- }
- ---------------------------
- 2.1.4
- // Function To Clean Up All The Balls
- function start() {
- ballsTaken();
- while(leftIsClear()) {
- endUpFacingEast();
- ballsTaken();
- if(rightIsClear()){
- endUpFacingWest();
- ballsTaken();
- } else {
- turnAround();
- }
- }
- }
- function ballsTaken() {
- if(ballsPresent()) {
- takeBall();
- }
- while(frontIsClear()) {
- move();
- if(ballsPresent()) {
- takeBall();
- }
- }
- }
- function endUpFacingEast() {
- turnLeft();
- move();
- turnLeft();
- }
- function endUpFacingWest() {
- turnRight();
- move();
- turnRight();
- }
- ---------------------------
- 2.1.5
- function start(){
- move();
- while(ballsPresent()) {
- takeBall();
- move();
- putBall();
- putBall();
- turnAround();
- move();
- turnAround();
- }
- move();
- while(ballsPresent()) {
- takeBall();
- turnAround();
- move();
- putBall();
- turnAround();
- move();
- }
- turnAround();
- move();
- move();
- turnAround();
- }
- function fakeOne() {
- move();
- }
- // My fake code
- function fakeTwo() {
- move();
- }
- // My fake code
- function fakeThree() {
- move();
- }
- ---------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement