src/FoodCell.cpp

Go to the documentation of this file.
00001 
00008 /*
00009 This file is part of Teapot Colony Wars.
00010 
00011 Teapot Colony Wars is free software: you can redistribute it and/or modify
00012 it under the terms of the GNU General Public License as published by
00013 the Free Software Foundation, either version 2 of the License, or
00014 (at your option) any later version.
00015 
00016 Teapot Colony Wars is distributed in the hope that it will be useful,
00017 but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 GNU General Public License for more details.
00020 
00021 You should have received a copy of the GNU General Public License
00022 along with Teapot Colony Wars.  If not, see <http://www.gnu.org/licenses/>.
00023 */
00024 
00025 #include "FoodCell.h"
00026 
00027 FoodCell::FoodCell(unsigned int max, unsigned int inc, unsigned int value) :
00028     ReachableCell(), _max(max), _inc(inc), _value(value) {
00029 
00030 }
00031 
00032 FoodCell::~FoodCell() {
00033 
00034 }
00035 
00036 unsigned int FoodCell::getMax() {
00037   return _max;
00038 }
00039 
00040 unsigned int FoodCell::getInc() {
00041   return _inc;
00042 }
00043 
00044 unsigned int FoodCell::getFood() {
00045   return _value;
00046 }
00047 
00048 unsigned int FoodCell::addFood(unsigned int inc) {
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 }
00060 
00061 unsigned int FoodCell::subFood(unsigned int inc) {
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 }
00073 
00074 Cell* FoodCell::makeActions() {
00075   ReachableCell::makeActions();
00076 
00077   _value += _inc;
00078   _value = (_value > _max ? _max : _value);
00079 
00080   return this;
00081 }

Generated on Sat Feb 2 22:22:54 2008 for Teapot Colony Wars by  doxygen 1.5.4