#include "freeplay.h" #include "interface.h" #include "physics.h" #include "utility.h" #include "player.h" #include "global.h" #include "team.h" #include #include #include #include #include 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"