nanomunchers.ui
Class NanoSimulation

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Canvas
          extended bynanomunchers.ui.NanoSimulation
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class NanoSimulation
extends java.awt.Canvas

Arguably the largest piece of the Nanomunchers game is the simulation that shows the state of the game at each frame. This Simulation class merely plays a set of frames. The Simulator class is the one that builds the frames themselves.

Author:
David Kaplin
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.awt.Canvas
java.awt.Canvas.AccessibleAWTCanvas
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
NanoSimulation(heurgame.ui.PlayerColors pc, heurgame.event.PlayerBroadcaster playerSpeaker)
          Sets up a new simulation
 
Method Summary
 boolean decreaseSpeed()
          Slows down the simulation either by adding frames (if any were skipped) or by lengthening the delay between frames
 boolean increaseSpeed()
          Either shortens the delay or skips frames.
static void main(java.lang.String[] args)
          Debugging method
 void nextFrame()
          Finishes the current frame
 void nextMove(java.lang.Integer nanoId, Node place, int munched, boolean alive, boolean naturaldeath)
          Constructs a piece of a frame
 void paint(java.awt.Graphics g)
          Only paints if the simulation is not running.
 void play()
          Reads through the frames and plays them at whatever the current speed is.
 java.lang.Integer register(heurgame.PlayerToken owner, NanoBot nb)
           
 void setFrameListener(FrameListener frame)
           
 void setSimulationSpeed(double s)
          Changes the speed of the simulation without skipping frames.
 void setup(Graph graph)
          Initializes the simulation
 void update(java.awt.Graphics g)
          If the graph is not null draws the simulation.
 
Methods inherited from class java.awt.Canvas
addNotify, createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NanoSimulation

public NanoSimulation(heurgame.ui.PlayerColors pc,
                      heurgame.event.PlayerBroadcaster playerSpeaker)
Sets up a new simulation

Parameters:
pc - Colors for each player.
playerSpeaker - to notify any listeners of score changes.
Method Detail

setFrameListener

public void setFrameListener(FrameListener frame)
Parameters:
frame - to be notified when frames are either being added or played.

setup

public void setup(Graph graph)
Initializes the simulation

Parameters:
graph - to be displayed

register

public java.lang.Integer register(heurgame.PlayerToken owner,
                                  NanoBot nb)

nextMove

public void nextMove(java.lang.Integer nanoId,
                     Node place,
                     int munched,
                     boolean alive,
                     boolean naturaldeath)
Constructs a piece of a frame

Parameters:
nanoId - object ref of a registered bot
place - where the bot is
munched - how many nodes has it munched
alive - whether the bot is alive
naturaldeath - whether or not the bot exhausted its food supply

nextFrame

public void nextFrame()
Finishes the current frame


setSimulationSpeed

public void setSimulationSpeed(double s)
Changes the speed of the simulation without skipping frames. If frames were skipped at a previous setting, there will not be any frames skipped at this ratio.

Parameters:
s - Larger numbers yeild a SLOWER speed.

decreaseSpeed

public boolean decreaseSpeed()
Slows down the simulation either by adding frames (if any were skipped) or by lengthening the delay between frames

Returns:
true if the speed or frames were changed

increaseSpeed

public boolean increaseSpeed()
Either shortens the delay or skips frames.

Returns:
true if the speed could be increased

play

public void play()
Reads through the frames and plays them at whatever the current speed is. Speed may be changed during playback. With the aid of the PlayerBroadcaster the play method replays the scores as they occured in the simulation.


paint

public void paint(java.awt.Graphics g)
Only paints if the simulation is not running.

See Also:
Component.paint(java.awt.Graphics)

update

public void update(java.awt.Graphics g)
If the graph is not null draws the simulation.

See Also:
Component.update(java.awt.Graphics)

main

public static void main(java.lang.String[] args)
Debugging method

Parameters:
args -