so I am creating a program that has a human bicycle car and truck and they all run on a street but they can collide. so I am confused on how I should write it, the car should be able to collide with the other three objects. I have more code but it seems that it will be to confusing to put all of it up but if it is needed to solve my problem i will post it.
thanks in advanced
/*
* TCSS 305
* assignment 2 easystreet
*/
import java.util.Map;
/**
* This program creates a subclass of the vehicle object.
*
* @author Goyofoyo
* @version 1
*/
public class Car extends Vehicle
{
/**
* the death time.
*/
private static final int DEATH_TIME = 0;
/**
*
* @param the_x the x-coordinate.
* @param the_y the y-coordinate.
* @param the_terrain the terrain.
* @param the_dir the direction.
*/
public Car(final int the_x, final int the_y,
final Direction the_dir, final Terrain the_terrain)
{
super(the_x, the_y, the_dir, the_terrain, DEATH_TIME);
}
/**
* @return the direction of the car.
* @param the_neighbors the_neighbors provides the direction and the terrain.
* @param the_light the light terrain.
*/
public Direction chooseDirection(final Map<Direction, Terrain> the_neighbors,
final Light the_light)
{
Direction direction = Direction.random();
if (moveTo(the_neighbors, the_light))
{
while (direction == getDirection().reverse() ||
(the_neighbors.get(direction) != Terrain.STREET &&
the_neighbors.get(direction) != Terrain.LIGHT))
{
direction = Direction.random();
}
}
else
{
setDirection(direction.reverse());
}
return direction;
}
/**
*
* @param the_neighbors the_neighbors provides the direction and the terrain.
* @param the_light the light terrain.
* @return the terrain.
*/
public boolean moveTo(final Map<Direction, Terrain> the_neighbors,
final Light the_light)
{
return the_neighbors.get(getDirection()) == Terrain.STREET ||
the_neighbors.get(getDirection()) == Terrain.LIGHT ||
the_neighbors.get(getDirection().left()) == Terrain.STREET ||
the_neighbors.get(getDirection().left()) == Terrain.LIGHT ||
the_neighbors.get(getDirection().right()) == Terrain.STREET ||
the_neighbors.get(getDirection().right()) == Terrain.LIGHT;
}
/**
* @param the_terrain the type of terrain the truck can move in.
* @param the_light the lights it can go threw
* @return Where the truck can move to, street and threw lights.
*/
public boolean canPass(final Terrain the_terrain, final Light the_light)
{
boolean can_pass = false;
if (the_terrain == Terrain.STREET)
{
can_pass = true;
}
else if (the_terrain == Terrain.LIGHT)
{
if (the_light == Light.GREEN)
{
can_pass = true;
}
else if (the_light == Light.YELLOW)
{
can_pass = true;
}
}
return can_pass;
}
public void collide(final Movable the_other)
{
}
}