-
Notifications
You must be signed in to change notification settings - Fork 3
/
Main_Menu.py
95 lines (84 loc) · 3.88 KB
/
Main_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
"""
Copyright 2020, Sidhant Agarwal, [email protected], All rights reserved.
Borrowed from https://github.com/sidhantagar/ConnectX under the MIT license.
"""
import os
import time
import pygame
from new_game import*
from draw_text import *
from draw_buttons import *
#Initial values
player_number = 1
def mainMenu(font, screen):
if font == None:
font = pygame.font.SysFont("comicsans",30)
if screen == None:
screen = pygame.display.set_mode((400,500),0,0)
image = pygame.image.load('Group_1.jpg')
dummy = pygame.Surface((1280,1600))
background = pygame.Surface((400,500))
dummy.blit(image,(0,0))
pygame.transform.scale(dummy,(400,500),background)
from edit_configuration import editConfig
#Creating New Game Button
screen.blit(background,(0,0))
draw_bordered_rounded_rect (screen, (100,200,200,70),(0,0,255),(255,255,0),10,5)
screen = draw_text (font, screen, "New Game", (255,255,255), 200, 235)
#Creating Customize Board Button
draw_bordered_rounded_rect (screen, (100,300,200,70),(0,0,255),(255,255,0),10,5)
screen = draw_text (font, screen, "Customize Board", (255,255,255), 200, 335)
pygame.display.update()
#Reading For Button Click
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.display.quit()
os._exit(1)
if event.type == pygame.MOUSEBUTTONDOWN:
(mouse_pos_x, mouse_pos_y) = event.pos
#Checking for Button Click
if mouse_pos_x > 99 and mouse_pos_x < 301 and mouse_pos_y > 199 and mouse_pos_y < 271:
ret = newGameMenu(screen,font)
if ret== 0:
return
elif mouse_pos_x > 99 and mouse_pos_x <301 and mouse_pos_y > 299 and mouse_pos_y <371:
editConfig(screen, font, player_number)
def newGameMenu(screen,font):
draw_bordered_rounded_rect (screen, (70,145,260,280),(0,0,255),(255,255,0),10,5)
draw_bordered_rounded_rect (screen, (310,130,35,35),(0,0,255),(255,255,0),6,5)
pygame.draw.line(screen,(255,0,0),(322,142),(333,153),3)
pygame.draw.line(screen,(255,0,0),(333,142),(322,153),3)
draw_bordered_rounded_rect (screen, (100,180,200,60),(0,0,255),(255,255,0),10,5)
screen = draw_text(font, screen, "Player vs AI", (255,255,255), 200, 210)
draw_bordered_rounded_rect (screen, (100,255,200,60),(0,0,255),(255,255,0),10,5)
screen = draw_text(font, screen, "Player vs Player", (255,255,255), 200, 285)
draw_bordered_rounded_rect (screen, (100,330,200,60),(0,0,255),(255,255,0),10,5)
screen = draw_text (font, screen, "AI vs AI", (255,255,255), 200, 360)
pygame.display.update()
ret = 1
#Reading For Button Click
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.display.quit()
os._exit(1)
if event.type == pygame.MOUSEBUTTONDOWN:
(mouse_pos_x, mouse_pos_y) = event.pos
#Checking for Button Click
if mouse_pos_x > 99 and mouse_pos_x < 301 and mouse_pos_y > 179 and mouse_pos_y < 241:
ret = newGame(1,1)
elif mouse_pos_x > 99 and mouse_pos_x <301 and mouse_pos_y > 254 and mouse_pos_y <316:
ret = newGame(1,2)
elif mouse_pos_x > 99 and mouse_pos_x <301 and mouse_pos_y > 339 and mouse_pos_y < 391:
ret = newGame(1,3)
elif mouse_pos_x > 309 and mouse_pos_x < 346 and mouse_pos_y > 129 and mouse_pos_y < 166:
mainMenu(font, screen)
if ret == 0:
return 0
if __name__ == "__main__":
pygame.init()
pygame.font.init()
font = pygame.font.SysFont('comicsans',30)
screen = pygame.display.set_mode((400,500),0,0)
mainMenu(font,screen)