diff options
Diffstat (limited to 'kue/modules/freeplay/freeplay.cpp')
-rw-r--r-- | kue/modules/freeplay/freeplay.cpp | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/kue/modules/freeplay/freeplay.cpp b/kue/modules/freeplay/freeplay.cpp new file mode 100644 index 00000000..022c0ec9 --- /dev/null +++ b/kue/modules/freeplay/freeplay.cpp @@ -0,0 +1,93 @@ +#include "freeplay.h" +#include "interface.h" +#include "physics.h" +#include "utility.h" +#include "player.h" +#include "global.h" +#include "team.h" + +#include <tdelocale.h> +#include <tdemessagebox.h> +#include <stdlib.h> +#include <stdio.h> +#include <krandomsequence.h> + +const int BILLIARDS_COUNT = 15; + +K_EXPORT_COMPONENT_FACTORY( libkuefreeplay, FreePlayFactory ) + +TQObject *FreePlayFactory::createObject (TQObject *parent, const char* name, const char* classname, const TQStringList &args = TQStringList() ) +{ + Q_UNUSED(args); + + if (classname != TQString("KueRulesEngine")) + return 0; + + return new FreePlay(parent, name); +} + +FreePlay::FreePlay(TQObject *parent, const char *name) : KueRulesEngine(parent, name) +{ + KueUtility::layoutTable(); + KueUtility::layoutPockets(); + KueUtility::layoutBilliards(KueUtility::Triangle); + + _current_team = 0; +} + +FreePlay::~FreePlay() +{ +} + +void FreePlay::start() +{ + startShot(); +} + +void FreePlay::motionStopped() +{ + // The physics engine has finished its job, turn it off to save CPU time + KueGlobal::physics()->stop(); + + _current_team++; + + if (_current_team == KueGlobal::teams()->count()) + _current_team = 0; + + startShot(); +} + +void FreePlay::shotTaken() +{ + // Start the physics engine + KueGlobal::physics()->start(); +} + +void FreePlay::startShot() +{ + TQString message; + KuePlayer *current_player = KueGlobal::teams()->at(_current_team)->nextPlayer(); + + // Did the cue ball get sunk? Replace it. + if (!KueGlobal::physics()->billiards()[0]) + { + KueBilliard cue( + KueGlobal::physics()->fieldWidth() / 4.0, + KueGlobal::physics()->fieldHeight() / 2.0, + KueUtility::defaultBilliardRadius() + ); + + KueGlobal::physics()->insertBilliard(0, cue); + } + + // What type of shot is this? + message = i18n("%1's shot").arg(current_player->name()); + + // Show the generated message + emit(showMessage(message)); + + // Tell the interface to start the shot UI. + current_player->takeShot(0, false, this, TQ_SLOT(shotTaken())); +} + +#include "freeplay.moc" |