My Project
 All Classes
Client.h
1 #pragma once
2 
3 #include <ClanLib/core.h>
4 #include <ClanLib/network.h>
5 #include <vector>
6 #include "direction.h"
7 enum CONTROL {WASD, ARROW};
8 
9 class Client : public CL_Runnable
10 {
11 public:
12  Client();
13  Client(CL_String8 _nickname, CL_String8 _ip, CL_String8 _port);
14  ~Client();
15 
16  typedef struct narea{
17  std::string area; int h; int w;
18  } netarea;
19 
20  void run();
21  void setServer(CL_String server);
22  void setNickame(CL_String nick);
23  void sendKey(int id);
24  void quit();
25  void setNetworkControl(CONTROL c);
26 
27  bool hasQuit();
28  bool isConnected();
29  bool isWaiting();
30 
31  int getLives(unsigned int i);
32  int getRemainingTime();
33  CL_String8 getName(unsigned int i);
34 
35  netarea getArea();
36 
37 
38 private:
39  void connect_to_server();
40 
41  void on_connected();
42  void on_disconnected();
43 
44  void on_event_received(const CL_NetGameEvent &e);
45 
46  void on_event_say_name_success(const CL_NetGameEvent &e);
47  void on_event_say_name_fail(const CL_NetGameEvent &e);
48  void on_event_server_full(const CL_NetGameEvent &e);
49  void on_event_game_start(const CL_NetGameEvent &e);
50  void on_event_names_data(const CL_NetGameEvent &e);
51  void on_event_game_rcv_data(const CL_NetGameEvent &e);
52 
53 
54 
55 private:
56  CL_NetGameClient network_client;
57  CL_SlotContainer slots;
58  std::map<char,CL_String8> names;
59 
60  CL_NetGameEventDispatcher_v0 name_event;
61  CL_NetGameEventDispatcher_v0 game_event;
62 
63  bool _quit;
64  bool said_name;
65  bool connected;
66  bool waiting;
67  bool gotArea;
68  CONTROL netcontrol;
69 
70  CL_String8 nickname;
71  CL_String8 port;
72  CL_String8 ip;
73  netarea area;
74  std::vector<int> lives;
75  int remainingTime;
76 };