source: network-game/common/Player.h@ 0065962

Last change on this file since 0065962 was 48801af, checked in by Dmitry Portnoy <dmp1488@…>, 10 years ago

Use an enum for the player's team

  • Property mode set to 100644
File size: 1.9 KB
Line 
1#ifndef _PLAYER_H
2#define _PLAYER_H
3
4#include <string>
5#include <map>
6
7#include "Compiler.h"
8
9#if defined WINDOWS
10 #include <winsock2.h>
11#elif defined LINUX
12 #include <netinet/in.h>
13#elif defined MAC
14 #include <netinet/in.h>
15#endif
16
17#include "WorldMap.h"
18
19using namespace std;
20
21//forward declaration
22class Game;
23
24class Player {
25private:
26 unsigned int id;
27 unsigned int targetPlayer;
28
29public:
30
31 enum PlayerClass {
32 CLASS_NONE,
33 CLASS_WARRIOR,
34 CLASS_RANGER
35 };
36
37 enum AttackType {
38 ATTACK_NONE,
39 ATTACK_MELEE,
40 ATTACK_RANGED
41 };
42
43 enum PlayerTeam {
44 TEAM_NONE,
45 TEAM_BLUE,
46 TEAM_RED
47 };
48
49 Player();
50 Player(const Player& p);
51 Player(string name, string password);
52
53 ~Player();
54
55 unsigned int getId();
56 unsigned int getTargetPlayer();
57
58 void setId(unsigned int id);
59 void setTargetPlayer(unsigned int id);
60 void setAddr(sockaddr_in addr);
61 void setClass(PlayerClass c);
62
63 void serialize(char* buffer);
64 void deserialize(char* buffer);
65
66 bool updateTarget(map<unsigned int, Player*>& players);
67 bool move(WorldMap *map);
68 void takeDamage(int damage);
69
70 void takeFlag(unsigned int flag, WorldMap* map);
71 void dropFlag(unsigned int flag, WorldMap* map);
72
73 string name;
74 string password;
75 sockaddr_in addr;
76 FLOAT_POSITION pos;
77 POSITION target;
78 unsigned long long timeLastUpdated;
79 unsigned long long timeAttackStarted;
80 unsigned long long timeDied;
81 bool isChasing;
82 bool isAttacking;
83 bool isDead;
84
85 PlayerClass playerClass;
86 int maxHealth;
87 int health;
88 int attackType;
89 int damage;
90 int range;
91 unsigned long long attackCooldown;
92 PlayerTeam team;
93 bool hasBlueFlag;
94 bool hasRedFlag;
95
96 // permanent attributes
97 unsigned int level;
98 unsigned int experience;
99 unsigned int honor;
100 unsigned int wins;
101 unsigned int losses;
102
103 Game* currentGame;
104};
105
106#endif
Note: See TracBrowser for help on using the repository browser.