summaryrefslogtreecommitdiffstats
path: root/konquest/gameboard.h
blob: 7826d00fc8bdfa9ad7a6ddbe2210d5e1c71b3eaa (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#ifndef _GAMEBOARD_H_
#define _GAMEBOARD_H_

#include <tqwidget.h>

#include "planet_info.h"
#include "map_widget.h"

//************************************************************************
// forward declarations
//************************************************************************
class TQSlider;
class TQLabel;
class TQListBox;
class TQPushButton;
class TQLineEdit;
class TQTextEdit;

enum GameState { NONE, SOURCE_PLANET, DEST_PLANET, SHIP_COUNT, RULER_SOURCE, RULER_DEST, AI_PLAYER };

//************************************************************************
// GameBoard Widget
//************************************************************************
class GameBoard : public TQWidget
{
    Q_OBJECT
  TQ_OBJECT

public:
    GameBoard( TQWidget *tqparent );
    virtual ~GameBoard();

    bool isGameInProgress(void) const { return gameInProgress; }

//    virtual TQSize tqsizeHint() const;

protected slots:
    void startNewGame();
    void shutdownGame();
    void planetSelected( Planet * );
    void newShipCount();
    void nextPlayer();

    //***************************************************************
    // Toolbar items
    //***************************************************************
    void measureDistance();
    void showScores();
    void showFleets();

signals:
    void newGameState( GameState newState );

    //***************************************************************
    // Event Handlers
    //***************************************************************
protected:
    virtual void keyPressEvent( TQKeyEvent * );

private:
    void turn();
    void nextTurn();
    void gameOver();

    void resolveShipsInFlight();
    void sendAttackFleet( Planet *source, Planet *dest, int ships );
    void doFleetArrival( AttackFleet *arrivingFleet );
    void scanForSurvivors();

    void gameMsg(const TQString &msg, Player *player = 0, Planet *planet = 0, Player *planetPlayer = 0);

    void changeGameBoard( bool inPlay );
    void cleanupGame();
    Player *findWinner();

    TQString playerString(Player *player = 0);
    
    //***************************************************************
    // Game State information
    //***************************************************************
    bool gameInProgress;
    GameState gameState;
    PlayerListIterator *currentPlayer;

    //***************************************************************
    // Display Widgets
    //***************************************************************
    ConquestMap *mapWidget;
    PlanetInfo *planetInfo;
    TQLabel *gameMessage;
    TQLabel *turnCounter;
    TQPushButton *endTurn;
    TQLineEdit *shipCountEdit;
    TQLabel *splashScreen;
    TQTextEdit *msgWidget;


    //***************************************************************
    // Game objects
    //***************************************************************
    int turnNumber;
    int lastTurn;

    PlayerList players;
    PlanetList planets;
    Player *neutralPlayer;
    Map *map;

    bool haveSourcePlanet;
    Planet *sourcePlanet;

    bool haveDestPlanet;
    Planet *destPlanet;

    bool haveShipCount;
    int shipCount;

};

#endif