1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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"
|