-
Notifications
You must be signed in to change notification settings - Fork 0
/
game_main.py
executable file
·109 lines (86 loc) · 3.26 KB
/
game_main.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
from game_functions import *
#Initiate
screen_fill_color = g_color_WHITE
mouse_x = 0
mouse_y = 0
#Game variables
game_running = True
player_details_taken = False
host_join_choice_made = False
all_players_have_joined = False
def main():
global game_running
global host_join_choice_made
global player_details_taken
global all_players_have_joined
global mouse_x
global mouse_y
if not host_join_choice_made:
choice = g_get_host_or_join()
host_join_choice_made = True
if not player_details_taken:
player_name = g_get_player_name()
me = Player(player_name)
t = threading.Thread(target=receiving_threaded, args=(me,))
me.type = choice
me.number, me.color = g_get_player_number_and_color(me)
current_number_of_players = me.number
print(f'me.number = {me.number}, me.color = {me.color}')
player_details_taken = True
if current_number_of_players == maximum_players_allowed:
all_players_have_joined = True
while not all_players_have_joined:
print("Checking with Server now ...")
time.sleep(2)
current_number_of_players = g_get_number_of_players_from_game_server(me)
print(f'ch = {choice}, cp = {current_number_of_players}, mp = {maximum_players_allowed}')
if current_number_of_players == maximum_players_allowed:
all_players_have_joined = True
print("Entering game !")
t.start()
#Game settings
pygame.init()
g_SCREEN = pygame.display.set_mode((g_WIDTH, g_HEIGHT), pygame.HWSURFACE | pygame.DOUBLEBUF)
pygame.display.set_caption(g_NAME)
g_clock = pygame.time.Clock()
g_post_coordinates, g_wall_list, g_fonts = g_initialize_parameters(g_SCREEN, g_c_posts_number, g_r_posts_number)
#Game loop
while game_running:
conduit(g_SCREEN, g_wall_list)
# Clock management
g_clock.tick(g_FPS)
# Clear screen
g_SCREEN.fill(screen_fill_color)
# Capture events
for event in pygame.event.get():
if event.type == pygame.QUIT:
game_running = False
print("Caught in event handler")
elif event.type == pygame.MOUSEMOTION:
mouse_x = event.pos[0]
mouse_y = event.pos[1]
elif event.type == pygame.MOUSEBUTTONDOWN:
if all_players_have_joined:
g_make_player_wall(g_SCREEN, g_currently_selected_wall, me)
else:
print("Game yet to start.")
# Draw posts
g_draw_posts(g_SCREEN, g_post_coordinates)
# Draw walls
g_wall_list = g_draw_walls(g_SCREEN, g_wall_list)
# Show wall trace
g_currently_selected_wall = g_show_wall_trace(g_SCREEN, g_wall_list, mouse_x, mouse_y)
# Display texts
g_show_text(g_SCREEN, str(me.number_of_walls) + '_' + str(me.number_of_houses), g_fonts[0], 50, 25, me.color, g_color_WHITE)
# Count houses
g_count_houses(g_SCREEN, g_post_coordinates, g_fonts[1], g_wall_list, me)
# Screen flip
pygame.display.flip()
# Quit game
print("Reached t.join()")
me.network_send("EndGame")
t.join()
print("Reached pygame.quit()")
pygame.quit()
if __name__ == "__main__":
main()