Skip to content

Changed Color of Game #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Binary file added .DS_Store
Binary file not shown.
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/Checkers-_Add_Function.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added GethoBold.ttf
Binary file not shown.
13 changes: 7 additions & 6 deletions Main_Board.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
"""

import pygame
from constants import BLACK, ROWS, RED, SQUARE_SIZE, COLS, WHITE
from constants import BLACK, ROWS, RED, SQUARE_SIZE, COLS, WHITE, CHERRY
from pieces import Piece


class Main_Board:
"""
The Main_Board class is responsible for managing the board and the pieces, and contains functions to draw the board,
Expand Down Expand Up @@ -82,7 +83,7 @@ def create_board(self):
if row < 3:
self.board[row].append(Piece(row, col, WHITE))
elif row > 4:
self.board[row].append(Piece(row, col, RED))
self.board[row].append(Piece(row, col, CHERRY))
else:
self.board[row].append(0)
else:
Expand All @@ -106,7 +107,7 @@ def remove(self, pieces):
for piece in pieces:
self.board[piece.row][piece.col] = 0
if piece != 0:
if piece.color == RED:
if piece.color == CHERRY:
self.red_left -= 1
else:
self.white_left -= 1
Expand All @@ -116,10 +117,10 @@ def winner(self):
The winner function checks if a winner has been found and returns the winner. If no winner has been found, None is returned.
If a user has no pieces left or no moves left, the other user is the winner.
"""
if self.red_left <= 0 or self.no_moves(RED):
if self.red_left <= 0 or self.no_moves(CHERRY):
return WHITE
elif self.white_left <= 0 or self.no_moves(WHITE):
return RED
return CHERRY

return None

Expand All @@ -131,7 +132,7 @@ def get_valid_moves(self, piece):
left = piece.col - 1
right = piece.col + 1
row = piece.row
if piece.color == RED or piece.king:
if piece.color == CHERRY or piece.king:
moves.update(self.move_left(row -1, max(row-3, -1), -1, piece.color, left))
moves.update(self.move_right(row -1, max(row-3, -1), -1, piece.color, right))
if piece.color == WHITE or piece.king:
Expand Down
130 changes: 53 additions & 77 deletions SecondMenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from computer import minimax
from MusicClass import BackgroundMusic
from SharedObjects import background_music
from ThirdMenu import ThirdMenu



Width, Height = 1000, 700
Expand Down Expand Up @@ -40,18 +42,18 @@ class SecondMenu:
The SecondMenu class consists of a String color, which represents the color of the board chosen by the user.
The class also has three functions, start_game_menu, start_game_vs_player, and start_game_vs_computer.
"""

def __init__(self, track):
self.selected_music_track = track
self.background_music = BackgroundMusic([track])

color = RED
def start_game_menu(self):
"""
The start game menu function displays the second menu of the game, which allows the user to choose between playing against another player or against the computer.
"""


global player1_name, player2_name
start_game_screen = pygame.display.set_mode([Width, Height])

Expand Down Expand Up @@ -104,13 +106,13 @@ def start_game_menu(self):

button_text2 = button_font.render("Start Game VS Computer", True, (255, 255, 255)) # Button text and color
button_text_rect2 = button_text2.get_rect(
center=(Width // 2, Height // 3 + button_height + spacing + button_height // 2))
center=(Width // 2, Height // 3 + button_height + spacing + button_height // 2))

# Create button on screen using position and size parameters
pygame.draw.rect(start_game_screen, color, pygame.Rect(position, size))
start_game_screen.blit(button_text2, button_text_rect2)
button_rect_2 = pygame.Rect(position, size)

# Exit Second Menu Button
position = (Width // 2-150, Height // 3 + 135)
size = (300, 50) # width, height
Expand All @@ -127,42 +129,42 @@ def start_game_menu(self):

pygame.display.flip()
mouse = pygame.mouse.get_pos()

while True:
mouse = pygame.mouse.get_pos()
if button_rect_3.collidepoint(mouse):

pygame.draw.rect(start_game_screen, cursor_color, button_rect_3) # Change color when cursor hovered over
start_game_screen.blit(button_text3, button_text_rect3)
pygame.display.update()
elif button_rect_2.collidepoint(mouse):

pygame.draw.rect(start_game_screen, cursor_color, button_rect_2)
start_game_screen.blit(button_text2, button_text_rect2)
pygame.display.update()

elif button_rect.collidepoint(mouse):
pygame.draw.rect(start_game_screen, cursor_color, button_rect)
start_game_screen.blit(button_text1, button_text_rect1)
pygame.display.update()

else:
pygame.display.update()
pygame.draw.rect(start_game_screen, color, button_rect_3) # stay original color if cursor not hovering over
start_game_screen.blit(button_text3, button_text_rect3)

pygame.draw.rect(start_game_screen, color, button_rect_2)
start_game_screen.blit(button_text2, button_text_rect2)

pygame.draw.rect(start_game_screen, color, button_rect)
start_game_screen.blit(button_text1, button_text_rect1)

pygame.display.update()


for event in pygame.event.get():
score_manager.load_scores()

if event.type == pygame.QUIT:
pygame.quit()
return
Expand All @@ -180,13 +182,15 @@ def start_game_menu(self):
elif button_rect_2.collidepoint(event.pos): # Start Game VS Computer button clicked
player1_name.get_player_name()
score_manager.add_user(player1_name.username)
self.start_game_vs_computer(start_game_screen)
score_manager.save_scores()
# Create an instance of ThirdMenu and start the difficulty menu
third_menu = ThirdMenu(self.selected_music_track, self.color,player1_name) # Pass color too
third_menu.start_difficulty_menu() # This will display the difficulty selection menu

return
# score_manager.save_scores() # now inside elif so scores are updated before returning to main

elif event.type == self.background_music.SONG_END:
self.background_music.handle_event(event)

def start_game_vs_player(self, screen):
"""
The start game vs player function starts the game against another player by creating an object of the game class and passing the screen, color, and player names.
Expand All @@ -196,20 +200,16 @@ def start_game_vs_player(self, screen):
game = Game(screen, self.color, player1_name.username, player2_name.username)
global score_manager, user_scores

# Exit Button
button_font = pygame.font.Font(None, 32)
exit_text = button_font.render("Exit Game", True, (255, 255, 255))
exit_button_rect = exit_text.get_rect(center=(Width // 2+350, Height - 100))
pygame.draw.rect(screen, (128, 128, 128), exit_button_rect)
screen.blit(exit_text, exit_button_rect)
pygame.display.flip()
post_duration = 10000 # Display time in milliseconds
post_text = None
post_display_time = 0 # Initialize the time when the tweet is displayed

while run:
clock.tick(60)
if game.winner() != None:
print(game.winner())
run = False
if game.winner() == RED:
if game.winner() == CHERRY:
player1_name.update_win()
score_manager.update_scores(player1_name)
player2_name.update_loss()
Expand All @@ -223,60 +223,36 @@ def start_game_vs_player(self, screen):
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False

#Feature to quit at any point of the game
if event.type ==pygame.MOUSEBUTTONDOWN:
pos = pygame.mouse.get_pos() #if button is clicked
quit_button = game.display_quit()
if quit_button.collidepoint(pos):
run = False

if event.type == pygame.MOUSEBUTTONDOWN:
pos = pygame.mouse.get_pos()
row, col = get_row_col_from_mouse(pos)
game.select(row, col)
reddit_button = game.display_button() # Draw button
if reddit_button.collidepoint(pos): # If Reddit button clicked
print('Fetching Reddit post...')
reddit_post = game.fetch_reddit_post() # Fetch most recent Reddit post
if reddit_post:
post_text = reddit_post.title # Store the post title
post_display_time = pygame.time.get_ticks() + post_duration # Set the display time

else:
row, col = get_row_col_from_mouse(pos)
game.select(row, col)
# Check for background music event
if event.type == background_music.SONG_END:
background_music.handle_event(event)
background_music.handle_event(event)

game.update()
# Display the fetched Reddit post
if post_text and pygame.time.get_ticks() < post_display_time:
game.display_text_box() # Call the function to display the post
else:
post_text = None # Clear the post when time is up

def start_game_vs_computer(self, screen):
"""
The start game vs computer function starts the game against the computer by creating an object of the game class and passing the screen, color, and player name.
"""
run = True
clock = pygame.time.Clock()
game = Game(screen, self.color, player1_name.username, "Computer")
global score_manager, user_scores

# Exit Button
button_font = pygame.font.Font(None, 32)
exit_text = button_font.render("Exit Game", True, (255, 255, 255))
exit_button_rect = exit_text.get_rect(center=(Width // 2+350, Height - 100))
pygame.draw.rect(screen, (128, 128, 128), exit_button_rect)
screen.blit(exit_text, exit_button_rect)
pygame.display.flip()

while run:
clock.tick(60)
if game.turn == WHITE:
value, new_board = minimax(game.get_board(), 4, WHITE, game)
game.ai_move(new_board)

if game.winner() != None:
print(game.winner())
run = False
if game.winner() == RED:
player1_name.update_win()
score_manager.update_scores(player1_name)
else:
player1_name.update_loss()
score_manager.update_scores(player1_name)

for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False

if event.type == pygame.MOUSEBUTTONDOWN:
pos = pygame.mouse.get_pos()
row, col = get_row_col_from_mouse(pos)
game.select(row, col)

if event.type == background_music.SONG_END:
background_music.handle_event(event)
pygame.display.flip() # Update the display after drawing everything

game.update()
Loading