Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public void move(){
- //aim coordinates
- Point2D.Double aim = new Point2D.Double();
- switch(currentDirection){
- case NORTH://if the left handside is a space...
- if(maze.getCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y-1 )==' '
- ||maze.getCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y-1 )=='X'){
- //...move right
- aim.x=maze.getRoboCoordinate().x;
- aim.y=maze.getRoboCoordinate().y-1;
- maze.setCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y,' '); //erase the old r
- maze.setCell((int)aim.x,(int)aim.y,'r'); //set the new r
- this.setDirection(EAST);
- break;
- }else{
- //if straight is a space...
- if(maze.getCell((int)maze.getRoboCoordinate().x-1,(int)maze.getRoboCoordinate().y )==' '
- ||maze.getCell((int)maze.getRoboCoordinate().x-1,(int)maze.getRoboCoordinate().y )=='X'){
- //...move straight
- aim.x=maze.getRoboCoordinate().x-1;
- aim.y=maze.getRoboCoordinate().y;
- maze.setCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y,' '); //erase the old r
- maze.setCell((int)aim.x,(int)aim.y,'r'); //set the new r
- this.setDirection(this.getDirection());
- break;
- }else{
- //if right handside is a space...
- if(maze.getCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y+1 )==' '
- ||maze.getCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y+1 )=='X'){
- //...move left
- aim.x=maze.getRoboCoordinate().x;
- aim.y=maze.getRoboCoordinate().y+1;
- maze.setCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y,' '); //erase the old r
- maze.setCell((int)aim.x,(int)aim.y,'r'); //sert the new r
- this.setDirection(WEST);
- break;
- }else{
- //turn around...
- setDirection(SOUTH);
- break;
- }
- }
- }
- case EAST://if the left handside is a space...
- if(maze.getCell((int)maze.getRoboCoordinate().x-1,(int)maze.getRoboCoordinate().y )==' '
- ||maze.getCell((int)maze.getRoboCoordinate().x-1,(int)maze.getRoboCoordinate().y )=='X'){
- //...move right
- aim.x=maze.getRoboCoordinate().x-1;
- aim.y=maze.getRoboCoordinate().y;
- maze.setCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y,' '); //erase the old r
- maze.setCell((int)aim.x,(int)aim.y,'r'); //set the new r
- this.setDirection(SOUTH);
- break;
- }else{
- //if straight is a space...
- if(maze.getCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y+1 )==' '
- ||maze.getCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y+1 )=='X'){
- //...move straight
- aim.x=maze.getRoboCoordinate().x;
- aim.y=maze.getRoboCoordinate().y+1;
- maze.setCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y,' '); //erase the old r
- maze.setCell((int)aim.x,(int)aim.y,'r'); //set the new r
- this.setDirection(this.getDirection());
- break;
- }else{
- //if right handside is a space...
- if(maze.getCell((int)maze.getRoboCoordinate().x+1,(int)maze.getRoboCoordinate().y )==' '
- ||maze.getCell((int)maze.getRoboCoordinate().x+1,(int)maze.getRoboCoordinate().y )=='X'){
- //...move left
- aim.x=maze.getRoboCoordinate().x+1;
- aim.y=maze.getRoboCoordinate().y;
- maze.setCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y,' '); //erase the old r
- maze.setCell((int)aim.x,(int)aim.y,'r'); //sert the new r
- this.setDirection(NORTH);
- break;
- }else{
- //turn around...
- setDirection(WEST);
- break;
- }
- }
- }
- case SOUTH:
- //if the left handside is a space...
- if(maze.getCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y+1 )==' '
- ||maze.getCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y+1 )=='X'){
- //...move right
- aim.x=maze.getRoboCoordinate().x;
- aim.y=maze.getRoboCoordinate().y+1;
- maze.setCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y,' '); //erase the old r
- maze.setCell((int)aim.x,(int)aim.y,'r'); //set the new r
- this.setDirection(WEST);
- break;
- }else{
- //if straight is a space...
- if(maze.getCell((int)maze.getRoboCoordinate().x+1,(int)maze.getRoboCoordinate().y )==' '
- ||maze.getCell((int)maze.getRoboCoordinate().x+1,(int)maze.getRoboCoordinate().y )=='X'){
- //...move straight
- aim.x=maze.getRoboCoordinate().x+1;
- aim.y=maze.getRoboCoordinate().y;
- maze.setCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y,' '); //erase the old r
- maze.setCell((int)aim.x,(int)aim.y,'r'); //set the new r
- this.setDirection(this.getDirection());
- break;
- }else{
- //if right handside is a space...
- if(maze.getCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y-1 )==' '
- ||maze.getCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y-1 )=='X'){
- //...move left
- aim.x=maze.getRoboCoordinate().x;
- aim.y=maze.getRoboCoordinate().y-1;
- maze.setCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y,' '); //erase the old r
- maze.setCell((int)aim.x,(int)aim.y,'r'); //sert the new r
- this.setDirection(EAST);
- break;
- }else{
- //turn around...
- setDirection(NORTH);
- break;
- }
- }
- }
- case WEST://if the left handside is a space...
- if(maze.getCell((int)maze.getRoboCoordinate().x+1,(int)maze.getRoboCoordinate().y )==' '
- ||maze.getCell((int)maze.getRoboCoordinate().x+1,(int)maze.getRoboCoordinate().y )=='X'){
- //...move right
- aim.x=maze.getRoboCoordinate().x+1;
- aim.y=maze.getRoboCoordinate().y;
- maze.setCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y,' '); //erase the old r
- maze.setCell((int)aim.x,(int)aim.y,'r'); //set the new r
- this.setDirection(NORTH);
- break;
- }else{
- //if straight is a space...
- if(maze.getCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y-1 )==' '
- ||maze.getCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y-1 )=='X'){
- //...move straight
- aim.x=maze.getRoboCoordinate().x;
- aim.y=maze.getRoboCoordinate().y-1;
- maze.setCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y,' '); //erase the old r
- maze.setCell((int)aim.x,(int)aim.y,'r'); //set the new r
- this.setDirection(this.getDirection());
- break;
- }else{
- //if right handside is a space...
- if(maze.getCell((int)maze.getRoboCoordinate().x-1,(int)maze.getRoboCoordinate().y )==' '
- ||maze.getCell((int)maze.getRoboCoordinate().x-1,(int)maze.getRoboCoordinate().y )=='X'){
- //...move left
- aim.x=maze.getRoboCoordinate().x-1;
- aim.y=maze.getRoboCoordinate().y;
- maze.setCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y,' '); //erase the old r
- maze.setCell((int)aim.x,(int)aim.y,'r'); //sert the new r
- this.setDirection(SOUTH);
- break;
- }else{
- //turn around...
- setDirection(EAST);
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement