Results 1 to 2 of 2
  1. #1
    DesertFlower is offline Member
    Join Date
    Oct 2012
    Posts
    7
    Rep Power
    0

    Default Can't get key click to move robot

    I am not understanding why I cannot get this code to work. It compiles just fine, but when I run & start it the keys clicked won't make the bot move as directed. Nothing happens. What am I missing? Bot is supposed to move, turn right or left according to the keys clicked then lose a single fuel for each good move, or lose two fuels each time it cannot moveForward. When the fuel is empty, the robot will break.

    Java Code:
    import becker.robots.*;//program sets keys to move bot around city
    
    public class RobotCar extends RobotGB //creates RobotCar using provided values
    {
        public RobotCar(CityGB city, int street, int avenue, Direction direction)
        {
            super(city,street,avenue,direction);
    		  
    }	
    	public int getFuel = 10;	  
    	protected void keyTyped(char key)
    	{
    		//set key s to move robot forward one 
    			
    		if(key=='s'||key=='S')
    		{
    		if(getFuel>0)
    		{
    		if (pathIsClear())
    		{
    		moveForward();
    		
    		//set up fuel gauge to remove one fuel after move
    		getFuel-=1;
    		//set up fuel gauge to remove two fuel if unable to move forward
    		}
    		else
    		{
    		getFuel-=2;
    		}
    		}
    		else
    		{
    		breakRobot("getFuel<1");
    		}
    		}
    		//set key x to move robot one to the right
    		else if(key=='x'||key=='X')
    		{
    		turnRight();
    		getFuel-=1;		}
    		//set key z to move robot one to the left
    		else if(key=='z'||key=='Z')
    		{
    		turnLeft();
    		getFuel-=1;
    
    		}
    	}
    	}

  2. #2
    DesertFlower is offline Member
    Join Date
    Oct 2012
    Posts
    7
    Rep Power
    0

    Default Re: Can't get key click to move robot

    I figured out what I was doing wrong-if this helps anyone. I had to click the map after running and starting the program. I didn't know this and didn't read it anywhere on the site (although I'm sure it's here somewhere, right?). Just replying in case any other noobs needed this info. Thanks

Similar Threads

  1. Robot map
    By Naphoria in forum New To Java
    Replies: 5
    Last Post: 01-16-2012, 05:06 PM
  2. Replies: 3
    Last Post: 07-04-2011, 12:50 PM
  3. Replies: 2
    Last Post: 06-22-2011, 01:19 PM
  4. Robot
    By rp181 in forum Advanced Java
    Replies: 4
    Last Post: 12-07-2010, 12:58 AM
  5. Problem with click to move ball algorithm
    By Laythe in forum Java Applets
    Replies: 1
    Last Post: 12-19-2009, 12:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •