Skip to content
1 change: 1 addition & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
blue = (0, 0, 255)
white = (255, 255, 255)
black = (0, 0, 0)
green = (0,255,0)
1 change: 0 additions & 1 deletion connect_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
57 changes: 25 additions & 32 deletions game.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import sys

import pygame
from pygame.locals import KEYDOWN

Expand All @@ -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))
Expand Down Expand Up @@ -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
Expand All @@ -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()