-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
126 lines (97 loc) · 3.8 KB
/
Copy pathclient.py
File metadata and controls
126 lines (97 loc) · 3.8 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
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
import pickle
import pygame
import sys
pygame.font.init()
from network import Network
pygame.init()
class Button:
def __init__(self, text, position):
self.text = text
self.font = pygame.font.Font(None, 30)
self.width = 150
self.height = 50
self.position = position
self.rect = pygame.Rect(position[0], position[1], self.width, self.height)
self.color = (0, 128, 255)
self.highlight_color = (0, 200, 255)
self.is_hovered = False
def draw(self, screen):
pygame.draw.rect(screen, self.highlight_color if self.is_hovered else self.color, self.rect)
text_surface = self.font.render(self.text, True, (255, 255, 255))
text_rect = text_surface.get_rect(center=self.rect.center)
screen.blit(text_surface, text_rect)
def check_hover(self, mouse_pos):
if self.rect.collidepoint(mouse_pos):
self.is_hovered = True
else:
self.is_hovered = False
n=Network()
screen_width = 800
screen_height = 600
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption("Client")
screen.fill((255,255,255))
button_1 = Button("1", (300, 200))
button_2 = Button("2",(300,200))
bts=[button_1,button_2]
playerStatus=[False,False,False,False]
print(all(playerStatus))
def redraw(screen):
screen.fill((255,255,255))
font = pygame.font.SysFont("comicsans", 60)
text = font.render("Prompts", 1, (0, 255,255))
screen.blit(text, (screen_width/2 - text.get_width()/2, screen_height/18 - text.get_height()/18))
def displayWaiting():
screen.fill((255,255,255))
font = pygame.font.SysFont("comicsans",50)
text=font.render("Waiting for Players",1,(255,0,0),True)
screen.blit(text, (screen_width/2 - text.get_width()/2, screen_height/4 - text.get_height()/4))
def displayCurrentPrompt():
current_prompt=n.send("current prompt")
current_prompt=str(current_prompt)
font = pygame.font.SysFont("comicsans", 36)
prompt_text = font.render(current_prompt, True, (0, 0, 0))
prompt_rect = prompt_text.get_rect(center=(screen_width // 2, 150))
screen.blit(prompt_text, prompt_rect)
def main():
run=True
checkStat=False
try:
p=n.send("pos")
print("You are player ",p)
displayWaiting()
pygame.display.flip()
except:
pass
while run:
while checkStat!=True:
checkStat=n.send("Connect")
displayWaiting()
pygame.display.flip()
redraw(screen)
displayCurrentPrompt()
for event in pygame.event.get():
if event.type==pygame.QUIT:
run=False
elif event.type==pygame.MOUSEMOTION:
bts[p].check_hover(pygame.mouse.get_pos())
elif event.type==pygame.MOUSEBUTTONDOWN:
if event.button==1:
if bts[p].rect.collidepoint(event.pos):
if p==0:
new_prompt=n.send('p1')
else:
new_prompt=n.send('p2')
new_prompt=str(new_prompt)
font = pygame.font.Font(None, 36)
prompt_text = font.render(new_prompt, True, (0, 0, 0))
prompt_rect = prompt_text.get_rect(center=(screen_width // 2, 150))
screen.blit(prompt_text, prompt_rect)
pygame.display.flip()
redraw(screen)
bts[p].draw(screen)
pygame.display.flip()
#checkStat=n.send("Connect")
main()
pygame.quit()
sys.exit()