-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.hpp
129 lines (115 loc) · 3.71 KB
/
game.hpp
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
121
122
123
124
125
126
127
128
129
/*
sueca - An implementation of the Portuguese game "Sueca" in C++ and wxWidgets
Copyright (C) 2003-2024 Rodrigo Araujo
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef _GAME_HPP_
#define _GAME_HPP_ 1
// Forward declarations
class PlayerIteratorNode;
class PlayerIterator;
class EndTurnTimer;
class Game;
#include <wx/timer.h>
#include "cards.hpp"
#include "mycanvas.hpp"
#include "player.hpp"
#include "scoredialog.hpp"
#include "trumphdialog.hpp"
// Circular player iterator node class
class PlayerIteratorNode
{
public:
PlayerIteratorNode( Player* player, PlayerIteratorNode* next );
Player* GetData() const { return m_player; }
PlayerIteratorNode* GetNext() const { return m_next; }
void SetNext( PlayerIteratorNode* next ) { m_next = next; }
private:
Player* m_player;
PlayerIteratorNode* m_next;
};
// Circular player iterator class
class PlayerIterator
{
public:
PlayerIterator( Player *p1, Player *p2, Player *p3, Player *p4 );
PlayerIterator( PlayerIterator& original );
~PlayerIterator();
bool SetCurrent( Player *player );
void SetCurrent( size_t n );
Player* GetCurrent() { return m_current->GetData(); }
Player* GetNext();
Player* operator []( size_t n_index );
PlayerIteratorNode* GetFirst() { return m_first; }
bool Replace( Player* oldplayer, Player* newplayer );
private:
PlayerIteratorNode* m_first;
PlayerIteratorNode* m_current;
};
// Timer to wait when the turn ends before collecting cards
class EndTurnTimer: public wxTimer
{
public:
EndTurnTimer( Game* game );
void Notify();
private:
Game* m_game;
};
// Game engine class
enum movestatus_t { MOVE_OK, MOVE_TURN, MOVE_INVALID, MOVE_DELAYED };
class Game
{
public:
ScoreDialog* score;
TrumphDialog* trumphdlg;
Game( Player* p1,
Player* p2,
Player* p3,
Player* p4,
MyCanvas *the_canvas );
virtual ~Game();
Deck& GetDeck() const { return (Deck&)m_deck; }
PlayerIterator* GetPlayers() { return new PlayerIterator( *m_players ); }
Player* TurnWinner();
void CardMoved( Card* card );
virtual void NewRound();
virtual void EndTurn();
unsigned short CalcWonGames( Team** win );
void PassTurn( Player* player = NULL );
virtual movestatus_t PlayMove( Player *player, Card *card );
CardList& GetPlayed() const { return (CardList&)m_played; }
Card* GetTrumph() const { return m_trumph; }
bool ReplacePlayer( Player* oldplayer, Player* newplayer );
virtual void SetPlayerName( Player* player, const wxString& newname );
void RefreshNames();
void DisplayResults();
protected:
MyCanvas *canvas;
// Ensure deck is initialized after the wxApp derived class has started,
// or wxBitmap objects creation may cause segfaults under wxGTK.
Deck m_deck;
PlayerIterator *m_players;
PlayerIterator *m_roundpos;
Team *team1;
Team *team2;
CardList m_played;
Card* m_trumph;
Player* trumph_owner;
unsigned short m_cards_to_collect;
EndTurnTimer m_endturntimer;
unsigned short turns_left;
bool playtime;
private:
static Game* running;
};
#endif // _GAME_HPP_