-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.cs
136 lines (103 loc) · 3.13 KB
/
Player.cs
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
/************************************************************************************
SOURCE FILE: Player.cs
PROGRAM: server
FUNCTIONS: Player(EndPoint ep, byte id, float x, float z)
TakeDamage(byte damage)
IsDead()
DATE: Mar. 14, 2018
REVISIONS:
DESIGNER: Benny Wang
PROGRAMMER: Benny Wang
NOTES:
This is the class that the server uses to repersent the players in
the game.
**********************************************************************************/
using System;
using Networking;
public class Player
{
public EndPoint ep { get; set; }
public byte[] buffer { get; set; }
public byte id { get; set; }
public float x { get; set; }
public float z { get; set; }
public float r { get; set; }
public byte h { get; set; }
public int currentWeaponId { get; set; }
public byte currentWeaponType { get; set; }
/************************************************************************************
FUNCTION: Player
DATE: Mar. 14, 2018
REVISIONS:
DESIGNER: Benny Wang
PROGRAMMER: Benny Wang
INTERFACE: Player(EndPoint ep, byte id, float x, float z)
EndPoint ep: The networking enpdoint of the player.
byte id: The player id.
float x: The x position of the player.
float z: The z position of the player.
NOTES:
Creates a player with the given id at the given x, z positoin.
**********************************************************************************/
public Player(EndPoint ep, byte id, float x, float z)
{
this.ep = ep;
this.id = id;
this.x = x;
this.z = z;
this.r = 0;
this.h = 100;
this.currentWeaponId = 0;
this.currentWeaponType = 0;
}
/************************************************************************************
FUNCTION: TakeDamage
DATE: Mar. 14, 2018
REVISIONS:
DESIGNER: Benny Wang
PROGRAMMER: Benny Wang
INTERFACE: TakeDamage(byte damage)
byte damage: The amount of damage to take.
NOTES:
Subtracts the given damage from the player. If the player's health is lower than
the amount of damage given, the players health is set to 0 and their position is
permanently set to (1000 + id, 1000) to enuser that dead players are stuck in the
graveyard area.
**********************************************************************************/
public void TakeDamage(byte damage)
{
if (this.h < damage)
{
this.h = 0;
this.x = 1000 + this.id;
this.z = 1000;
}
else
{
this.h -= damage;
}
}
/************************************************************************************
FUNCTION: IsDead
DATE: Mar. 14, 2018
REVISIONS:
DESIGNER: Benny Wang
PROGRAMMER: Benny Wang
INTERFACE: IsDead()
RETURN: True if the player is dead, false otherwise.
NOTES:
Checks if the player is dead. If the player is dead this function will also set
their position to (1000 + id, 1000) to ensure that dead players are stuck in the
graveyard area.
**********************************************************************************/
public bool IsDead()
{
if (this.h == 0)
{
this.x = 1000 + this.id;
this.z = 1000;
return true;
}
return false;
}
}