Sure, I can help you with that. Here's an example code for the game you described using Pygame:
import pygame
import random
# Game resolution
screen_width = 800
screen_height = 600
# Colors
white = (255, 255, 255)
black = (0, 0, 0)
red = (255, 0, 0)
green = (0, 255, 0)
# Initialize Pygame
pygame.init()
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption("Dice Game")
clock = pygame.time.Clock()
def draw_text(text, font, color, x, y):
text_surface = font.render(text, True, color)
text_rect = text_surface.get_rect()
text_rect.center = (x, y)
screen.blit(text_surface, text_rect)
def main_menu():
running = True
player1_score = 0
player1_turn = True
player2_score = 0
player2_turn = False
dice_throw = None
circle_radius = 20
circle_gap = 30
circle_number = 1
max_circles = 10
while running:
screen.fill(white)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
mouse_x, mouse_y = pygame.mouse.get_pos()
if player1_turn:
if dice_throw is None:
if 300 < mouse_x < 500 and 200 < mouse_y < 300:
dice_throw = random.randint(1, 6)
elif 300 < mouse_x < 500 and 400 < mouse_y < 500:
player1_score += dice_throw
player1_turn = False
player2_turn = True
dice_throw = None
elif player2_turn:
if dice_throw is None:
if 300 < mouse_x < 500 and 200 < mouse_y < 300:
dice_throw = random.randint(1, 6)
elif 300 < mouse_x < 500 and 500 < mouse_y < 600:
player2_score += dice_throw
player1_turn = True
player2_turn = False
dice_throw = None
if dice_throw is None:
draw_text("Player 1's Turn", pygame.font.Font(None, 36), black, screen_width // 2, 100)
if player1_turn:
pygame.draw.rect(screen, green, (300, 200, 200, 100))
draw_text("Throw Dice", pygame.font.Font(None, 36), black, screen_width // 2, 250)
else:
draw_text("Dice: {}".format(dice_throw), pygame.font.Font(None, 36), black, screen_width // 2, 100)
if player1_turn:
pygame.draw.rect(screen, red, (300, 400, 200, 100))
draw_text("Go!", pygame.font.Font(None, 36), black, screen_width // 2, 450)
elif player2_turn:
pygame.draw.rect(screen, red, (300, 500, 200, 100))
draw_text("Go!", pygame.font.Font(None, 36), black, screen_width // 2, 550)
draw_text("Player 1 Score: {}".format(player1_score), pygame.font.Font(None, 24), black, 100, 100)
draw_text("Player 2 Score: {}".format(player2_score), pygame.font.Font(None, 24), black, 100, 150)
for i in range(circle_number):
pygame.draw.circle(screen, black, (circle_radius + i * circle_gap, screen_height - circle_radius), circle_radius)
pygame.display.flip()
clock.tick(60)
pygame.quit()
if __name__ == "__main__":
main_menu()
This code sets up the basic structure of the dice game you described. However, there are some parts that need further implementation, like the game ending condition and the ability to pause the game and change the number of circles. You can modify and extend the code according to your needs.