diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | c90c389a8a8d9d8661e9772ec4144c5cf2039f23 (patch) | |
tree | 6d8391395bce9eaea4ad78958617edb20c6a7573 /kblackbox/util.cpp | |
download | tdegames-c90c389a8a8d9d8661e9772ec4144c5cf2039f23.tar.gz tdegames-c90c389a8a8d9d8661e9772ec4144c5cf2039f23.zip |
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
Diffstat (limited to 'kblackbox/util.cpp')
-rw-r--r-- | kblackbox/util.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/kblackbox/util.cpp b/kblackbox/util.cpp new file mode 100644 index 00000000..7282fe41 --- /dev/null +++ b/kblackbox/util.cpp @@ -0,0 +1,68 @@ +// +// +// KBlackBox +// +// A simple game inspired by an emacs module +// +// File: util.cpp +// +// The implementation of the RectOnArray class +// + +#include "util.h" + +RectOnArray::RectOnArray( int newWidth, int newHeight ) +{ + w = newWidth; + h = newHeight; + array = new ArrayType[w*h]; +} + +RectOnArray::~RectOnArray() +{ + delete[] array; +} + +/* + Size info... +*/ + +int RectOnArray::width() { return w; } +int RectOnArray::height() { return h; } + +/* + Utility function for mapping from 2D table to 1D array +*/ + +int RectOnArray::indexOf( int col, int row ) const +{ + return (row * w) + col; +} + +/* + Return content of cell +*/ + +ArrayType RectOnArray::get( int col, int row ) +{ + return array[indexOf( col, row )]; +} + +/* + Set content of cell +*/ + +void RectOnArray::set( int col, int row, ArrayType type ) +{ + array[indexOf( col, row )] = type; +} + +/* + Fill all cells witj type +*/ + +void RectOnArray::fill( ArrayType type ) +{ + int i; + for (i = 0; i < w*h; i++) array[i] = type; +} |