From c90c389a8a8d9d8661e9772ec4144c5cf2039f23 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdegames@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kjumpingcube/cubeboxbase.h | 246 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 246 insertions(+) create mode 100644 kjumpingcube/cubeboxbase.h (limited to 'kjumpingcube/cubeboxbase.h') diff --git a/kjumpingcube/cubeboxbase.h b/kjumpingcube/cubeboxbase.h new file mode 100644 index 00000000..63bc0529 --- /dev/null +++ b/kjumpingcube/cubeboxbase.h @@ -0,0 +1,246 @@ +/* **************************************************************************** + This file is part of the game 'KJumpingCube' + + Copyright (C) 1998-2000 by Matthias Kiefer + + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +**************************************************************************** */ +#ifndef CUBEBOXBASE_H +#define CUBEBOXBASE_H + +#ifdef DEBUG +#include +#endif + +template +class CubeBoxBase +{ +public: + enum Player{One=1,Two=2}; + + CubeBoxBase(const int dim=1); + virtual ~CubeBoxBase(); + + T** operator[](const int index); + /** + * sets number of Cubes in a row/column to 'size'. + */ + virtual void setDim(int dim); + + /** + * returns number of Cubes in a row/column + */ + inline int dim() const { return _dim; } + + inline Player player() const { return currentPlayer; } + +protected: + virtual void deleteCubes(); + virtual void initCubes(); + + /** increases the neighbours of cube at ['row','column'] */ + //void increaseNeighbours(int forWhom,int row,int column); + + T*** cubes; + Player currentPlayer; + +private: + int _dim; + +}; + +template +CubeBoxBase::CubeBoxBase(const int dim) +{ +#ifdef DEBUG + assert(dim>0); +#endif + + _dim=dim; + currentPlayer=One; +} + +template +CubeBoxBase::~CubeBoxBase() +{ + if(cubes) + deleteCubes(); +} + +template +T** CubeBoxBase::operator[](const int index) +{ +#ifdef DEBUG + assert(index >= 0); +#endif + + return cubes[index]; +} + +template +void CubeBoxBase::setDim(int d) +{ + if(d != _dim) + { + deleteCubes(); + + _dim=d; + + initCubes(); + } +} + + +template +void CubeBoxBase::initCubes() +{ + const int s=dim(); + + int i,j; + // create new cubes + cubes = new T**[s]; + for(i=0;isetMax(2); + cubes[0][max]->setMax(2); + cubes[max][0]->setMax(2); + cubes[max][max]->setMax(2); + + for(i=0;i<=max;i++) + { + cubes[i][0]->setMax(3); + cubes[i][max]->setMax(3); + cubes[0][i]->setMax(3); + cubes[max][i]->setMax(3); + } + + for(i=1;isetMax(4); + } +} + +template +void CubeBoxBase::deleteCubes() +{ + int i,j; + for(i=0;i +void CubeBoxBase::increaseNeighbours(int forWhom,int row,int column) +{ + int _player = (T::Owner)(forWhom); + + if(row==0) + { + if(column==0) // linke obere Ecke + { + cubes[0][1]->increase(_player); + cubes[1][0]->increase(_player); + return; + } + else if(column==dim()-1) // rechte obere Ecke + { + cubes[0][dim()-2]->increase(_player); + cubes[1][dim()-1]->increase(_player); + return; + } + else // oberer Rand + { + cubes[0][column-1]->increase(_player); + cubes[0][column+1]->increase(_player); + cubes[1][column]->increase(_player); + return; + } + } + else if(row==dim()-1) + { + if(column==0) // linke untere Ecke + { + cubes[dim()-2][0]->increase(_player); + cubes[dim()-1][1]->increase(_player); + return; + } + + else if(column==dim()-1) // rechte untere Ecke + { + cubes[dim()-2][dim()-1]->increase(_player); + cubes[dim()-1][dim()-2]->increase(_player); + return; + } + else // unterer Rand + { + cubes[dim()-1][column-1]->increase(_player); + cubes[dim()-1][column+1]->increase(_player); + cubes[dim()-2][column]->increase(_player); + return; + } + } + else if(column==0) // linker Rand + { + cubes[row-1][0]->increase(_player); + cubes[row+1][0]->increase(_player); + cubes[row][1]->increase(_player); + return; + } + else if(column==dim()-1) // rechter Rand + { + cubes[row-1][dim()-1]->increase(_player); + cubes[row+1][dim()-1]->increase(_player); + cubes[row][dim()-2]->increase(_player); + return; + } + else + { + cubes[row][column-1]->increase(_player); + cubes[row][column+1]->increase(_player); + cubes[row-1][column]->increase(_player); + cubes[row+1][column]->increase(_player); + return; + } + + +} +*/ + +#endif // CUBEBOXBASE_H + -- cgit v1.2.1