Class Truck

java.lang.Object
  |
  +--Vehicle
        |
        +--Truck

public class Truck
extends Vehicle

A Truck is a kind of Vehicle that occupies two adjacent (horizontal or vertical) traffic grid locations.

Version:
1.0
Author:
David Matuszek

Field Summary
private  int extraColumn
           
private  int extraRow
           
private static java.util.Random random
           
 
Fields inherited from class Vehicle
currentColumn, currentRow, destinations, goalColumn, goalRow, town
 
Constructor Summary
(package private) Truck(Vehicle[][] town, java.lang.String[][] destinations, int row, int column)
          Constructs a Truck.
 
Method Summary
private  boolean canPlace(int row, int column)
           
(package private)  void disappear()
          Removes this Vehicle from the traffic grid.
(package private)  boolean onDestination()
          Tests if this Truck is at its destination.
(package private)  boolean tryMove(int rowChange, int columnChange)
          Tries to move this Truck one step closer to its destination, and returns true if successful.
 
Methods inherited from class Vehicle
alreadyTaken, manhattanDistance, manhattanDistance, move, sign, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

extraRow

private int extraRow

extraColumn

private int extraColumn

random

private static java.util.Random random
Constructor Detail

Truck

Truck(Vehicle[][] town,
      java.lang.String[][] destinations,
      int row,
      int column)
Constructs a Truck.

Parameters:
town - The traffic grid on which to place this Truck.
destinations - The array in which to indicate this Truck's destination.
row - The row at which to place this Truck.
column - The column at which to place this Truck.
Method Detail

canPlace

private boolean canPlace(int row,
                         int column)

tryMove

boolean tryMove(int rowChange,
                int columnChange)
Tries to move this Truck one step closer to its destination, and returns true if successful. Note that this method has the side effect of actually moving this Truck, if the move is possible.

Specified by:
tryMove in class Vehicle
Parameters:
rowChange - The amount to add to this Truck's row.
columnChange - The amount to add to this Truck's column.
Returns:
True if this Truck has been moved.

onDestination

boolean onDestination()
Tests if this Truck is at its destination.

Specified by:
onDestination in class Vehicle
Returns:
True if this Truck is at its destination.

disappear

void disappear()
Removes this Vehicle from the traffic grid.

Overrides:
disappear in class Vehicle