File: BurgerSpaceClient.h

package info (click to toggle)
burgerspace 1.9.2-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,524 kB
  • sloc: sh: 10,939; cpp: 5,791; makefile: 240
file content (205 lines) | stat: -rw-r--r-- 7,462 bytes parent folder | download | duplicates (3)
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
/*  $Id: BurgerSpaceClient.h,v 1.4 2013/02/25 05:04:43 sarrazip Exp $
    BurgerSpaceClient.h - Game client

    burgerspace - A hamburger-smashing video game.
    Copyright (C) 2001-2013 Pierre Sarrazin <http://sarrazip.com/>

    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 _H_BurgerSpaceClient
#define _H_BurgerSpaceClient

#include <flatzebra/GameEngine.h>
#include <flatzebra/SoundMixer.h>
#include <flatzebra/Sprite.h>

#include <map>

#include "BurgerSpaceServer.h"

class RemoteServer;


class BurgerSpaceClient : public flatzebra::GameEngine
{
public:

    BurgerSpaceClient(Role _role,
                        bool _showRole,
                        bool _useSound,
                        SDLKey _pepperKey,
                        bool _fullScreen,
                        bool _processActiveEvent);

    virtual ~BurgerSpaceClient();

    /*  Creates an object that establishes a UDP connection to a UDP server.
        This method blocks while it resolves the given server hostname
        to an IP address.
        'port' must be the UDP port on which the server is listening on
        the machine designated by the hostname.
        'role' must be the role that the user of this client wants to play;
        the server may not grand ROLE_CHEF or ROLE_ENEMY it the role is
        already assigned to an already connected user.
        Stores -1 in 'errorCode' if the host name could not be resolved to
        an IP address.
        Stores a positive <errno.h> code in 'errorCode' if it failed to
        create and connect a UDP socket to the designated host and port.
        Stores 0 in 'errorCode' otherwise.
        If 'errorCode' is non-zero, then the method also returns NULL.
        If 'errorCode' is zero, then the method also returns a non-null
        pointer to an object that represents the server.  This pointer
        should then be passed to setServer().
        Upon a successful connection, the method sends a description of
        this client to the server and requests a level update from the
        server.
    */
    RemoteServer *createRemoteServer(const std::string &serverHostname,
                                        unsigned short port,
                                        Role role,
                                        int &errorCode);

    /*  Tells this client object to use 'server' as its server interface.
        'server' should be obtained from createRemoteServer().
    */
    void setServer(BurgerSpaceServerInterface *server);


    // Inherited from flatzebra::GameEngine -- not used.
    virtual void processKey(SDLKey /*keysym*/, bool /*pressed*/) {}

    // Inherited from flatzebra::GameEngine.
    virtual void processActivation(bool appActive);

    // Inherited from flatzebra::GameEngine -- not used.
    virtual bool tick() { return false; }

    void runClientMode(Uint32 millisecondsPerFrame);

    void handleRoleAssignment(Role assignedRole);

    void handleLevelUpdate(int levelNo, size_t numColumns, size_t numRows, flatzebra::Couple levelPos, const std::string &desc);

    void handleSpriteUpdate(uint32_t id, BurgerSpaceServer::SpriteType type, flatzebra::Couple pos, size_t pixmapIndex);

    void handleSpriteDeletion(uint32_t id);

    void handleSoundEffect(BurgerSpaceServer::SoundEffect se);

    void handleScoreUpdate(long theScore, int numLives, int numAvailablePeppers, int cumulLevelNo);

private:

    int getSpriteDisplayLevel(const flatzebra::Sprite &s) const;

private:

    BurgerSpaceServerInterface *serverInterface;
    Role role;
    bool showRole;
    flatzebra::Couple roleAreaPos;
    flatzebra::Couple roleAreaSize;
    BurgerSpaceServer::Level theCurrentLevel;
    SDL_Surface *tilePixmaps[5];
    flatzebra::PixmapArray playerPA;
    flatzebra::PixmapArray pepperPA;
    flatzebra::PixmapArray eggPA;
    flatzebra::PixmapArray hotdogPA;
    flatzebra::PixmapArray picklePA;
    flatzebra::PixmapArray topBunPA;
    flatzebra::PixmapArray lettucePA;
    flatzebra::PixmapArray meatPA;
    flatzebra::PixmapArray redStuffPA;
    flatzebra::PixmapArray yellowStuffPA;
    flatzebra::PixmapArray bottomBunPA;
    flatzebra::PixmapArray treatPA;
    flatzebra::PixmapArray digitPA;

    std::map<uint32_t, flatzebra::Sprite *> spriteTable;

    long theScore;      // player's score in points
    flatzebra::Couple scoreAreaPos;
    flatzebra::Couple scoreAreaSize;

    int numLives;  // number of player lives left
    flatzebra::Couple numLivesAreaPos;
    flatzebra::Couple numLivesAreaSize;

    int numAvailablePeppers;  // number of pepper shots available to player
    flatzebra::Couple numAvailablePeppersAreaPos;
    flatzebra::Couple numAvailablePeppersAreaSize;
    SDLKey pepperKey;

    int cumulLevelNo;
    flatzebra::Couple levelNoAreaPos;
    flatzebra::Couple levelNoAreaSize;

    std::string currentPauseMessage;

    enum GameMode { QUIT_DIALOG, SAVE_DIALOG, LOAD_DIALOG, IN_GAME };

    GameMode gameMode;

    size_t slotDirCursorPos;  // 1..9; used by getSlotNumber()

    /*  SOUND EFFECTS:
    */
    flatzebra::SoundMixer *theSoundMixer;  // see method playSoundEffect()
    bool useSound;
    flatzebra::SoundMixer::Chunk ingredientBouncesChunk;
    flatzebra::SoundMixer::Chunk ingredientInPlateChunk;
    flatzebra::SoundMixer::Chunk ingredientFallsChunk;
    flatzebra::SoundMixer::Chunk ingredientLoweredChunk;
    flatzebra::SoundMixer::Chunk enemyCatchesChefChunk;
    flatzebra::SoundMixer::Chunk enemyParalyzedChunk;
    flatzebra::SoundMixer::Chunk enemySmashedChunk;
    flatzebra::SoundMixer::Chunk chefThrowsPepperChunk;
    flatzebra::SoundMixer::Chunk chefGetsTreatChunk;
    flatzebra::SoundMixer::Chunk chefShootsBlanksChunk;
    flatzebra::SoundMixer::Chunk newGameStartsChunk;
    flatzebra::SoundMixer::Chunk levelFinishedChunk;
    flatzebra::SoundMixer::Chunk treatAppearsChunk;
    flatzebra::SoundMixer::Chunk treatDisappearsChunk;

    ///////////////////////////////////////////////////////////////////////////

    void loadPixmaps() throw(flatzebra::PixmapLoadError);
    void restoreBackground();
    void draw();
    void displayMessage(int row, const char *msg);
    void showDialogBox(const std::string &msg);

    void drawQuitDialog();
    bool doQuitDialog(SDLKey lastKeyPressed);

    void drawSaveDialog();
    int getSlotNumber(SDLKey lastKeyPressed);
    static std::string getSavedGamesDir();
    static std::string formSavedGameFilename(int slotNum);
    void showSlotDirectory();
    void doSaveDialog(SDLKey lastKeyPressed);

    void drawLoadDialog();
    void doLoadDialog(SDLKey lastKeyPressed);

    // Forbidden operations:
    BurgerSpaceClient(const BurgerSpaceClient &x);
    BurgerSpaceClient &operator = (const BurgerSpaceClient &x);
};


#endif  /* _H_BurgerSpaceClient */