summaryrefslogtreecommitdiffstats
path: root/kue/modules/8ball/8ball.h
blob: 73ee38643cb9c5f79ca31b46315fc4c332ac0ef1 (plain)
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
#ifndef _EIGHTBALL_H
#define _EIGHTBALL_H

#include <tqobject.h>
#include <klibloader.h>

#include "vector.h"
#include "point.h"
#include "rules.h"


// Forward declarations of our helper classes
class TQString;
class KuePlayer;

// Possible values of _game_called
enum gameCallType {GAME_UNCALLED, GAME_PLAYER1_STRIPES, GAME_PLAYER1_SOLIDS};


class EightBallFactory : KLibFactory {
  public:
	TQObject*  createObject(TQObject*, const char*, const char*, const TQStringList &);
};

class EightBall : public KueRulesEngine {
  TQ_OBJECT
  public:
	EightBall(TQObject *parent, const char *name);
	~EightBall();
	
	void start();

  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();

	void cuePlaced();
	void shotTaken();

  private:
	// Ask the interface to start the shot
	TQString startShotMessage();
	// Ask the interface to place the cue ball
	TQString placeCueBallMessage();

	// 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
	KuePlayer *_current_player;
	// The current team
	int _current_team;
	// Who's stripes? And who's solids?
	gameCallType _game_called;

	// Have we had a successful break?
	bool _broke;

	TQString sideString();
};


#endif