-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.hpp
229 lines (210 loc) · 8.12 KB
/
player.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*
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 _PLAYER_HPP_
#define _PLAYER_HPP_ 1
// Forward declarations
class GamePos;
class GamePosP1;
class GamePosP2;
class GamePosP3;
class GamePosP4;
class Player;
class Team;
class HumanPlayer;
class LocalPlayer;
class BotPlayer;
class DumbPlayer;
#ifndef MAX_CARDS
#define MAX_CARDS 10
#endif // MAX_CARDS
#include "mycanvas.hpp"
#include "cards.hpp"
#include "game.hpp"
// Game Layout
// Canvas dimensions MC_X_SIZE, MC_Y_SIZE defined in mycanvas.hpp
#define CARDBMP_W 71
#define CARDBMP_H 96
#define CARDBMP_INCR 15
#define CARDBMP_GAP 10
#define PLAYED_CARD_GAP 20
#define NAME_GAP 15
#define TRUMPH_GAP 10
// Game layout positioners
class GamePos
{
public:
GamePos(): i( 0 ) {}
wxString& GetName() { return m_name; }
virtual ~GamePos() {}
virtual wxPoint& NextPosition() = 0;
virtual wxPoint NamePosition( wxSize& size ) = 0;
virtual wxPoint PlayedCardPos() const = 0;
virtual wxPoint CollectPos() const = 0;
virtual wxPoint TrumphPos( wxSize& size ) const = 0;
virtual GamePos* Clone() const = 0;
protected:
void ResetCheck();
static int xgap;
static int ygap;
int i;
int xstart;
int ystart;
wxPoint pos;
wxString m_name;
};
class GamePosP1: public GamePos
{
public:
GamePosP1();
wxPoint& NextPosition();
wxPoint NamePosition( wxSize& size )
{ return wxPoint( xstart - size.GetWidth() - NAME_GAP, ystart + ( CARDBMP_H - size.GetHeight() ) / 2); }
wxPoint PlayedCardPos() const { return wxPoint( ( MC_X_SIZE - CARDBMP_W ) / 2, MC_Y_SIZE / 2 + PLAYED_CARD_GAP ); }
wxPoint CollectPos() const { return wxPoint( ( MC_X_SIZE - CARDBMP_W ) / 2, MC_Y_SIZE + CARDBMP_H ); }
wxPoint TrumphPos( wxSize& size ) const { return wxPoint( xstart + 9 * CARDBMP_INCR + CARDBMP_W + TRUMPH_GAP, ystart + CARDBMP_H - size.GetHeight() ); }
GamePos* Clone() const { return new GamePosP1( *this ); }
};
class GamePosP2: public GamePos
{
public:
GamePosP2();
wxPoint& NextPosition();
wxPoint NamePosition( wxSize& size )
{ return wxPoint( xstart + ( CARDBMP_W - size.GetWidth() ) / 2, ystart + NAME_GAP + CARDBMP_H ); }
wxPoint PlayedCardPos() const { return wxPoint( MC_X_SIZE / 2 + PLAYED_CARD_GAP, ( MC_Y_SIZE - CARDBMP_H ) / 2 ); }
wxPoint CollectPos() const { return wxPoint( MC_X_SIZE + CARDBMP_W, ( MC_Y_SIZE - CARDBMP_H ) / 2 ); }
wxPoint TrumphPos( wxSize& size ) const { return wxPoint( xstart + CARDBMP_W - size.GetWidth(), ystart - 9 * CARDBMP_INCR - TRUMPH_GAP - size.GetHeight() ); }
GamePos* Clone() const { return new GamePosP2( *this ); }
};
class GamePosP3: public GamePos
{
public:
GamePosP3();
wxPoint& NextPosition();
wxPoint NamePosition( wxSize& size )
{ return wxPoint( xstart + NAME_GAP + CARDBMP_W, ystart + ( CARDBMP_H - size.GetHeight() ) / 2); }
wxPoint PlayedCardPos() const { return wxPoint( ( MC_X_SIZE - CARDBMP_W ) / 2, MC_Y_SIZE / 2 - PLAYED_CARD_GAP - CARDBMP_H ); }
wxPoint CollectPos() const { return wxPoint( ( MC_X_SIZE - CARDBMP_W ) / 2, - CARDBMP_H ); }
wxPoint TrumphPos( wxSize& size ) const { return wxPoint( xstart - 9 * CARDBMP_INCR - TRUMPH_GAP - size.GetWidth(), ystart ); }
GamePos* Clone() const { return new GamePosP3( *this ); }
};
class GamePosP4: public GamePos
{
public:
GamePosP4();
wxPoint& NextPosition();
wxPoint NamePosition( wxSize& size )
{ return wxPoint( xstart + ( CARDBMP_W - size.GetWidth() ) / 2, ystart - size.GetHeight() - NAME_GAP); }
wxPoint PlayedCardPos() const { return wxPoint( MC_X_SIZE / 2 - PLAYED_CARD_GAP - CARDBMP_W, ( MC_Y_SIZE - CARDBMP_H ) / 2 ); }
wxPoint CollectPos() const { return wxPoint( - CARDBMP_W, ( MC_Y_SIZE - CARDBMP_H ) / 2 ); }
wxPoint TrumphPos( wxSize& size ) const { return wxPoint( xstart, ystart + 9 * CARDBMP_INCR + CARDBMP_H + TRUMPH_GAP ); }
GamePos* Clone() const { return new GamePosP4( *this ); }
};
// Generic player (abstract class)
class Player
{
public:
Player( GamePos* gamepos );
virtual ~Player() { delete m_gamepos; }
virtual void NewGame( Game* game ) {}
virtual void NewRound( Card* trumph, Player* owner ) {}
virtual void NewTurn( Player* starter ) {}
virtual void Turn( Player* player, Card* card ) {}
virtual void TurnEnd( const Player* winner, const CardList& played ) {}
virtual void OnMyTurn( Game* game, const CardList& played ) = 0;
virtual void AddToHand( Card* newcard, MyCanvas* canvas );
wxString& GetName() { return m_name; }
void SetName( const wxString& name ) { m_name = name; }
void SetTeam( Team* newteam ) { m_team = newteam; }
Team* GetTeam() { return m_team; }
bool AreCardsHidden() { return m_hidden_cards; }
wxPoint GetNamePos( wxSize labelsize ) { return m_gamepos->NamePosition( labelsize ); }
wxPoint GetTrumphPos( wxSize labelsize ) { return m_gamepos->TrumphPos( labelsize ); }
wxString GetNamePosStr() const { return m_gamepos->GetName(); }
wxPoint GetPlayPos() { return m_gamepos->PlayedCardPos(); }
wxPoint GetCollectPos() { return m_gamepos->CollectPos(); }
bool IsValidMove( const Card* card, const CardList& played );
void Remove( Card* card ) { GetHand().DeleteObject( card ); }
CardList& GetHand() const { return (CardList&)m_hand; }
void SetGamePos( GamePos* newpos );
GamePos* GetGamePos() const { return m_gamepos; }
GamePos* GetGamePosCopy() const { return m_gamepos->Clone(); }
protected:
GamePos* m_gamepos;
bool m_hidden_cards;
wxString m_name;
private:
Team* m_team;
CardList m_hand;
};
// Player team
class Team {
public:
Team( Player* np1, Player* np2 );
unsigned short GetRoundPoints() const { return m_points; }
void AddToWon( unsigned short won ) { m_won += won; }
unsigned short GetWon() const { return m_won; }
void AddToCapt( CardList& cards );
const CardList& GetCapt() const { return captured; }
void NewRound( Card* trumph, Player* owner );
bool Belongs( Player *player ) const { return player == p1 || player == p2; }
Player* GetP1() const { return p1; }
Player* GetP2() const { return p2; }
wxString& GetWonStr() const { return (wxString&)wonstr; }
void SetWonStr( wxString str ) { wonstr = str; }
bool Replace( Player* oldplayer, Player* newplayer );
private:
unsigned short m_won;
unsigned short m_points;
Player* p1;
Player* p2;
CardList captured;
wxString wonstr;
};
// Human player
class HumanPlayer: public Player {
public:
HumanPlayer( const wxString& name, GamePos* gamepos );
virtual ~HumanPlayer() {}
virtual void OnMyTurn( Game* game, const CardList& played ) {}
};
class LocalPlayer: public HumanPlayer {
public:
LocalPlayer( const wxString& name, GamePos* gamepos );
void AddToHand( Card* newcard, MyCanvas* canvas );
};
// Computer player (abstract class)
// N_BOT_NAMES should match the number of bot names in player.cpp
#define N_BOT_NAMES 14
class BotPlayer: public Player {
public:
BotPlayer( GamePos* gamepos );
virtual ~BotPlayer();
void OnMyTurn( Game* game, const CardList& played );
virtual Card* PlayCard( const CardList* played ) = 0;
private:
int nameind;
static char* botnames[N_BOT_NAMES];
static bool nameused[N_BOT_NAMES];
};
// Specific computer players
// Dumb player: plays first available card
class DumbPlayer: public BotPlayer {
public:
DumbPlayer( GamePos* gamepos );
Card* PlayCard( const CardList* played );
};
#endif // _PLAYER_HPP_