-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfoomy.py
138 lines (97 loc) · 2.74 KB
/
foomy.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
import socket
from pygame import surface
from pygame.cursors import sizer_x_strings
from board import *
import math
import pickle
import sys, pygame, random
from pygame.locals import *
import time
import winsound
from config import *
from grid import *
import copy
doExit = False
pygame.init()
# Set up screen
screen = pygame.display.set_mode(size)
# Make a list of all squareys
squareyTypes = [dirt(screen), water(screen)]
################################
# DIPLAY SQUAREY MENU #
################################
def showMenu(x, y):
gridSize = math.ceil(math.sqrt(len(squareyTypes)))
# Draw box
rect = pygame.Rect(x, y, (blockW + 5) * gridSize + 15, (blockH + 5) * gridSize + 15)
pygame.draw.rect(screen, pygame.Color("grey"), rect)
# Draw squareys
sx = x + 10
sy = y + 10
for sq in squareyTypes:
sq.drawAt(sx, sy)
sx = sx + blockW + 5
pygame.display.update()
# Wait for mouse click in squareys
loop = True
while loop:
events = pygame.event.get()
# Check for next click
for ev in events:
if ev.type == pygame.MOUSEBUTTONDOWN:
(clickx, clicky) = pygame.mouse.get_pos()
loop = False
# Work out which squarey clicked
sx = x + 10
sy = y + 10
for sq in squareyTypes:
rect = pygame.Rect(sx, sy, blockW, blockH)
if rect.collidepoint(clickx, clicky):
# Add clicked squarey to grid
myGrid.addSquarey(sq, x, y)
sx = sx + blockW + 5
################################
# CHECK KEYS #
################################
def checkKeys():
global doExit
events = pygame.event.get()
for ev in events:
# Check all keys
if ev.type == pygame.KEYDOWN:
if ev.key == pygame.K_ESCAPE:
doExit = True
if ev.type == pygame.QUIT:
doExit = True
if ev.type == pygame.MOUSEBUTTONDOWN:
(x, y) = pygame.mouse.get_pos()
showMenu(x, y)
if ev.type == pygame.MOUSEBUTTONUP:
myGrid.draw()
serverIP = "192.168.1.161"
serverPort = 60001
clientIP = None
clientPort = None
myboard = board()
myboard.set("tony")
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(('', serverPort))
sock.setblocking(False)
rxdata = []
myGrid = grid(screen)
myGrid.draw()
pygame.display.update()
while not doExit:
pygame.event.pump()
checkKeys()
pygame.display.update()
time.sleep(0.1)
pass
# try:
# (data, addr) = sock.recvfrom(65536)
# rxdata = data
# except:
# pass
# if len(rxdata) > 0:
# print("Got it *-*")
# sock.sendto(pickle.dumps(myboard), ("192.168.1.179", 60001))