forked from H3LLB0Y/Warlocks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lobby.py
145 lines (128 loc) · 3.52 KB
/
lobby.py
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
137
138
139
140
141
142
143
144
145
from direct.gui.DirectGui import *
from direct.gui.OnscreenImage import OnscreenImage
from direct.gui.OnscreenText import OnscreenText
from pandac.PandaModules import *
class Lobby():
def __init__(self, game):
self.game=game
self.ready=False
self.game.num_warlocks=1
self.game.which=0
self.background = OnscreenImage(
image = 'media/gui/lobby.jpg',
parent = render2d
)
# Send Message Button
self.send_button = DirectButton(
command = self.send_message,
frameSize = (-3, 3, -.5, 1),
pos = (0.0, 0.0, .3),
scale = .1,
text = "Send",
)
# Text box for message entry
self.entry = DirectEntry(
focusInCommand = self.clearText,
frameSize = (-3, 3, -.5, 1),
initialText = "Chat:",
parent = self.send_button,
pos = (0, 0, -1.5),
text = "" ,
text_align = TextNode.ACenter,
)
# button to tell server client is ready
self.ready_button = DirectButton(
command = self.toggle_ready,
frameSize = (-3, 3, -.5, 1),
pos = (0.0, 0.0, -.3),
scale = .1,
text = "Ready?",
)
# button to tell server client is not ready
self.unready_button = DirectButton(
command = self.toggle_unready,
frameSize = (-3, 3, -.5, 1),
pos = (0.0, 0.0, -.3),
scale = .1,
text = "Unready?",
)
# hide unready button until ready
self.unready_button.hide()
# button to quit game
self.quit_button = DirectButton(
command = game.quit,
frameSize = (-4,-1,0,0),#-3, 3, -.5, 1),
pos = (-1.0, 0.0, -1.0),
scale = .1,
text = "QUIT!",
)
# Add the game loop procedure to the task manager.
taskMgr.doMethodLater(1.0, self.update_lobby, 'Update Lobby')
def update_lobby(self, task):
temp=self.game.client.getData()
if temp!=[]:
for i in range(len(temp)):
valid_packet=False
package=temp[i]
if len(package)==2:
print "Received: " + str(package)
# if username is sent, assign to client
if package[0]=='chat':
print "Chat: "+package[1]
valid_packet=True
# updates warlocks in game
elif package[0]=='warlocks':
print "warlocks: "+str(package[1])
self.game.num_warlocks=package[1]
valid_packet=True
elif package[0]=='which':
print "i am warlock: "+str(package[1])
self.game.which=package[1]
valid_packet=True
# changes to game state
elif package[0]=='state':
print "state: "+package[1]
if package[1]=='game':
self.game.join_game()
valid_packet=True
if not valid_packet:
data = {}
data[0] = "error"
data[1] = "Fail Server"
self.game.client.sendData(data)
print "Bad packet from server"
else:
print "Packet wrong size"
return task.again
#def select_spell(self,spell):
def toggle_ready(self):
self.ready=True
data = {}
data[0] = "ready"
data[1] = "ready"
self.ready_button.hide()
self.unready_button.show()
self.game.client.sendData(data)
def toggle_unready(self):
self.unready=True
data = {}
data[0] = "unready"
data[1] = "unready"
self.unready_button.hide()
self.ready_button.show()
self.game.client.sendData(data)
def send_message(self):
data = {}
data[0] = "chat"
data[1] = self.entry.get()
self.entry.enterText('')
self.game.client.sendData(data)
def clearText(self):
self.entry.enterText('')
def hide(self):
self.background.hide()
self.send_button.hide()
self.entry.hide()
self.ready_button.hide()
self.unready_button.hide()
self.quit_button.hide()