zinger.nibbles.drivers
Class SnakeDriverAdapter

java.lang.Object
  |
  +--zinger.nibbles.drivers.SnakeDriverAdapter
All Implemented Interfaces:
SnakeDriver
Direct Known Subclasses:
KeyboardSnakeDriver, SynchronousSnakeDriverAdapter

public class SnakeDriverAdapter
extends java.lang.Object
implements SnakeDriver

A simple adapter class for SnakeDriver interface. Direction can be changed asynchrously by calling enqueue(int) method. To receive notifications override the where method and return its result at the end. Because of this behavior, extensions of this class should not be assigned to more than one instance of Snake.

See Also:
enqueue(int), where(zinger.nibbles.Snake), Snake

Field Summary
private  int direction
           
private  int[] directionQueue
           
private  int offset
           
private  int start
           
 
Constructor Summary
SnakeDriverAdapter()
           
 
Method Summary
protected  void clear()
          Clears the queue.
protected  void enqueue(int direction)
           
 int where(Snake snake)
          This method is called on every turn as initiated by Field.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

direction

private int direction

directionQueue

private int[] directionQueue

start

private int start

offset

private int offset
Constructor Detail

SnakeDriverAdapter

public SnakeDriverAdapter()
Method Detail

where

public int where(Snake snake)
Description copied from interface: SnakeDriver
This method is called on every turn as initiated by Field.
Specified by:
where in interface SnakeDriver
Following copied from interface: zinger.nibbles.SnakeDriver
See Also:
Field.timeCall(zinger.nibbles.Timer)

enqueue

protected void enqueue(int direction)

clear

protected void clear()
Clears the queue. Because of the circular array implementation of the queue, this operation is extremely cheap.