![]() Up |
Enemy TerritoryDevelopment/Source |
main()
BasicWindow
ConnectionData
Sensor
Effector
SimpleReflexAgent
Map
AsciiKette
FateMaker
main() - defined in BasicAgent.cc
creates a BApplication object,
a BasicWindow object ( that's the window
that is displayed on startup ),
a SimpleReflexAgent object ( that's a
looper that handles messages from the server )
and calls the Run() method of SimpleReflexAgent
and BApplication.
BasicWindow - derived from BWindow, defined in BasicWindow.cc
This class is a little extension of BWindow:
It shows some controls and sends a message to the SimpleReflexAgent
when the login button is pressed.
ConnectionData - defined in ConnectionData.cc
This class simply stores some data that is needed to send and receive
BMessages from the server.
Sensor - derived from BLooper and ConnectionData, defined in Sensor.cc
This class redefines BLooper's MessageReceived()
method. If the server sends a BMessage to
this looper, this function extracts the relevant fields of the message
and calls the appropriate virtual methods, e.g. MapSizeReceived
( int Width, int Height ) or VisibleFieldReceived
( int X, int Y, int Type ).
Effector - derived from BLooper and ConnectionData, defined in Effector.cc
This class provides the functions Login()
and Move(). A derived class needn't create
a login or move message, it simply calls these methods.
SimpleReflexAgent - derived from Sensor and Effector, defined in SimpleReflexAgent.cc
This is the most interesting class of the agent. An instance of this class is created in the main() function. When the user presses the login button of the BasicWindow, a BMessage is posted to the SimpleReflexAgent. When this happens, the SimpleReflexAgent sends the login to the server, receives the welcome and the status messages and sends move messages.
GetEnvironment() extracts the 6 fields
around an army from a BMessage,
LookForEnemies() determines, if the army
can see enemies,
StatusMessageReceived() gets a status
message and sends an appropriate move,
MessageReceived() hides Sensor::MessageReceived()
to catch the BMessage that is sent by the login button.
Map - defined in Map.cc
Map is a utility class, that provides some
useful static functions, e.g. Distance() and
IsShiftRight().
AsciiKette - defined in AsciiKette.cc
This is a collection of some simple string functions.
FateMaker - defined in FateMaker.cc
This is a random integer generator.