标签:
1.turnRight的使用:
1 import stanford.karel.*; 2 public class Mykarel01 extends Karel{ 3 public void run(){ 4 move(); 5 pickBeeper(); 6 move(); 7 turnLeft(); 8 move(); 9 move(); 10 turnRight(); 11 move(); 12 putBeeper(); 13 move(); 14 } 15 public void turnRight(){ 16 turnLeft(); 17 turnLeft(); 18 turnLeft(); 19 } 20 21 }
2.SuperKarel
1 import stanford.karel.*; 2 public class Mykarel01 extends SuperKarel{ 3 public void run(){ 4 move(); 5 pickBeeper(); 6 move(); 7 turnLeft(); 8 move(); 9 move(); 10 turnRight(); 11 move(); 12 putBeeper(); 13 move(); 14 } 15 16 }
2.6karelFQ
1 import stanford.karel.*; 2 public class ClimbKarel extends Karel{ 3 public void run(){ 4 for(int i=0;i<7;i++){ 5 if(frontIsClear()){ 6 move(); 7 } 8 else{ 9 jumpWall(); 10 } 11 } 12 } 13 public void jumpWall(){ 14 up(); 15 move(); 16 down(); 17 } 18 public void up(){ 19 turnLeft(); 20 while(!rightIsClear()){ 21 move(); 22 } 23 turnRight(); 24 } 25 public void down(){ 26 turnRight(); 27 while(frontIsClear()){ 28 move(); 29 } 30 turnLeft(); 31 } 32 public void turnRight(){ 33 turnLeft(); 34 turnLeft(); 35 turnLeft(); 36 } 37 38 }
标签:
原文地址:http://www.cnblogs.com/ftdwlei/p/4454480.html