summaryrefslogtreecommitdiffstats
path: root/ksokoban/MoveSequence.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commitc90c389a8a8d9d8661e9772ec4144c5cf2039f23 (patch)
tree6d8391395bce9eaea4ad78958617edb20c6a7573 /ksokoban/MoveSequence.cpp
downloadtdegames-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 'ksokoban/MoveSequence.cpp')
-rw-r--r--ksokoban/MoveSequence.cpp81
1 files changed, 81 insertions, 0 deletions
diff --git a/ksokoban/MoveSequence.cpp b/ksokoban/MoveSequence.cpp
new file mode 100644
index 00000000..b5a5c824
--- /dev/null
+++ b/ksokoban/MoveSequence.cpp
@@ -0,0 +1,81 @@
+/*
+ * ksokoban - a Sokoban game for KDE
+ * Copyright (C) 1998 Anders Widell <d95-awi@nada.kth.se>
+ *
+ * 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
+ */
+
+#include "MoveSequence.h"
+#include "LevelMap.h"
+#include "Move.h"
+
+MoveSequence::MoveSequence (Move *_move, LevelMap *_map, bool _undo) {
+ assert (_move->finished_);
+
+ move_ = _move;
+ map_ = _map;
+ undo_ = _undo;
+
+ if (undo_) {
+ pos_ = move_->moveIndex_-2;
+
+ xDest_ = x_ = move_->moves_[move_->moveIndex_-1]&0x7f;
+ yDest_ = y_ = (move_->moves_[move_->moveIndex_-1]>>8)&0x7f;
+ } else {
+ pos_ = 1;
+
+ xDest_ = x_ = move_->moves_[0]&0x7f;
+ yDest_ = y_ = (move_->moves_[0]>>8)&0x7f;
+ }
+
+ newStep ();
+}
+
+bool
+MoveSequence::newStep () {
+ if (pos_>=move_->moveIndex_ || pos_<0) return false;
+
+ xDest_ = move_->moves_[pos_]&0x7f;
+ yDest_ = (move_->moves_[pos_]>>8)&0x7f;
+ if (undo_) push_ = (move_->moves_[pos_+1]&0x80)==0x80;
+ else push_ = (move_->moves_[pos_]&0x80)==0x80;
+
+ xd_ = yd_ = 0;
+ if (xDest_ < x_) xd_ = -1;
+ if (xDest_ > x_) xd_ = 1;
+ if (yDest_ < y_) yd_ = -1;
+ if (yDest_ > y_) yd_ = 1;
+
+ if (undo_) pos_--;
+ else pos_++;
+
+ return true;
+}
+
+bool
+MoveSequence::next () {
+ if (x_ == xDest_ && y_ == yDest_ && !newStep ()) return false;
+
+ x_ += xd_;
+ y_ += yd_;
+
+ if (undo_) {
+ if (push_) return map_->unpush (x_, y_);
+ else return map_->unstep (x_, y_);
+ } else {
+ if (push_) return map_->push (x_, y_);
+ else return map_->step (x_, y_);
+ }
+}