-
Notifications
You must be signed in to change notification settings - Fork 0
/
game_of_luck_client.py
59 lines (47 loc) · 1.49 KB
/
game_of_luck_client.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
import sys
import random
import json
import time
import pygame
import time
from renderer import draw_everything
from get_ip import check_for_internet_conection as get_ip
from event_handler import unparse
from time import sleep, localtime
from weakref import WeakKeyDictionary
from PodSixNet.Server import Server
from PodSixNet.Channel import Channel
from PodSixNet.Connection import connection, ConnectionListener
class ClientLuck(ConnectionListener):
def __init__(self, host, port):
try:
pygame.init()
self.Connect((host, int(port)))
self.screen = pygame.display.set_mode((800, 600))
except:
exit()
def Loop(self):
connection.Send({'action': 'print_game_state'})
connection.Pump()
self.Pump()
def Network_connected(self, data):
print("You are now connected to the server")
def Network_error(self, data):
print("error: {0}".format(data['error'][1]))
connection.Close()
def Network_disconnected(self, data):
print('Server disconnected')
exit()
def Network_render_game_state(self, data):
draw_everything(self.screen, data['objects'])
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit()
pygame.display.update()
if data['should_stop']:
return data['closest_type']
exit()
if __name__ == "__main__":
host = get_ip()
s = ClientLuck(host, int(31425))
s.Loop()