3 Replies - 5764 Views - Last Post: 11 April 2011 - 03:46 PM Rate Topic: -----

#1 feet  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 04-April 11

How to make the bug go under a rock?

Posted 11 April 2011 - 12:31 PM

One of my assignment was to create a TunnelBug (Grid World Java). This TunnelBug goes under a rock if it has a rock in front of it. If there are two rock in front of the bug then it would act like a normal bug, meaning the bug would turn.
So far I have this :

package gridworld;
import info.gridworld.actor.ActorWorld;
import info.gridworld.actor.Bug;
import info.gridworld.actor.Rock;
/**
*
* @author Mihir
*/
public class TunnelBug extends Bug {

   public void act(){

     if (canMove())
        move();
     else
       turn();
     }

}



This is what I have so far. I do know that we have use Location but don't know how to implement it.

This post has been edited by macosxnerd101: 11 April 2011 - 01:07 PM
Reason for edit:: Added code tags and moved to GridWorld


Is This A Good Question/Topic? 0
  • +

Replies To: How to make the bug go under a rock?

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10196
  • View blog
  • Posts: 37,655
  • Joined: 27-December 08

Re: How to make the bug go under a rock?

Posted 11 April 2011 - 01:09 PM

Moved to GridWorld.

Define going "under" a Rock. Do you mean going to the space next to the Rock? If so, just get occupied locations. If the Bug and Rock are on the same row, just add/subtract 2 to the x coordinate of the bug appropriately. If the Bug and Rock are on the same column, add/subtract two appropriately, again based on direction.
Was This Post Helpful? 0
  • +
  • -

#3 feet  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 04-April 11

Re: How to make the bug go under a rock?

Posted 11 April 2011 - 03:44 PM

Yes, the bug moves to the next available location. I used Location loc1 = getLocation().getAdjacentLocation(90);
I even try to use moveTo() method, but it doesn't work.....
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10196
  • View blog
  • Posts: 37,655
  • Joined: 27-December 08

Re: How to make the bug go under a rock?

Posted 11 April 2011 - 03:46 PM

Post your good faith attempt.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1