-
Notifications
You must be signed in to change notification settings - Fork 1
/
menu.py
147 lines (139 loc) · 4.54 KB
/
menu.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
146
147
import threading
from Tkinter import *
import os
from broadcast_client import *
from tcp_server_local import *
from tcp_client import *
from teste import Bomberman
class Carregamento(Frame):
def __init__(self, parent, op, nick):
Frame.__init__(self,parent)
self.pack(fill=BOTH)
root.protocol("WM_DELETE_WINDOW", self.close)
self.num = 0
self.op = op
self.nick=nick
self.tela()
self.create_widgets()
def create_widgets(self):
self.label = Label(self, bd=0)
self.label.pack()
Thread(target=self.animate).start()
Thread(target=self.conexao).start()
def tela(self):
self.texto = Label(self,text="Encontrando Jogador!")
self.texto.pack()
def animate(self):
while True:
try:
time.sleep(0.04)
img = PhotoImage(file="/usr/bin/radio.gif", format="gif - {}".format(self.num))
self.label.config(image=img)
self.label.image=img
self.num += 1
except:
self.num = 0
def conexao(self):
if self.op == 1:
self.cli = cliente('54.207.57.244')
self.cli.enviar("entrei")
resposta = self.cli.receber()
if resposta == "True":
self.destroy()
self.cli.enviar("sorteio")
resposta = self.cli.receber()
app = Bomberman(root,resposta,self.cli,self.nick)
#t1 = threading.Thread(target=app.conexao, args=[self.cli])
#t1.start()
app.master.title("Bomberman")
app.master.geometry("480x480+600+100")
app.master.resizable(width=False, height=False)
else:
udp = udpclient()
ip = udp.loop()
self.cli = cliente(ip)
self.cli.enviar("entrei")
resposta = self.cli.receber()
if resposta == "True":
self.destroy()
self.cli.enviar("sorteio")
resposta = self.cli.receber()
app = Bomberman(root,resposta,self.cli,self.nick)
#t1 = threading.Thread(target=app.conexao, args=[self.cli])
#t1.start()
app.master.title("Bomberman")
app.master.geometry("480x480+600+100")
app.master.resizable(width=False, height=False)
def close(self):
os._exit(0)
class Menu(Frame):
def __init__(self, parent):
Frame.__init__(self,parent)
self.pack(fill=BOTH, expand=1)
root.protocol("WM_DELETE_WINDOW", self.close)
self.tela()
def tela(self):
self.v = IntVar()
self.servidorexterno = Radiobutton(self, text="Conectar ao Servidor Externo",variable=self.v, value=1)
self.servidorexterno.place(x=10,y=50)
self.servidorlocal = Radiobutton(self, text="Conectar a algum Servidor Local",variable=self.v, value=2)
self.servidorlocal.place(x=10,y=70)
self.servidor1 = Radiobutton(self, text="Ser o Servidor",variable=self.v, value=3)
self.servidor1.place(x=10,y=90)
self.Button1=Button(self.master, text="Selecione", command=self.seleciona2)
self.Button1.place(x=20,y=110)
def seleciona2(self):
if self.v.get() == 1:
self.textexterno = Label(self, text="Nick:")
self.textexterno.place(x=250,y=50)
self.nickexterno = Entry(self, width="10")
self.nickexterno.place(x=290,y=50)
self.servidorexterno['state'] = 'disabled'
self.servidorlocal['state'] = 'disabled'
self.servidor1['state'] = 'disabled'
self.Button1.destroy()
self.Button1=Button(self.master, text="Selecione seu nick", command=self.seleciona)
self.Button1.place(x=20,y=110)
elif self.v.get() == 2:
self.textexterno = Label(self, text="Nick:")
self.textexterno.place(x=250,y=50)
self.nickexterno = Entry(self, width="10")
self.nickexterno.place(x=290,y=50)
self.servidorexterno['state'] = 'disabled'
self.servidorlocal['state'] = 'disabled'
self.servidor1['state'] = 'disabled'
self.Button1.destroy()
self.Button1=Button(self.master, text="Selecione seu nick", command=self.seleciona)
self.Button1.place(x=20,y=110)
elif self.v.get() == 3:
t1 = threading.Thread(target=self.servidor2)
t1.start()
self.Button1['state'] = 'disabled'
self.servidorexterno['state'] = 'disabled'
self.servidorlocal['state'] = 'disabled'
self.servidor1['state'] = 'disabled'
self.texto = Label(self,text="Servidor On!")
self.texto.pack()
def seleciona(self):
if self.v.get() == 1:
nick = self.nickexterno.get()
self.destroy()
app = Carregamento(root,self.v.get(),nick)
app.master.title("Bomberman")
app.master.geometry("450x240+600+100")
elif self.v.get() == 2:
nick = self.nickexterno.get()
self.destroy()
app = Carregamento(root,self.v.get(),nick)
app.master.title("Bomberman")
app.master.geometry("450x240+600+100")
def servidor2(self):
servidor()
def close(self):
os._exit(0)
root = Tk()
app = Menu(root)
app.master.title("Menu")
app.master.geometry("450x240+600+100")
app.master.resizable(width=False, height=False)
root.mainloop()