FoodCell Class Reference

#include <FoodCell.h>

Inheritance diagram for FoodCell:

Inheritance graph
[legend]
Collaboration diagram for FoodCell:

Collaboration graph
[legend]

Public Member Functions

virtual ~FoodCell ()
 Empty Destructor.
unsigned int getMax ()
 Get the value of _max.
unsigned int getInc ()
 Get the value of _inc.
virtual unsigned int getFood ()
 Get the amount of food the Cell contains.
virtual unsigned int addFood (unsigned int inc)
 Add some food on the Cell.
virtual unsigned int subFood (unsigned int inc)
 Substract some food on the Cell.
virtual CellmakeActions ()
 Make the actions needed by the Cell for one iteration.

Protected Member Functions

 FoodCell (unsigned int max, unsigned int inc, unsigned int value)
 Constructor of FoodCell.

Protected Attributes

unsigned int _max
unsigned int _inc
unsigned int _value

Detailed Description

< A Cell that contains food

Definition at line 33 of file FoodCell.h.


Constructor & Destructor Documentation

FoodCell::FoodCell ( unsigned int  max,
unsigned int  inc,
unsigned int  value 
) [protected]

Constructor of FoodCell.

Parameters:
max the max value of food the Cell can contain
inc the regeneration rate of the food
value the amount of the food currently on the Cell

Definition at line 27 of file FoodCell.cpp.

00027                                                                          :
00028     ReachableCell(), _max(max), _inc(inc), _value(value) {
00029 
00030 }


Member Function Documentation

unsigned int FoodCell::getMax (  ) 

Get the value of _max.

Returns:
the value of _max

Definition at line 36 of file FoodCell.cpp.

References _max.

00036                               {
00037   return _max;
00038 }

unsigned int FoodCell::getInc (  ) 

Get the value of _inc.

Returns:
the value of _inc

Definition at line 40 of file FoodCell.cpp.

References _inc.

00040                               {
00041   return _inc;
00042 }

unsigned int FoodCell::getFood (  )  [virtual]

Get the amount of food the Cell contains.

Returns:
the value of _value

Reimplemented from Cell.

Definition at line 44 of file FoodCell.cpp.

References _value.

Referenced by GodsGiftFood::makeActions(), and CorpseFood::makeActions().

00044                                {
00045   return _value;
00046 }

Here is the caller graph for this function:

unsigned int FoodCell::addFood ( unsigned int  inc  )  [virtual]

Add some food on the Cell.

Parameters:
inc the food to add on the Cell
Returns:
the total amount of food actually added

Reimplemented from Cell.

Definition at line 48 of file FoodCell.cpp.

References _max, and _value.

00048                                                {
00049   unsigned int res = inc;
00050 
00051   if(_value + inc > _max) {
00052     res = _max - _value;
00053     _value = _max;
00054   } else {
00055     _value = _value + inc;
00056   }
00057 
00058   return res;
00059 }

unsigned int FoodCell::subFood ( unsigned int  inc  )  [virtual]

Substract some food on the Cell.

Parameters:
inc the food to remove of the Cell
Returns:
the total amount of food actually removed

Reimplemented from Cell.

Definition at line 61 of file FoodCell.cpp.

References _value.

00061                                                {
00062   int res = inc;
00063 
00064   if((signed int) (_value - inc) < 0) {
00065     res = _value;
00066     _value = 0;
00067   } else {
00068     _value = _value - inc;
00069   }
00070 
00071   return res;
00072 }

Cell * FoodCell::makeActions (  )  [virtual]

Make the actions needed by the Cell for one iteration.

Returns:
a pointer to the new Cell which should replace this one

Reimplemented from ReachableCell.

Reimplemented in CorpseFood, and GodsGiftFood.

Definition at line 74 of file FoodCell.cpp.

References _inc, _max, _value, and ReachableCell::makeActions().

Referenced by GodsGiftFood::makeActions(), and CorpseFood::makeActions().

00074                             {
00075   ReachableCell::makeActions();
00076 
00077   _value += _inc;
00078   _value = (_value > _max ? _max : _value);
00079 
00080   return this;
00081 }

Here is the call graph for this function:

Here is the caller graph for this function:


Field Documentation

unsigned int FoodCell::_max [protected]

the max value of food the Cell can contain

Definition at line 38 of file FoodCell.h.

Referenced by addFood(), getMax(), and makeActions().

unsigned int FoodCell::_inc [protected]

the regeneration rate of the food

Definition at line 41 of file FoodCell.h.

Referenced by getInc(), and makeActions().

unsigned int FoodCell::_value [protected]

the amount of the food currently on the Cell

Definition at line 44 of file FoodCell.h.

Referenced by addFood(), getFood(), makeActions(), and subFood().


The documentation for this class was generated from the following files:
Generated on Sat Feb 2 22:23:14 2008 for Teapot Colony Wars by  doxygen 1.5.4