Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

game.h

00001 /*
00002  *   EasySok --- A(nother) sokoban game for KDE.
00003  *
00004  *   Copyright (C) 2001 by Ralf Schmelter (ralfs@pc2a.chemie.uni-dortmund.de).
00005  *
00006  *   This program is free software; you can redistribute it and/or modify
00007  *   it under the terms of the GNU General Public License version 2 as
00008  *   published by the Free Software Foundation.
00009  *
00010  *   This program is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU General Public License
00016  *   along with this program; if not, write to the Free Software
00017  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018  */
00019 
00020 
00021 #ifndef EASYSOK_GAME_INC_GUARD_H
00022 #define EASYSOK_GAME_INC_GUARD_H
00023 
00024 
00025 #include <deque>
00026 #include <vector>
00027 
00028 #include <qobject.h>
00029 #include <qpoint.h>
00030 
00031 #include "map.h"
00032 #include "map_widget.h"
00033 #include "move.h"
00034 #include "movements.h"
00035 
00036 class AtomicMove;
00037 class QTimer;
00038 
00039 
00040 
00041 
00049 class Game : public QObject
00050 {
00051     Q_OBJECT
00052 
00053 public:
00054 
00062     Game(Map * map, Movements const & moves);
00063 
00064 
00072     void setMapAndMoves(Map * map, Movements const & moves);
00073 
00074 
00081     bool retroMode() const;
00082 
00083 
00094     bool setRetroMode(bool retro_mode);
00095 
00096 
00104     bool tryMove(AtomicMove const & move);
00105 
00106 
00114     bool tryMove(Move const & move);
00115 
00116 
00124     bool tryPullMove(AtomicMove const & move);
00125 
00126 
00136     bool tryFarMove(AtomicMove const & move);
00137 
00138 
00145     void moveVirtualKeeper(AtomicMove const & move);
00146 
00147 
00152     bool canUndo() const;
00153 
00154 
00159     bool canRedo() const;
00160 
00161 
00166     int numberOfPushes() const;
00167 
00168 
00173     int numberOfMoves() const;
00174 
00175 
00180     int numberOfEmptyGoals() const;
00181 
00182 
00189     Movements const & moves() const;
00190 
00191 
00200     void setMoves(Movements const & moves);
00201 
00202 
00207     bool isSolved() const;
00208 
00209 
00214     bool showArrows() const;
00215 
00216 
00221     bool honorDeadlocks() const;
00222 
00223 
00233     int animation() const;
00234 
00235 
00240     AtomicMove::AtomicMoveType keeperDirection() const;
00241 
00242 
00247     void configChanged();
00248 
00249 
00256     void setShowArrows(bool show);
00257 
00258 
00265     void setHonorDeadlock(bool honor_deadlocks);
00266 
00267 
00274     void setAnimation(int animation);
00275 
00276 
00283     void emptyMoveQueue();
00284 
00285 
00294     bool tryMoveKeeper(QPoint const & from, QPoint const & to);
00295 
00296 
00305     bool tryMoveGem(QPoint const & from, QPoint const & to);
00306 
00307 
00312     void jumpToStart();
00313 
00314 
00319     void jumpToEnd();
00320 
00321 
00328     bool tryUndo();
00329 
00330 
00337     bool tryRedo();
00338 
00339 
00346     void playMoves(bool from_start);
00347 
00348 
00353     void forceUpdate();
00354 
00355 
00362     void preventUpdate(bool prevent_update);
00363 
00364 
00365 signals:
00366 
00371     void wasSolved();
00372 
00373 
00378     void wasUnsolved();
00379 
00380 
00386     void wasSolvedByHand();
00387 
00388 
00393     void mapChanged();
00394 
00395 
00404     void arrowsChanged(std::vector<Move> const &arrows);
00405 
00406 
00415     void keeperDirectionChanged(AtomicMove::AtomicMoveType direction);
00416 
00417 
00424     void virtualKeeperChanged(const QPoint & position);
00425 
00426 
00427 private slots:
00428 
00433     void processMoveQueue();
00434 
00435 
00436 private:
00437 
00442     void removeVirtualKeeper();
00443 
00444 
00449     void undo();
00450 
00451 
00456     void redo();
00457 
00458 
00469     void doMove(Move const & move);
00470 
00471 
00481     void doAtomicMoves(Movements const & moves);
00482 
00483 
00494     void doMoves(Movements const & moves);
00495 
00496 
00507     void doUndoMove(Move const & move);
00508 
00509 
00516     void addToMoveQueue(Move const & move);
00517 
00518 
00523     void processMove();
00524 
00525 
00530     void calcArrows();
00531 
00532 
00540     Movements simplifyMove(Move const & move, Map const * map) const;
00541 
00542 
00550     Movements simplifyUndoMove(Move const & move, Map const * map) const;
00551 
00552 
00561     bool isDeadlockField(QPoint const & position) const;
00562 
00563 
00568     bool isDeadlockField(int index) const;
00569 
00570 
00577     void makeEndMap();
00578 
00579 
00584     Map * m_map;
00585 
00586 
00591     int m_width;
00592 
00593 
00598     int m_height;
00599 
00600 
00605     int m_size;
00606 
00607 
00612     int m_xy_offsets[4];
00613 
00614 
00619     Movements m_moves;
00620 
00621 
00626     std::deque<Move> m_move_queue;
00627 
00628 
00633     bool m_undo_moves;
00634 
00635 
00640     bool m_handmade_moves;
00641 
00642 
00647     bool m_no_update;
00648 
00649 
00654     bool m_is_solved;
00655 
00656 
00661     int m_number_of_moves;
00662 
00663 
00668     int m_number_of_pushes;
00669 
00670 
00675     bool m_show_arrows;
00676 
00677 
00682     bool m_honor_deadlocks;
00683 
00684 
00689     AtomicMove::AtomicMoveType m_keeper_direction;
00690 
00691 
00696     QPoint m_virtual_keeper;
00697 
00698 
00703     bool m_wrap_virtual_keeper;
00704 
00705 
00710     QTimer * m_timer;
00711 
00712 
00717     int m_animation;
00718 
00719 
00724     bool m_retro_mode;
00725 
00726 
00731     Map m_backup_map;
00732 
00733 
00738     Movements m_backup_moves;
00739 
00740 
00745     bool m_prevent_update;
00746 
00747 
00752     bool m_in_play;
00753 
00754 
00759     static int s_fast_time;
00760 
00761 
00766     static int s_normal_time;
00767 
00768 
00773     static int s_slow_time;
00774 };
00775 
00776 
00777 #endif

Generated at Sun Jan 6 18:49:09 2002 for EasySok by doxygen1.2.9.1 written by Dimitri van Heesch, © 1997-2001