diff options
author | Mavridis Philippe <mavridisf@gmail.com> | 2024-08-07 19:13:02 +0300 |
---|---|---|
committer | Mavridis Philippe <mavridisf@gmail.com> | 2024-08-07 19:23:24 +0300 |
commit | 04b5a62b8d9f5ff8240f25361046f2a5d58e8262 (patch) | |
tree | 98b126454cdf68d544e138d7e8b31d5fd45b72c2 /kue/modules/freeplay | |
parent | 83ba00b7e569587d50383ff06a70148042ca780e (diff) | |
download | tdegames-feat/kue.tar.gz tdegames-feat/kue.zip |
Add Kue billiards gamefeat/kue
Signed-off-by: Mavridis Philippe <mavridisf@gmail.com>
Diffstat (limited to 'kue/modules/freeplay')
-rw-r--r-- | kue/modules/freeplay/CMakeLists.txt | 42 | ||||
-rw-r--r-- | kue/modules/freeplay/freeplay.cpp | 93 | ||||
-rw-r--r-- | kue/modules/freeplay/freeplay.h | 46 | ||||
-rw-r--r-- | kue/modules/freeplay/freeplay.h.save | 85 | ||||
-rw-r--r-- | kue/modules/freeplay/freeplay.plugin | 5 |
5 files changed, 271 insertions, 0 deletions
diff --git a/kue/modules/freeplay/CMakeLists.txt b/kue/modules/freeplay/CMakeLists.txt new file mode 100644 index 00000000..0f935a3c --- /dev/null +++ b/kue/modules/freeplay/CMakeLists.txt @@ -0,0 +1,42 @@ +################################################################################ +# Improvements and feedback are welcome! # +# This software is licensed under the terms of the GNU GPL v3 license. # +################################################################################ + +include_directories( + ${CMAKE_BINARY_DIR} + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR} + ${TDE_INCLUDE_DIR} + ${TQT_INCLUDE_DIRS} +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + +### kuefreeplay (library) ####################################################### +tde_add_library( + kuefreeplay SHARED AUTOMOC + + SOURCES + freeplay.cpp + + LINK + tdeio-shared + kue-shared + + DESTINATION + ${LIB_INSTALL_DIR} +) + +### data ####################################################################### +install( + FILES + freeplay.plugin + + DESTINATION + ${DATA_INSTALL_DIR}/kue +) + +# kate: replace-tabs true; tab-width 2;
\ No newline at end of file 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" diff --git a/kue/modules/freeplay/freeplay.h b/kue/modules/freeplay/freeplay.h new file mode 100644 index 00000000..f51ba950 --- /dev/null +++ b/kue/modules/freeplay/freeplay.h @@ -0,0 +1,46 @@ +#ifndef _FREEPLAY_H +#define _FREEPLAY_H + +#include <tqobject.h> +#include <klibloader.h> + +#include "vector.h" +#include "point.h" +#include "rules.h" + + +// Forward declarations of our helper classes +class TQString; + +// Possible values of _game_called +enum gameCallType {GAME_UNCALLED, GAME_PLAYER1_STRIPES, GAME_PLAYER1_SOLIDS}; + + +class FreePlayFactory : KLibFactory { + public: + TQObject* createObject(TQObject*, const char*, const char*, const TQStringList &); +}; + +class FreePlay : public KueRulesEngine { + TQ_OBJECT + public: + FreePlay(TQObject *parent, const char *name); + ~FreePlay(); + + void start(); + + protected slots: + // Called by the physics engine when all billiards have stopped moving + void motionStopped(); + // Called by the interface after the user has decided on a shot + void shotTaken(); + + private: + // Ask the interface to start the shot + void startShot(); + + unsigned int _current_team; +}; + + +#endif diff --git a/kue/modules/freeplay/freeplay.h.save b/kue/modules/freeplay/freeplay.h.save new file mode 100644 index 00000000..36b9404e --- /dev/null +++ b/kue/modules/freeplay/freeplay.h.save @@ -0,0 +1,85 @@ +#ifndef _EIGHTBALL_H +#define _EIGHTBALL_H + +#include <ntqobject.h> +#include <klibloader.h> + +#include "vector.h" +#include "point.h" +#include "rules.h" + + +// Forward declarations of our helper classes +class TQString; + +// Possible values of _game_called +enum gameCallType {GAME_UNCALLED, GAME_PLAYER1_STRIPES, GAME_PLAYER1_SOLIDS}; + + +class FreePlayFactory : KLibFactory { + public: + TQObject* createObject(TQObject*, const char*, const char*, const TQStringList &); +}; + +class FreePlay : public TQObject, public KueRulesEngine { + Q_OBJECT + public: + FreePlay(); + ~FreePlay(); + + // Is the game over? + bool gameIsOver() { return false; } + + protected slots: + // Called by physics engine when a billiard is sunk + void billiardSunk(unsigned int ball, unsigned int pocket); + // Called by physics engine when a billiard is struck (by the cue ball or another billiard) + void billiardHit(unsigned int ball1, unsigned int ball2); + // Called by the physics engine when all billiards have stopped moving + void motionStopped(); + + // Called by the interface when the user has decided on a cue location + void cuePlaced(point &location); + // Called by the interface when the user is deciding on a cue location + void previewCuePlace(point &location); + // Called by the interface after the user has decided on a hot + void shotTaken(vector &velocity); + + private: + // Ask the interface to start the shot + void startShot(bool forward_only); + // Ask the interface to place the cue ball + void placeCueBall(); + + // Does a player only have an 8 ball left to shoot at? + bool onlyMagicLeft(int player); + // Does a player own a given ball? + bool ownsBall(int player, unsigned int ball); + + // Is a ball solid? + bool ballIsSolid(unsigned int number); + // Is a ball stripped? + bool ballIsStripe(unsigned int number); + // Is a ball the cue ball? + bool ballIsCue(unsigned int number); + // Is a ball the magic ball (8)? + bool ballIsMagic(unsigned int number); + + // Handle a player's victory + void playerWins(int player); + + // Is this shot a scratch? + bool _scratch; + // First ball sunk + int _first_sunk; + // First ball hit + int _first_hit; + + // The current player + int _current_player; + // Who's stripes? And who's solids? + gameCallType _game_called; +}; + + +#endif diff --git a/kue/modules/freeplay/freeplay.plugin b/kue/modules/freeplay/freeplay.plugin new file mode 100644 index 00000000..9e559e15 --- /dev/null +++ b/kue/modules/freeplay/freeplay.plugin @@ -0,0 +1,5 @@ +Filename=libkuefreeplay +Type=rulesengine +Name=Free Play +Description=A very simple version of 8-ball pool +# There are no minimum or maximum number of teams |