Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- EsperBot File for lesson 4
- */
- package Lesson4;
- import kareltherobot.Robot;
- import kareltherobot.World;
- import java.sql.Wrapper;
- import java.util.Scanner;
- public class EsperBot extends Robot {
- public EsperBot(int street, int avenue, Direction direction, int beeperCount) {
- super(street, avenue, direction, beeperCount);
- }
- public static void main(String[] args) {
- World.setDelay(50);
- World.setVisible();
- World.setSize(10, 10);
- World.showSpeedControl(true);
- Lesson3.Activity1 zgod = new Lesson3.Activity1(1, 3, North, -1);
- zgod.shuttleRun();
- }
- /**
- * Turns right
- * @return void
- * */
- public void turnRight(){
- World.setDelay(0);
- turnLeft();
- turnLeft();
- World.setDelay(50);
- turnLeft();
- }
- /**
- * Determines whether the left is clear
- * @return boolean
- * */
- boolean retLeft = true;
- public boolean leftIsClear() {
- if (facingNorth()) { //positions the robot to face west
- turnLeft();
- }
- else if (facingSouth()) { //positions the robot to face west
- turnRight();
- }
- else if (facingEast()) { //positions the robot to face west
- turnLeft();
- turnLeft();
- }
- if (frontIsClear()){ // checks if the front is clear. If it is, it returns true
- retLeft = true;
- }else {
- retLeft = false;
- }
- turnRight();
- return retLeft;
- }
- /**
- * Method to detect whether there is a stair in front of the robot to go up
- * @return boolean
- * */
- boolean retStair = true;
- public boolean inStair(){
- if (facingNorth()){
- turnRight();
- }
- if (frontIsClear()) {
- retStair = false;
- }
- else{
- retStair = true;
- }
- turnLeft();
- return retStair;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement