Repository navigation
Expand file tree
/
Copy pathClientThread.py
More file actions
53 lines (51 loc) · 1.57 KB
/
Copy pathClientThread.py
File metadata and controls
53 lines (51 loc) · 1.57 KB
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
from threading import Thread
from Player import player
from Weapon import *
class ClientThread(Thread):
def __init__(self, client, player, bulletList, playerList):
Thread.__init__(self)
self.client = client
self.bulletList = bulletList
self.player = player
self.playerList = playerList
def run(self):
self.client.send(b"Success")
while True:
data = self.client.recv(10).strip()
if not data:
break
print(data)
if data == b'0':
self.player.go_left()
if data == b'1':
self.player.jump()
if data == b'2':
self.player.go_right()
if data == b'3':
if self.player.dead == False:
bullet = self.player.weapon.shoot()
if not bullet is None:
self.bulletList.add(bullet)
if data == b'4':
self.player.stop()
if data.endswith(b'4'):
self.player.stop()
if data == b'5':
self.playerList.remove(self.player.weapon)
self.player.weapon = Weapon.machineGun(1)
self.player.weapon.rect.x = self.player.rect.x + 50
self.player.weapon.update()
self.playerList.add(self.player.weapon)
if data == b'6':
self.playerList.remove(self.player.weapon)
self.player.weapon = Weapon.grenade_launcher(direction = 1)
self.player.weapon.rect.x = self.player.rect.x + 50
self.player.weapon.update()
self.playerList.add(self.player.weapon)
if data == b'7':
self.playerList.remove(self.player.weapon)
self.player.weapon = Weapon.shotgun(direction = 1)
self.player.weapon.rect.x = self.player.rect.x + 50
self.player.weapon.update()
self.playerList.add(self.player.weapon)
self.client.close()