diff --git a/assets.py b/assets.py index 1c9c9f2..1d679ad 100644 --- a/assets.py +++ b/assets.py @@ -5,6 +5,10 @@ event_sound = join("sounds", "event.ogg") disc_drop_1 = join("sounds", "disc_drop_1.wav") disc_drop_2 = join("sounds", "disc_drop_2.wav") -red_coin = load(join("images", "redball90px.png")) -yellow_coin = load(join("images", "yellowball90px.png")) +red_coin = load(join("images", "red.png")) +yellow_coin = load(join("images", "Yellow.png")) +blue_coin = load(join("images", "darkBlue.png")) +gray_coin = load(join("images", "gray.png")) +green_coin = load(join("images", "green.png")) +violet_coin = load(join("images", "Violet.png")) black_coin = load(join("images", "blackball91px.png")) diff --git a/config.py b/config.py index debfff6..15b7a96 100644 --- a/config.py +++ b/config.py @@ -1,6 +1,9 @@ # Colors yellow = (255, 255, 0) red = (255, 0, 0) +green = (0, 255, 0) blue = (0, 0, 255) white = (255, 255, 255) black = (0, 0, 0) +violet = (255, 0, 255) +gray = (211, 211, 211) diff --git a/game.py b/game.py index 5f16d96..c119be0 100644 --- a/game.py +++ b/game.py @@ -3,19 +3,22 @@ import pygame from pygame.locals import KEYDOWN -from config import black, blue, white +from config import black, blue, gray, green, red, violet, white, yellow from connect_game import ConnectGame from events import MouseClickEvent, MouseHoverEvent, bus from game_data import GameData from game_renderer import GameRenderer +c1 = red +c2 = yellow + def quit(): sys.exit() def start(): - data = GameData() + data = GameData(c1, c2) screen = pygame.display.set_mode(data.size) game = ConnectGame(data, GameRenderer(screen, data)) @@ -50,6 +53,84 @@ def start(): game.draw() +flag = 1 + + +def color_change(): + global screen, flag + screen.fill(black) + + running = True + while running: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + quit() + + message_display("CONNECT FOUR!!", white, 350, 150, 75) + message_display("PLAYER 1", c1, 215, 300, 35) + message_display("PLAYER 2", c2, 215, 500, 35) + + button("", 100, 325, 30, 30, red, coin_change, 1) + button("", 150, 325, 30, 30, yellow, coin_change, 1) + button("", 200, 325, 30, 30, green, coin_change, 1) + button("", 250, 325, 30, 30, blue, coin_change, 1) + button("", 300, 325, 30, 30, violet, coin_change, 1) + button("", 350, 325, 30, 30, gray, coin_change, 1) + + button("", 100, 525, 30, 30, red, coin_change, 2) + button("", 150, 525, 30, 30, yellow, coin_change, 2) + button("", 200, 525, 30, 30, green, coin_change, 2) + button("", 250, 525, 30, 30, blue, coin_change, 2) + button("", 300, 525, 30, 30, violet, coin_change, 2) + button("", 350, 525, 30, 30, gray, coin_change, 2) + + button("SAVE", 510, 600, 130, 50, white, save) + button("SAVE", 512, 602, 125, 46, black, save) + pygame.display.update() + + if flag == 0: + flag = 1 + screen.fill(black) + message_display("CONNECT FOUR!!", white, 350, 150, 75) + message_display("HAVE FUN!", (23, 196, 243), 350, 300, 75) + running = False + + +def save(): + global flag + flag = 0 + + +def coin_change(color, player_no): + global c1, c2 + + if player_no == 1: + c1 = color + else: + c2 = color + + +def button(msg, x, y, w, h, color, action=None, player_no=0): + 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, color, (x, y, w, h)) + + if click[0] == 1 and action != None: + if action == coin_change: + action(color, player_no) + else: + action() + else: + pygame.draw.rect(screen, color, (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) + + def text_objects(text, font, color): textSurface = font.render(text, True, color) return textSurface, textSurface.get_rect() @@ -75,25 +156,10 @@ def message_display(text, color, p, q, v): 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) + button("PLAY!", 150, 450, 100, 50, white, start) + button("PLAY", 152, 452, 96, 46, black, start) + button("QUIT", 450, 450, 100, 50, white, quit) + button("QUIT", 452, 452, 96, 46, black, quit) + button("COLOR CHANGE", 210, 600, 230, 50, white, color_change) + button("COLOR CHANGE", 212, 602, 225, 46, black, color_change) pygame.display.update() diff --git a/game_data.py b/game_data.py index a7ae2fc..ad0a5b4 100644 --- a/game_data.py +++ b/game_data.py @@ -1,5 +1,8 @@ from typing import Tuple +from assets import (black_coin, disc_drop_1, disc_drop_2, event_sound, + red_coin, yellow_coin) +from config import black, blue, green, red, violet, white, yellow from game_board import GameBoard @@ -19,14 +22,15 @@ class GameData: last_move_col: [int] game_board: GameBoard - def __init__(self): + def __init__(self, color_player1=red, color_player2=yellow): self.game_over = False self.turn = 0 self.last_move_row = [] self.last_move_col = [] self.game_board = GameBoard() self.action = None - + self.c1 = color_player1 + self.c2 = color_player2 self.sq_size: int = 100 self.width: int = 7 * self.sq_size self.height: int = 7 * self.sq_size diff --git a/game_renderer.py b/game_renderer.py index 465063b..f163ace 100644 --- a/game_renderer.py +++ b/game_renderer.py @@ -7,9 +7,10 @@ from pygame.ftfont import Font from pygame.gfxdraw import aacircle, filled_circle -from assets import (black_coin, disc_drop_1, disc_drop_2, event_sound, - red_coin, yellow_coin) -from config import black, blue, red, white, yellow +from assets import (black_coin, blue_coin, disc_drop_1, disc_drop_2, + event_sound, gray_coin, green_coin, red_coin, violet_coin, + yellow_coin) +from config import black, blue, gray, green, red, violet, white, yellow from events import GameOver, MouseHoverEvent, PieceDropEvent, bus from game_data import GameData @@ -29,6 +30,22 @@ def on_piece_drop(event: PieceDropEvent): mixer.music.play(0) +def coin_color(color): + k = red_coin + if color == green: + k = green_coin + elif color == blue: + k = blue_coin + elif color == violet: + k = violet_coin + elif color == yellow: + k = yellow_coin + elif color == gray: + k = gray_coin + + return k + + class GameRenderer: """ Renders the current game state to the screen and the speakers. @@ -70,21 +87,21 @@ def on_mouse_move(self, event: MouseHoverEvent): int(self.game_data.sq_size) - self.game_data.sq_size + 5, ) - def draw_red_coin(self, x, y): + def draw_coin_p1(self, x, y): """ Draws a red coin. :param x: The x position to draw the coin. :param y: The y position to draw the coin. """ - self.screen.blit(red_coin, (x, y)) + self.screen.blit(coin_color(self.game_data.c1), (x, y)) - def draw_yellow_coin(self, x, y): + def draw_coin_p2(self, x, y): """ Draws a yellow coin. :param x: The x position to draw the coin. :param y: The y position to draw the coin. """ - self.screen.blit(yellow_coin, (x, y)) + self.screen.blit(coin_color(self.game_data.c2), (x, y)) def draw_black_coin(self, x, y): """ @@ -104,9 +121,9 @@ def draw_coin(self, game_data, x, y): :param y: The y position for the coin to be drawn. """ if game_data.turn == 0: - self.screen.blit(red_coin, (x, y)) + self.screen.blit(coin_color(game_data.c1), (x, y)) else: - self.screen.blit(yellow_coin, (x, y)) + self.screen.blit(coin_color(game_data.c2), (x, y)) def draw(self, game_data: GameData): """ @@ -154,9 +171,9 @@ def on_game_over(self, event: GameOver): color = None if event.winner == 1: - color = red + color = self.game_data.c1 if event.winner == 2: - color = yellow + color = self.game_data.c2 if not event.was_tie: self.label = self.myfont.render(f"PLAYER {event.winner} WINS!", 1, color) @@ -205,12 +222,12 @@ def draw_board(self, board): for c in range(board.cols): for r in range(board.rows): if board.board[r][c] == 1: - self.draw_red_coin( + self.draw_coin_p1( int(c * sq_size) + 5, height - int(r * sq_size + sq_size - 5) ) elif board.board[r][c] == 2: - self.draw_yellow_coin( + self.draw_coin_p2( int(c * sq_size) + 5, height - int(r * sq_size + sq_size - 5) ) diff --git a/images/Violet.png b/images/Violet.png new file mode 100644 index 0000000..c58f7f4 Binary files /dev/null and b/images/Violet.png differ diff --git a/images/Yellow.png b/images/Yellow.png new file mode 100644 index 0000000..23c36ed Binary files /dev/null and b/images/Yellow.png differ diff --git a/images/darkBlue.png b/images/darkBlue.png new file mode 100644 index 0000000..373a927 Binary files /dev/null and b/images/darkBlue.png differ diff --git a/images/gray.png b/images/gray.png new file mode 100644 index 0000000..b76d3fd Binary files /dev/null and b/images/gray.png differ diff --git a/images/green.png b/images/green.png new file mode 100644 index 0000000..cdfe9c7 Binary files /dev/null and b/images/green.png differ diff --git a/images/neonBlue.png b/images/neonBlue.png new file mode 100644 index 0000000..3565713 Binary files /dev/null and b/images/neonBlue.png differ diff --git a/images/red.png b/images/red.png new file mode 100644 index 0000000..c89cc0e Binary files /dev/null and b/images/red.png differ