Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 10 additions & 19 deletions coinflip.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import pygame
import pygame # Install required libs
import sys
import pygame_gui
import shared
import random
import time

# Initialize Pygame
# Set up pygame
pygame.init()
screen_width, screen_height = 600, 500
screen = pygame.display.set_mode((screen_width, screen_height))
Expand All @@ -14,21 +14,12 @@
clock = pygame.time.Clock()
ui_manager = pygame_gui.UIManager((screen_width, screen_height))

# Colours
white = (255, 255, 255)
black = (0, 0, 0)
red = (255, 0, 0)

# Fonts
try:
font = pygame.font.Font("fonts/PublicSans-Bold.ttf", 24)
except:
font = pygame.font.SysFont("arial", 24)
print("⚠️ Font not found, using system font.")
font = pygame.font.Font("fonts/PublicSans-Bold.ttf", 24)

# Team colours (set elsewhere)
home_team_colour = pygame.Color(0, 0, 0)
away_team_colour = pygame.Color(0, 0, 0)
home_team_colour = shared.home_team_colour
away_team_colour = shared.away_team_colour

# Text rendering helper
def draw_text(text, font, colour, surface, x, y):
Expand All @@ -47,7 +38,7 @@ def __init__(self, text, x, y, w, h, colour, action=None):

def draw(self, screen):
pygame.draw.rect(screen, self.colour, self.rect)
draw_text(self.text, font, white, screen, self.rect.x + 10, self.rect.y + 10)
draw_text(self.text, font, pygame.Color("azure"), screen, self.rect.x + 10, self.rect.y + 10)

def is_clicked(self, pos):
return self.rect.collidepoint(pos)
Expand All @@ -65,14 +56,14 @@ def cointossoutcome():
if coinresult == "Heads":
shared.first_batting_team = shared.home_team
shared.second_batting_team = shared.away_team
draw_text(f"{shared.home_team} won the toss", font, red, screen, 50, 100)
draw_text(f"{shared.home_team} won the toss", font, pygame.Color("orangered1"), screen, 50, 100)
pygame.display.flip()
time.sleep(1)

else:
shared.first_batting_team = shared.away_team
shared.second_batting_team = shared.home_team
draw_text(f"{shared.away_team} won the toss", font, red, screen, 50, 100)
draw_text(f"{shared.away_team} won the toss", font, pygame.Color("orangered1"), screen, 50, 100)
pygame.display.flip()
time.sleep(1)

Expand All @@ -98,8 +89,8 @@ def cointossoutcome():

ui_manager.update(time_delta)

screen.fill(black)
draw_text("Away team calls the toss", font, red, screen, 50, 50)
screen.fill(pygame.Color("gray1"))
draw_text("Away team calls the toss", font, pygame.Color("orangered1"), screen, 50, 50)
heads.draw(screen)
tails.draw(screen)
ui_manager.draw_ui(screen)
Expand Down