Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
- }
- /**
- * Turns right
- * @return void
- * */
- public void turnRight(){
- int del = World.delay();
- World.setDelay(0);
- turnLeft();
- turnLeft();
- World.setDelay(del);
- 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;
- }
- // L4A4
- /**
- * Method to check whether karel is standing on a pothole
- * @return boolean
- * */
- boolean retPothole = true;
- public boolean onPothole(){
- int delay= World.delay(); // saves the default delay of the world
- World.setDelay(0); // delay 0 to make the action instantaneous
- turnLeft();
- turnLeft();
- if (frontIsClear()){
- retPothole = true;
- } else {
- retPothole = false;
- }
- turnLeft();
- World.setDelay(delay); // sets delay back to normal
- turnLeft();
- return retPothole;
- }
- /**
- * Method for Karel to walk (standing up)
- * @return void
- * */
- public void walk(){
- int delay= World.delay(); // saves the default delay of the world
- World.setDelay(0); // delay 0 to make the action instantaneous
- turnRight();
- move();
- World.setDelay(delay); // sets delay back to normal
- turnLeft();
- }
- /**
- * Method to fill potholes
- * @return void
- * */
- public void fillPothole(){
- int delay= World.delay(); // saves the default delay of the world
- World.setDelay(0); // delay 0 to make the action instantaneous
- turnLeft();
- turnLeft();
- World.setDelay(delay); // sets delay back to normal
- move();
- putBeeper(); // Fills the pothole
- World.setDelay(0); // delay 0 to make the action instantaneous
- turnLeft();
- turnLeft();
- World.setDelay(delay); // sets delay back to normal
- move();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement