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

Game Class Reference

This class represents a game for a map. More...

#include <game.h>

Inheritance diagram for Game::

List of all members.

Signals

void wasSolved ()
void wasUnsolved ()
void wasSolvedByHand ()
void mapChanged ()
void arrowsChanged (std::vector< Move > const &arrows)
void keeperDirectionChanged (AtomicMove::AtomicMoveType direction)
void virtualKeeperChanged (const QPoint &position)

Public Methods

 Game (Map *map, Movements const &moves)
void setMapAndMoves (Map *map, Movements const &moves)
bool retroMode () const
bool setRetroMode (bool retro_mode)
bool tryMove (AtomicMove const &move)
bool tryMove (Move const &move)
bool tryPullMove (AtomicMove const &move)
bool tryFarMove (AtomicMove const &move)
void moveVirtualKeeper (AtomicMove const &move)
bool canUndo () const
bool canRedo () const
int numberOfPushes () const
int numberOfMoves () const
int numberOfEmptyGoals () const
Movements const & moves () const
void setMoves (Movements const &moves)
bool isSolved () const
bool showArrows () const
bool honorDeadlocks () const
int animation () const
AtomicMove::AtomicMoveType keeperDirection () const
void configChanged ()
void setShowArrows (bool show)
void setHonorDeadlock (bool honor_deadlocks)
void setAnimation (int animation)
void emptyMoveQueue ()
bool tryMoveKeeper (QPoint const &from, QPoint const &to)
bool tryMoveGem (QPoint const &from, QPoint const &to)
void jumpToStart ()
void jumpToEnd ()
bool tryUndo ()
bool tryRedo ()
void playMoves (bool from_start)
void forceUpdate ()
void preventUpdate (bool prevent_update)

Private Slots

void processMoveQueue ()

Private Methods

void removeVirtualKeeper ()
void undo ()
void redo ()
void doMove (Move const &move)
void doAtomicMoves (Movements const &moves)
void doMoves (Movements const &moves)
void doUndoMove (Move const &move)
void addToMoveQueue (Move const &move)
void processMove ()
void calcArrows ()
Movements simplifyMove (Move const &move, Map const *map) const
Movements simplifyUndoMove (Move const &move, Map const *map) const
bool isDeadlockField (QPoint const &position) const
bool isDeadlockField (int index) const
void makeEndMap ()

Private Attributes

Mapm_map
int m_width
int m_height
int m_size
int m_xy_offsets [4]
Movements m_moves
std::deque< Movem_move_queue
bool m_undo_moves
bool m_handmade_moves
bool m_no_update
bool m_is_solved
int m_number_of_moves
int m_number_of_pushes
bool m_show_arrows
bool m_honor_deadlocks
AtomicMove::AtomicMoveType m_keeper_direction
QPoint m_virtual_keeper
bool m_wrap_virtual_keeper
QTimer * m_timer
int m_animation
bool m_retro_mode
Map m_backup_map
Movements m_backup_moves
bool m_prevent_update
bool m_in_play

Static Private Attributes

int s_fast_time
int s_normal_time
int s_slow_time

Detailed Description

This class represents a game for a map.

Author:
Ralf Schmelter (ralfs@pc2a.chemie.uni-dortmund.de).
Version:
0.1


Constructor & Destructor Documentation

Game::Game Map * map,
Movements const & moves
 

Constructs the game.

Parameters:
map   The start map.
moves   The initial moves.


Member Function Documentation

void Game::addToMoveQueue Move const & move [private]
 

Adds an atomic move to the move queue.

Parameters:
move   The move to add.

int Game::animation const
 

Returns the current animation speed.

0: no animation 1: fast animation 2: normal animation 3: slow animation

void Game::arrowsChanged std::vector< Move > const & arrows [signal]
 

This is emitted, if the arrows we changed.

It's guaranteed, that a mapChanged() signal will be emitted later.

Parameters:
arrows   The new arrows.

void Game::calcArrows [private]
 

Calculates the possible moves and shows the arrows.

bool Game::canRedo const
 

Returns true, if we can redo a move.

bool Game::canUndo const
 

Returns true, if we can undo a move.

void Game::configChanged
 

Call this, when the config file has changed.

void Game::doAtomicMoves Movements const & moves [private]
 

Puts the given atomic moves in the move queue.

Note that the move queue will <e>not</e> be emptied and the moves are <e>not</e> stored in m_moves.

Parameters:
moves   The atomic moves to put in the queue.

void Game::doMove Move const & move [private]
 

Puts the given move in the move queue.

Note that the move queue will be emptied before.

The move will be added to m_moves.

Parameters:
move   The move to put (splitted into atomic moves) in the move queue.

void Game::doMoves Movements const & moves [private]
 

Puts the given moves in the move queue.

Note that the move queue will be emptied before.

The move will be added to m_moves.

Parameters:
moves   The moves to put (splitted into atomic moves) in the move queue.

void Game::doUndoMove Move const & move [private]
 

Puts the given undo move in the move queue.

Note that the move queue will be emptied before.

m_moves will not be changed.

Parameters:
move   The undo move to put (splitted into atomic moves) in the move queue.

void Game::emptyMoveQueue
 

Empties the move queue.

After this call, the map and the moves are corresponding.

void Game::forceUpdate
 

Updates the map.

bool Game::honorDeadlocks const
 

Returns true, if we honor deadlock fields.

bool Game::isDeadlockField int index const [private]
 

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

bool Game::isDeadlockField QPoint const & position const [private]
 

Returns true, if the given field is a deadlock field.

If m_honor_deadlocks is false, this alsways returns false.

Parameters:
position   The position of the field to test.

bool Game::isSolved const
 

Returns true, if the map is currently solved.

void Game::jumpToEnd
 

Jumps to the end position of the moves made.

void Game::jumpToStart
 

Jumps to the start position.

AtomicMove::AtomicMoveType Game::keeperDirection const
 

Returns the current direction of the keeper.

void Game::keeperDirectionChanged AtomicMove::AtomicMoveType direction [signal]
 

This is emitted, if the keeper direction was changed.

It's guaranteed, that a mapChanged() signal will be emitted later.

Parameters:
direction   The new keeper direction.

void Game::makeEndMap [private]
 

Moves all gems to the goals and sets the keeper to a reasonable position.

Note that the keeper should not be located on a goal field.

void Game::mapChanged [signal]
 

This is emitted, if the map was changed.

void Game::moveVirtualKeeper AtomicMove const & move
 

Moves the virtual keeper.

Parameters:
move   The atomic move to to withe the virtual keeper.

Movements const& Game::moves const
 

Returns the moves.

Note that unless you call emptyMoveQueue(), the map may lay behind the moves.

int Game::numberOfEmptyGoals const
 

Returns the number of empty goals (goals without a gem).

int Game::numberOfMoves const
 

Returns the number of moves currently made.

int Game::numberOfPushes const
 

Returns the number of pushes currently made.

void Game::playMoves bool from_start
 

Plays the moves.

Parameters:
from_start   If true, we als jump to the start first.

void Game::preventUpdate bool prevent_update
 

Enables or disables all updates.

Parameters:
prevent_update   If true, all updates to the map widget are prevented.

void Game::processMove [private]
 

Processes a single move in the move queue.

void Game::processMoveQueue [private, slot]
 

Processes them move queue.

void Game::redo [private]
 

Redoes a move.

void Game::removeVirtualKeeper [private]
 

Removes the virtual keeper.

bool Game::retroMode const
 

Returns true, if we are in retro mode.

Note that setMapAndMoves() will unset the retro mode.

void Game::setAnimation int animation
 

Sets the animation speed.

Parameters:
animation   The animation speed.

void Game::setHonorDeadlock bool honor_deadlocks
 

Sets if the should honor deadlock fields.

Parameters:
honor_deadlocks   If true, we honor deadlock fields.

void Game::setMapAndMoves Map * map,
Movements const & moves
 

Sets a new map with movements.

Parameters:
map   The start map.
moves   The initial moves.

void Game::setMoves Movements const & moves
 

Sets new moves.

Note that we automatically jump to the actual move.

Parameters:
moves   The moves to set.

bool Game::setRetroMode bool retro_mode
 

Sets the retro mode.

If you switch to retro mode and the keeper sits on a goal, we don't switch to retro mode.

Parameters:
retro_mode   If true, we switch to retro mode.
Returns:
True, if the switching was successful.

void Game::setShowArrows bool show
 

Sets if we should display arrows.

Parameters:
show   If true, we display arrows for valid moves.

bool Game::showArrows const
 

Returns true, if we show arrows.

Movements Game::simplifyMove Move const & move,
Map const * map
const [private]
 

Returns a simplified version of a move.

Parameters:
move   The move to simplify.
map   The map to use.

Movements Game::simplifyUndoMove Move const & move,
Map const * map
const [private]
 

Returns a simplified version of a undo move.

Parameters:
move   The undo move to simplify.
map   The map to use.

bool Game::tryFarMove AtomicMove const & move
 

Tries to move the keeper as far in a direction as possible.

If the first move would push a stone, we move the stone as far as possible and in the other case we move as far, as we reach a wall or a stone.

Parameters:
move   The direction of the move.

bool Game::tryMove Move const & move
 

Tries to make the given move.

Parameters:
move   The move to try.
Returns:
True if the move was made.

bool Game::tryMove AtomicMove const & move
 

Tries to make the given atomic move.

Parameters:
move   The atomic move to try.
Returns:
True if the move was made.

bool Game::tryMoveGem QPoint const & from,
QPoint const & to
 

Tries to move a gem from one point to the other.

Parameters:
from   The start position of the gem.
end   The end position of the gem.
Returns:
True, if the gem was moved.

bool Game::tryMoveKeeper QPoint const & from,
QPoint const & to
 

Tries to move the keeper.

Parameters:
from   The start position of the keeper.
to   The desired end position of the keeper.
True, if   the keeper was moved.

bool Game::tryPullMove AtomicMove const & move
 

Tries to move the keeper and pull a gem.

Parameters:
move   The atomic move to try.
Returns:
True, if the move was made (with or without pulling a gem).

bool Game::tryRedo
 

Tries to redo a move.

Returns:
True, if a redo move existed.

bool Game::tryUndo
 

Tries to undo a move.

Returns:
True, if an undo move existed.

void Game::undo [private]
 

Undoes a move.

void Game::virtualKeeperChanged const QPoint & position [signal]
 

This is emitted, if the virtual keeper was moved.

Parameters:
position   The new position of the virtual keeper.

void Game::wasSolved [signal]
 

This is emitted, whenever the map is solved.

void Game::wasSolvedByHand [signal]
 

This is emitted, whenever the map was solved by a try***() function (so not by undo, redo, play ...).

void Game::wasUnsolved [signal]
 

Emitted of we leave a solution.


Member Data Documentation

int Game::m_animation [private]
 

The animation speed.

Map Game::m_backup_map [private]
 

The backup map.

Movements Game::m_backup_moves [private]
 

The backup moves.

bool Game::m_handmade_moves [private]
 

If true, the moves in the queue are handmade moves.

int Game::m_height [private]
 

The height of the map.

bool Game::m_honor_deadlocks [private]
 

If true, we honor deadlock fields.

bool Game::m_in_play [private]
 

If true, we are playing the moves.

bool Game::m_is_solved [private]
 

If true, the level is solved.

AtomicMove::AtomicMoveType Game::m_keeper_direction [private]
 

The keeper direction.

Map* Game::m_map [private]
 

The current map.

std::deque<Move> Game::m_move_queue [private]
 

The moves in the move queue.

Movements Game::m_moves [private]
 

The current moves.

bool Game::m_no_update [private]
 

If true, we don't call mapChanged() in processMoveQueue().

int Game::m_number_of_moves [private]
 

The number of moves made.

int Game::m_number_of_pushes [private]
 

The number of pushes made.

bool Game::m_prevent_update [private]
 

If true, we prevent updates.

bool Game::m_retro_mode [private]
 

If true, we are in retro mode.

bool Game::m_show_arrows [private]
 

If true, we also calculate valid pushes and the corresponding arrows.

int Game::m_size [private]
 

m_width * m_height.

QTimer* Game::m_timer [private]
 

The animation timer.

bool Game::m_undo_moves [private]
 

If true, the moves in the queue are undo moves.

QPoint Game::m_virtual_keeper [private]
 

The position of the virtual keeper.

int Game::m_width [private]
 

The width of the map.

bool Game::m_wrap_virtual_keeper [private]
 

If true, we wrap the virtual keeper around the sides of the map.

int Game::m_xy_offsets[4] [private]
 

The offsets for nb calculation.

int Game::s_fast_time [static, private]
 

The time for fast animation.

int Game::s_normal_time [static, private]
 

The time for normal animation.

int Game::s_slow_time [static, private]
 

The time for slow animation.


The documentation for this class was generated from the following file:
Generated at Sun Jan 6 18:49:10 2002 for EasySok by doxygen1.2.9.1 written by Dimitri van Heesch, © 1997-2001