-
Notifications
You must be signed in to change notification settings - Fork 0
/
local_player.cpp
61 lines (49 loc) · 1.01 KB
/
local_player.cpp
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
#include"local_player.h"
local_player::local_player(int team, char * file, image * h, image ** r,
TCPsocket sock)
: human(team, file, h,r)
{
_sock = sock;
}
void local_player::send_pickup(int x, int y)
{
sprintf(_mess,"pickup %d %d", x,y);
send();
}
void local_player::send_putdown(int x, int y)
{
sprintf(_mess,"putdown %d %d", x,y);
send();
}
void local_player::send_motion(int x, int y)
{
sprintf(_mess,"motion %d %d", x,y);
send();
}
void local_player::send_location(int id, int x, int y)
{
sprintf(_mess,"location %d %d %d",id,x,y);
send();
}
void local_player::send_move(int oldx, int oldy, int newx, int newy)
{
sprintf(_mess,"move %d %d %d %d",oldx ,oldy, newx, newy);
SDL_Delay(100);
send();
}
void local_player::send_done()
{
sprintf(_mess,"done");
send();
}
void local_player::send()
{
int len, ret;
len = strlen(_mess) + 1;
ret = SDLNet_TCP_Send(_sock, _mess, len);
if (ret < len)
{
cerr<<"Client disconnected....I quit!"<<endl;
exit(1);
}
}