diff --git a/config.py b/config.py index debfff6..159ebbf 100644 --- a/config.py +++ b/config.py @@ -4,3 +4,4 @@ blue = (0, 0, 255) white = (255, 255, 255) black = (0, 0, 0) +green = (0,255,0) \ No newline at end of file diff --git a/connect_game.py b/connect_game.py index c5fe4a9..832bee7 100644 --- a/connect_game.py +++ b/connect_game.py @@ -102,7 +102,6 @@ def update(self): if self.game_data.game_over: print(os.getpid()) pygame.time.wait(1000) - os.system("game.py") def draw(self): """ diff --git a/game.py b/game.py index 5f16d96..0726eb7 100644 --- a/game.py +++ b/game.py @@ -1,5 +1,3 @@ -import sys - import pygame from pygame.locals import KEYDOWN @@ -8,13 +6,14 @@ from events import MouseClickEvent, MouseHoverEvent, bus from game_data import GameData from game_renderer import GameRenderer +from config import black, blue, red, white, yellow, green - -def quit(): - sys.exit() +def quitgame(): + pygame.quit() + quit() -def start(): +def startgame(): data = GameData() screen = pygame.display.set_mode(data.size) game = ConnectGame(data, GameRenderer(screen, data)) @@ -56,16 +55,29 @@ def text_objects(text, font, color): def message_display(text, color, p, q, v): - largeText = pygame.font.SysFont("monospace", v) - TextSurf, TextRect = text_objects(text, largeText, color) + Text = pygame.font.SysFont("monospace", v) + TextSurf, TextRect = text_objects(text, Text, color) TextRect.center = (p, q) screen.blit(TextSurf, TextRect) +def button(msg, x, y, w, h, ic, ac, action=None): + mouse = pygame.mouse.get_pos() + click = pygame.mouse.get_pressed() + + if x + w > mouse[0] > x and y + h > mouse[1] > y: + pygame.draw.rect(screen, ac, (x, y, w, h)) + if click[0] == 1 and action != None: + action() + else: + pygame.draw.rect(screen, ic, (x, y, w, h)) + message_display(msg, black, (x + (w / 2)), (y + (h / 2)), 30) + + pygame.init() screen = pygame.display.set_mode(GameData().size) pygame.display.set_caption("Connect Four | Mayank Singh") -message_display("CONNECT FOUR!!", white, 350, 150, 75) +message_display("CONNECT FOUR", yellow, 350, 150, 75) message_display("HAVE FUN!", (23, 196, 243), 350, 300, 75) running = True @@ -74,26 +86,7 @@ def message_display(text, color, p, q, v): for event in pygame.event.get(): if event.type == pygame.QUIT: running = False - - def button(msg, x, y, w, h, ic, ac, action=None): - mouse = pygame.mouse.get_pos() - click = pygame.mouse.get_pressed() - - if x + w > mouse[0] > x and y + h > mouse[1] > y: - pygame.draw.rect(screen, ac, (x, y, w, h)) - - if click[0] == 1 and action != None: - action() - else: - pygame.draw.rect(screen, ic, (x, y, w, h)) - - smallText = pygame.font.SysFont("monospace", 30) - textSurf, textRect = text_objects(msg, smallText, white) - textRect.center = ((x + (w / 2)), (y + (h / 2))) - screen.blit(textSurf, textRect) - - button("PLAY!", 150, 450, 100, 50, white, white, start) - button("PLAY", 152, 452, 96, 46, black, black, start) - button("QUIT", 450, 450, 100, 50, white, white, quit) - button("QUIT", 452, 452, 96, 46, black, black, quit) - pygame.display.update() + + button("PLAY", 125, 450, 150, 60, white, green, startgame) + button("QUIT", 425, 450, 150, 60, white, red, quitgame) + pygame.display.update() \ No newline at end of file