Untitled
unknown
plain_text
a year ago
32 kB
1
Indexable
Never
import random import pygame pygame.init() WIDTH = 800 HEIGHT = 1010 screen = pygame.display.set_mode([WIDTH, HEIGHT]) pygame.display.set_caption('Yahtzee!') timer = pygame.time.Clock() fps = 60 font = pygame.font.Font('freesansbold.ttf', 18) roll = False numbers = [7, 9, 11, 13, 17, 20] current_player = 1 # Start with Player 1 (0-based index) clicked = False draw_clicked = 30 count = 110 player_scores = {1: [0] * 21, 2: [0] * 21} player_choices = {1: [False] * 21, 2: [False] * 21} player_selected = {1: [False] * 6, 2: [False] * 6} player_rolls_left = {1: 3, 2: 3} possible = [False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False] done = [False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False] totals = [0, 0, 0, 0, 0, 0, 0] something_selected = False bonus_time = False game_over = False high_score = 0 score = 0 restart = '' class Choice: def __init__(self, x_pos, y_pos, text, selected, possibles, dones, my_score, player): if player == 1: self.x_pos1 = x_pos self.y_pos1 = y_pos self.text1 = text self.selected1 = selected self.possible1 = possibles self.done1 = dones self.score1 = my_score self.player1 = player if player == 2: self.x_pos2 = x_pos self.y_pos2 = y_pos self.text2 = text self.selected2 = selected self.possible2 = possibles self.done2 = dones self.score2 = my_score self.player2 = player def draw(self): pygame.draw.line(screen, (25, 0, 0), (self.x_pos, self.y_pos + 31), (self.x_pos + 295, self.y_pos + 31), 2) name_text = '' if not self.done: if self.possible: name_text = font.render(self.text, True, (34, 140, 34)) elif not self.possible: name_text = font.render(self.text, True, (255, 0, 0)) else: name_text = font.render(self.text, True, (0, 0, 0)) if self.selected: pygame.draw.rect(screen, (255, 0, 255), [self.x_pos, self.y_pos + 2, 155, 30]) screen.blit(name_text, (self.x_pos + 5, self.y_pos + 10)) score_text = font.render(str(self.score), True, (0, 0, 255)) screen.blit(score_text, (self.x_pos + 165, self.y_pos + 10)) screen.blit(score_text, (self.x_pos + 235, self.y_pos + 10)) class Dice: def __init__(self, x_pos, y_pos, num, key): self.x_pos = x_pos self.y_pos = y_pos self.number = num global player_selected self.key = key self.active = player_selected[current_player][self.key] self.die = '' def draw(self): self.die = pygame.draw.rect(screen, (255, 255, 255), [self.x_pos, self.y_pos, 100, 100], 0, 5) if self.number == 1: pygame.draw.circle(screen, (0, 0, 0), (self.x_pos + 50, self.y_pos + 50), 10) if self.number == 2: pygame.draw.circle(screen, (0, 0, 0), (self.x_pos + 20, self.y_pos + 20), 10) pygame.draw.circle(screen, (0, 0, 0), (self.x_pos + 80, self.y_pos + 80), 10) if self.number == 3: pygame.draw.circle(screen, (0, 0, 0), (self.x_pos + 50, self.y_pos + 50), 10) pygame.draw.circle(screen, (0, 0, 0), (self.x_pos + 20, self.y_pos + 20), 10) pygame.draw.circle(screen, (0, 0, 0), (self.x_pos + 80, self.y_pos + 80), 10) if self.number == 4: pygame.draw.circle(screen, (0, 0, 0), (self.x_pos + 20, self.y_pos + 20), 10) pygame.draw.circle(screen, (0, 0, 0), (self.x_pos + 80, self.y_pos + 80), 10) pygame.draw.circle(screen, (0, 0, 0), (self.x_pos + 20, self.y_pos + 80), 10) pygame.draw.circle(screen, (0, 0, 0), (self.x_pos + 80, self.y_pos + 20), 10) if self.number == 5: pygame.draw.circle(screen, (0, 0, 0), (self.x_pos + 50, self.y_pos + 50), 10) pygame.draw.circle(screen, (0, 0, 0), (self.x_pos + 20, self.y_pos + 20), 10) pygame.draw.circle(screen, (0, 0, 0), (self.x_pos + 80, self.y_pos + 80), 10) pygame.draw.circle(screen, (0, 0, 0), (self.x_pos + 20, self.y_pos + 80), 10) pygame.draw.circle(screen, (0, 0, 0), (self.x_pos + 80, self.y_pos + 20), 10) if self.number == 6: pygame.draw.circle(screen, (0, 0, 0), (self.x_pos + 20, self.y_pos + 50), 10) pygame.draw.circle(screen, (0, 0, 0), (self.x_pos + 80, self.y_pos + 50), 10) pygame.draw.circle(screen, (0, 0, 0), (self.x_pos + 20, self.y_pos + 20), 10) pygame.draw.circle(screen, (0, 0, 0), (self.x_pos + 80, self.y_pos + 80), 10) pygame.draw.circle(screen, (0, 0, 0), (self.x_pos + 20, self.y_pos + 80), 10) pygame.draw.circle(screen, (0, 0, 0), (self.x_pos + 80, self.y_pos + 20), 10) if self.active: pygame.draw.rect(screen, (255, 0, 0), [self.x_pos, self.y_pos, 100, 100], 4, 5) def check_click(self, coordinates): if self.die.collidepoint(coordinates): if player_selected[current_player][self.key]: player_selected[current_player][self.key] = False elif not player_selected[current_player][self.key]: player_selected[current_player][self.key] = True def restart_function(): global roll global numbers global player_selected global clicked global player_rolls_left global player_scores global player_choices global done global possible global totals global something_selected global score roll = False numbers = [7, 9, 11, 13, 17, 20] clicked = False player_scores = {1: [0] * 21, 2: [0] * 21} player_choices = {1: [False] * 21, 2: [False] * 21} player_selected = {1: [False] * 6, 2: [False] * 6} player_rolls_left = {1: 3, 2: 3} done = [False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False] possible = [False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False] totals = [0, 0, 0, 0, 0, 0, 0] something_selected = False score = 0 def make_choice(num, my_list, done_list): for index in range(len(my_list)): my_list[index] = False if not done_list[num]: my_list[num] = True return my_list def draw_stuff(): global game_over global game_score_player2 global game_score_player1 roll_text = font.render('Roll', True, (255, 255, 255)) screen.blit(roll_text, (130, 165)) accept_text = font.render('Accept Turn', True, (255, 255, 255)) screen.blit(accept_text, (390, 165)) turns_text = font.render(f'Rolls Player {str(current_player)}: ' + str(player_rolls_left[current_player]), True, (255, 255, 255)) screen.blit(turns_text, (15, 15)) but_text = font.render('Click a Die to Keep It Or Release It', True, (255, 255, 255)) screen.blit(but_text, (280, 15)) pygame.draw.rect(screen, (255, 0, 0), [0, 200, 295, HEIGHT - 200]) pygame.draw.line(screen, (0, 0, 0), (0, 40), (WIDTH, 40), 3) pygame.draw.line(screen, (0, 0, 0), (0, 200), (WIDTH, 200), 3) pygame.draw.line(screen, (0, 0, 0), (800, 0), (800, 200), 3) pygame.draw.line(screen, (0, 0, 0), (250, 0), (250, 40), 3) pygame.draw.line(screen, (0, 0, 0), (155, 200), (155, HEIGHT), 3) pygame.draw.line(screen, (0, 0, 0), (225, 200), (225, HEIGHT), 3) pygame.draw.line(screen, (0, 0, 0), (295, 200), (295, HEIGHT), 3) if game_over: over_text = font.render('Game Over! Restart to Play Again', True, (255, 255, 255)) screen.blit(over_text, (280, 280)) score_text = font.render('Score: ' + str(game_score_player1), True, (255, 255, 255)) screen.blit(score_text, (340, 340)) high_score_text = font.render('High Score: ' + str(high_score), True, (255, 255, 255)) screen.blit(high_score_text, (340, 370)) def draw_dice(): die1.draw() die2.draw() die3.draw() die4.draw() die5.draw() die6.draw() def draw_options(): ones_player1.draw() twos_player1.draw() threes_player1.draw() fours_player1.draw() fives_player1.draw() sixes_player1.draw() pair_player1.draw() two_pairs_player1.draw() three_pairs_player1.draw() three_kind_player1.draw() four_kind_player1.draw() five_kind_player1.draw() small_straight_player1.draw() large_straight_player1.draw() full_straight_player1.draw() small_house_player1.draw() full_house_player1.draw() tower_player1.draw() yahtzee_player1.draw() chance_player1.draw() lower_total1_player1.draw() lower_bonus_player1.draw() lower_total2_player1.draw() lower_total_player1.draw() upper_total_player1.draw() grand_total_player1.draw() bonus_player1.draw() ones_player2.draw() twos_player2.draw() threes_player2.draw() fours_player2.draw() fives_player2.draw() sixes_player2.draw() pair_player2.draw() two_pairs_player2.draw() three_pairs_player2.draw() three_kind_player2.draw() four_kind_player2.draw() five_kind_player2.draw() small_straight_player2.draw() large_straight_player2.draw() full_straight_player2.draw() small_house_player2.draw() full_house_player2.draw() tower_player2.draw() yahtzee_player2.draw() chance_player2.draw() lower_total1_player2.draw() lower_bonus_player2.draw() lower_total2_player2.draw() lower_total_player2.draw() upper_total_player2.draw() grand_total_player2.draw() bonus_player2.draw() def check_possibilities(pos_list, nums): pos_list[0] = True pos_list[1] = True pos_list[2] = True pos_list[3] = True pos_list[4] = True pos_list[5] = True pos_list[12] = True max_count = 0 for index in range(1, 7): if nums.count(index + 1) > max_count: max_count = nums.count(index + 1) lowest = 10 highest = 0 pair1 = 0 pair2 = 0 pair3 = 0 y = 0 z = 0 print(lowest, highest) for index in range(1, len(nums)): if nums[index] < lowest: lowest = nums[index] if nums[index] > highest: highest = nums[index] for index in range(1, len(nums) + 1): if nums.count(index) >= 2 and pair1 == 0 and pair2 == 0 and pair3 == 0: pair1 = index z = nums.count(index) #for index in range(len(number_list)): if nums.count(index) >= 2 and pair2 == 0 and pair1 != 0 and index != pair1 and pair3 == 0: pair2 = index y = nums.count(index) #for index in range(len(number_list)): if nums.count(index) == 2 and pair3 == 0 and pair1 != 0 and pair2 != 0 and index != pair1 and index != pair2: pair3 = index print(pair1, pair2, pair3) if max_count >= 2: pos_list[19] = True if max_count >= 3: pos_list[6] = True if max_count >= 4: pos_list[7] = True if max_count >= 5: pos_list[13] = True if max_count >= 6: pos_list[11] = True if pair1 > 0 and pair2 > 0 and pair3 == 0: pos_list[15] = True pos_list[19] = True if pair1 > 0 and pair2 > 0 and pair3 > 0: pos_list[16] = True pos_list[15] = True pos_list[19] = True #else: # pos_list[16] = False # pos_list[15] = False # pos_list[19] = False if pair1 != 0 and pair2 != 0 and pair3 == 0 and z >= 3 and y >= 2: pos_list[20] = True pos_list[19] = True if pair1 != 0 and pair2 != 0 and pair3 == 0 and z >= 2 and y >= 3: pos_list[20] = True pos_list[19] = True else: pos_list[20] = False pos_list[19] = False if max_count < 3: pos_list[6] = False pos_list[7] = False pos_list[8] = False pos_list[10] = False pos_list[9] = False pos_list[11] = False pos_list[13] = False pos_list[19] = True elif max_count == 3: pos_list[7] = False pos_list[8] = False pos_list[10] = False pos_list[9] = False pos_list[11] = False pos_list[13] = False pos_list[6] = True pos_list[19] = True checker = False if nums.count(lowest) == 3 and nums.count(highest) == 3: pos_list[8] = True pos_list[19] = True pos_list[20] = True pos_list[6] = True checker = True if not checker: pos_list[8] = False elif max_count == 4: pos_list[8] = False pos_list[9] = False pos_list[10] = False pos_list[11] = False pos_list[13] = False pos_list[6] = True if y >= 2 and z >= 3: pos_list[14] = False pos_list[20] = True print(nums.count(lowest)) if y == 4 and z == 2 or y == 2 and z == 4: pos_list[14] = True lowest = 10 highest = 0 for index in range(len(nums)): if nums[index] < lowest: lowest = nums[index] if nums[index] > highest: highest = nums[index] if 1 in nums and 2 in nums and 3 in nums and 4 in nums and 5 in nums and 6 in nums: pos_list[10] = True else: pos_list[10] = False if 1 in nums and 2 in nums and 3 in nums and 4 in nums and 5 in nums: pos_list[9] = True else: pos_list[9] = False if 6 in nums and 5 in nums and 4 in nums and 3 in nums and 2 in nums: pos_list[18] = True else: pos_list[18] = False if max_count < 2: pos_list[19] = False return pos_list def check_scores(select_list, number_list, possible_list, points): lowest = 10 highest = 0 max_count = 0 x = 0 tow = False tower = False pair1 = 0 pair2 = 0 pair3 = 0 y = 0 z = 0 for index in range(1, len(number_list) + 1): if number_list.count(index) >= 2 and pair1 == 0 and pair2 == 0 and pair3 == 0: pair1 = index y = number_list.count(index) #for index in range(len(number_list)): if number_list.count(index) >= 2 and pair2 == 0 and pair1 != 0 and index != pair1 and pair3 == 0: pair2 = index z = number_list.count(index) #for index in range(len(number_list)): if number_list.count(index) >= 2 and pair3 == 0 and pair1 != 0 and pair2 != 0 and index != pair1 and index != pair2: pair3 = index print(number_list.count(index), index) print(pair1, pair2, pair3) for index in range(len(number_list)): if number_list[index] < lowest: lowest = number_list[index] if number_list[index] > highest: highest = number_list[index] for index in range(len(number_list)): if number_list.count(index) >= 3: max_count = number_list.count(index) x = index print(max_count, x) if number_list.count(lowest) == 2 or number_list.count(lowest) == 4: tower = False print(number_list.count(lowest)) if number_list.count(highest) == 4 or number_list.count(highest) == 2: tower = True print(number_list.count(highest)) print(lowest, highest) active = 0 for index in range(len(select_list)): if select_list[index]: active = index if active == 0: points = number_list.count(1) elif active == 1: points = number_list.count(2) * 2 elif active == 2: points = number_list.count(3) * 3 elif active == 3: points = number_list.count(4) * 4 elif active == 4: points = number_list.count(5) * 5 elif active == 5: points = number_list.count(6) * 6 elif active == 6: if possible_list[6] and max_count >= 3: points = 3 * max(pair1, pair2, pair3) else: points = 0 elif active == 7: if possible_list[7] and max_count >= 4: points = 4 * x else: points = 0 elif active == 13: if possible_list[active] and number_list.count(lowest) == 5: points = sum(number_list) - highest elif possible_list[active] and number_list.count(highest) == 5: points = sum(number_list) - lowest else: points = 0 elif active == 8: if possible_list[active]: points = sum(number_list) else: points = 0 elif active == 9: if possible_list[active]: points = 15 else: points = 0 elif active == 18: if possible_list[active]: points = 20 else: points = 0 elif active == 10: if possible_list[active]: points = 21 else: points = 0 elif active == 11: if possible_list[active]: points = 100 else: points = 0 elif active == 12: points = sum(number_list) elif active == 14: if possible_list[active]: points = sum(number_list) else: points = 0 elif active == 19: if possible_list[active] and pair1 > 0: points = 2 * max(pair1, pair2, pair3) else: points = 0 elif active == 15: if possible_list[active] and pair1 > 0 and pair2 > 0: points = 2 * (pair1 + pair2) elif pair3 > 0: points = 2 * (pair2 + pair3) else: points = 0 elif active == 16: if possible_list[active] and pair1 > 0 and pair2 > 0 and pair3 > 0: points = 2 * (pair1 + pair2 + pair3) else: points = 0 elif active == 20: if possible_list[active] and pair1 > 0 and pair2 > 0 and pair3 == 0 and y == 2 and z == 3: points = (3 * pair2) + (2 * pair1) elif possible_list[active] and pair1 > 0 and pair2 > 0 and pair3 == 0 and y == 3 and z == 2: points = (2 * pair2) + (3 * pair1) else: points = 0 return points def check_totals(totals_list, scores_list, my_bonus): totals_list[0] = scores_list[0] + scores_list[1] + scores_list[2] + scores_list[3] + scores_list[4] + scores_list[5] if totals_list[0] >= 75: totals_list[1] = 50 else: totals_list[1] = 0 totals_list[2] = totals_list[0] + totals_list[1] totals_list[4] = scores_list[6] + scores_list[7] + scores_list[8] + scores_list[9] + scores_list[10] + \ scores_list[11] + scores_list[12] + scores_list[13] + scores_list[14] + scores_list[15] + scores_list[16] + scores_list[20] + scores_list[18] + scores_list[19] totals_list[5] = totals_list[2] totals_list[6] = totals_list[4] + totals_list[5] if my_bonus: totals_list[3] += 100 my_bonus = False return totals_list, my_bonus running = True while running: timer.tick(fps) screen.fill((128, 128, 128)) button1 = pygame.draw.rect(screen, (0, 89, 0), [10, 160, 280, 30]) button2 = pygame.draw.rect(screen, (0, 255, 0), [310, 160, 280, 30]) if game_over: restart = pygame.draw.rect(screen, (0, 0, 0), [277, 272, 300, 30]) die1 = Dice(10, 50, numbers[0], 0) die2 = Dice(130, 50, numbers[1], 1) die3 = Dice(250, 50, numbers[2], 2) die4 = Dice(370, 50, numbers[3], 3) die5 = Dice(490, 50, numbers[4], 4) die6 = Dice(610, 50, numbers[5], 5) print(numbers) ones_player1 = Choice(0, 200, '1s', player_choices[current_player][0], possible[0], done[0], player_scores[1][0], current_player) twos_player1 = Choice(0, 230, '2s', player_choices[1][1], possible[1], done[1], player_scores[1][1], current_player) threes_player1 = Choice(0, 260, '3s', player_choices[1][2], possible[2], done[2], player_scores[1][2], current_player) fours_player1 = Choice(0, 290, '4s', player_choices[1][3], possible[3], done[3], player_scores[1][3], current_player) fives_player1 = Choice(0, 320, '5s', player_choices[1][4], possible[4], done[4], player_scores[1][4], current_player) sixes_player1 = Choice(0, 350, '6s', player_choices[1][5], possible[5], done[5], player_scores[1][5], current_player) lower_total1_player1 = Choice(0, 380, 'Upper Score', False, False, True, totals[0], current_player) lower_bonus_player1 = Choice(0, 410, 'Bonus if >= 75', False, False, True, totals[1], current_player) lower_total2_player1 = Choice(0, 440, 'Upper Total', False, False, True, totals[2], current_player) pair_player1 = Choice(0, 470, 'Pair', player_choices[1][19], possible[19], done[19], player_scores[1][19], current_player) two_pairs_player1 = Choice(0, 500, '2 pairs', player_choices[1][15], possible[15], done[15], player_scores[1][15], current_player) three_pairs_player1 = Choice(0, 530, '3 pairs', player_choices[1][16], possible[16], done[16], player_scores[1][16], current_player) three_kind_player1 = Choice(0, 560, '3 of Kind', player_choices[1][6], possible[6], done[6], player_scores[1][6], current_player) four_kind_player1 = Choice(0, 590, '4 of Kind', player_choices[1][7], possible[7], done[7], player_scores[1][7], current_player) five_kind_player1 = Choice(0, 620, '5 of Kind', player_choices[1][13], possible[13], done[13], player_scores[1][13], current_player) small_straight_player1 = Choice(0, 650, 'Sm. Straight', player_choices[1][9], possible[9], done[9], player_scores[1][9], current_player) large_straight_player1 = Choice(0, 680, 'Lg. Straight', player_choices[1][18], possible[18], done[18], player_scores[1][18], current_player) full_straight_player1 = Choice(0, 710, 'Full Straight', player_choices[1][10], possible[10], done[10], player_scores[1][10], current_player) small_house_player1 = Choice(0, 740, 'Small House', player_choices[1][20], possible[20], done[20], player_scores[1][20], current_player) full_house_player1 = Choice(0, 770, 'Full House', player_choices[1][8], possible[8], done[8], player_scores[1][8], current_player) tower_player1 = Choice(0, 800, 'Tower', player_choices[1][14], possible[14], done[14], player_scores[1][14], current_player) yahtzee_player1 = Choice(0, 830, 'YAHTZEE', player_choices[1][11], possible[11], done[11], player_scores[1][11], current_player) chance_player1 = Choice(0, 860, 'Chance', player_choices[1][12], possible[12], done[12], player_scores[1][12], current_player) bonus_player1 = Choice(0, 890, 'YAHTZEE Bonus', False, False, True, totals[3], current_player) lower_total_player1 = Choice(0, 920, 'Lower Total', False, False, True, totals[4], current_player) upper_total_player1 = Choice(0, 950, 'Upper Total', False, False, True, totals[5], current_player) grand_total_player1 = Choice(0,980, 'Grand Total', False, False, True, totals[6], current_player) game_score_player1 = totals[6] ones_player2 = Choice(0, 200, '1s', player_choices[2][0], possible[0], done[0], player_scores[2][0], current_player) twos_player2 = Choice(0, 230, '2s', player_choices[2][1], possible[1], done[1], player_scores[2][1], current_player) threes_player2 = Choice(0, 260, '3s', player_choices[2][2], possible[2], done[2], player_scores[2][2], current_player) fours_player2 = Choice(0, 290, '4s', player_choices[2][3], possible[3], done[3], player_scores[2][3], current_player) fives_player2 = Choice(0, 320, '5s', player_choices[2][4], possible[4], done[4], player_scores[2][4], current_player) sixes_player2 = Choice(0, 350, '6s', player_choices[2][5], possible[5], done[5], player_scores[2][5], current_player) lower_total1_player2 = Choice(0, 380, 'Upper Score', False, False, True, totals[0], current_player) lower_bonus_player2 = Choice(0, 410, 'Bonus if >= 75', False, False, True, totals[1], current_player) lower_total2_player2 = Choice(0, 440, 'Upper Total', False, False, True, totals[2], current_player) pair_player2 = Choice(0, 470, 'Pair', player_choices[2][19], possible[19], done[19], player_scores[2][19], current_player) two_pairs_player2 = Choice(0, 500, '2 pairs', player_choices[2][15], possible[15], done[15], player_scores[2][15], current_player) three_pairs_player2 = Choice(0, 530, '3 pairs', player_choices[2][16], possible[16], done[16], player_scores[2][16], current_player) three_kind_player2 = Choice(0, 560, '3 of Kind', player_choices[2][6], possible[6], done[6], player_scores[2][6], current_player) four_kind_player2 = Choice(0, 590, '4 of Kind', player_choices[2][7], possible[7], done[7], player_scores[2][7], current_player) five_kind_player2 = Choice(0, 620, '5 of Kind', player_choices[2][13], possible[13], done[13], player_scores[2][13], current_player) small_straight_player2 = Choice(0, 650, 'Sm. Straight', player_choices[2][9], possible[9], done[9], player_scores[2][9], current_player) large_straight_player2 = Choice(0, 680, 'Lg. Straight', player_choices[2][18], possible[18], done[18], player_scores[2][18], current_player) full_straight_player2 = Choice(0, 710, 'Full Straight', player_choices[2][10], possible[10], done[10], player_scores[2][10], current_player) small_house_player2 = Choice(0, 740, 'Small House', player_choices[2][20], possible[20], done[20], player_scores[2][20], current_player) full_house_player2 = Choice(0, 770, 'Full House', player_choices[2][8], possible[8], done[8], player_scores[2][8], current_player) tower_player2 = Choice(0, 800, 'Tower', player_choices[2][14], possible[14], done[14], player_scores[2][14], current_player) yahtzee_player2 = Choice(0, 830, 'YAHTZEE', player_choices[2][11], possible[11], done[11], player_scores[2][11], current_player) chance_player2 = Choice(0, 860, 'Chance', player_choices[2][12], possible[12], done[12], player_scores[2][12], current_player) bonus_player2 = Choice(0, 890, 'YAHTZEE Bonus', False, False, True, totals[3], current_player) lower_total_player2 = Choice(0, 920, 'Lower Total', False, False, True, totals[4], current_player) upper_total_player2 = Choice(0, 950, 'Upper Total', False, False, True, totals[5], current_player) grand_total_player2 = Choice(0,980, 'Grand Total', False, False, True, totals[6], current_player) game_score_player2 = totals[6] draw_stuff() draw_dice() draw_options() possible = check_possibilities(possible, numbers) score = check_scores(player_choices[current_player], numbers, possible, score) totals, bonus_time = check_totals(totals, player_scores[current_player], bonus_time) if draw_clicked < 30: outline_button = pygame.draw.rect(screen, (70, 70, 70), [10, 160, 280, 30], 4) draw_clicked += 1 for event in pygame.event.get(): if event.type == pygame.QUIT: running = False if event.type == pygame.MOUSEBUTTONDOWN: if game_over and restart.collidepoint(event.pos): restart_function() game_over = False die1.check_click(event.pos) die2.check_click(event.pos) die3.check_click(event.pos) die4.check_click(event.pos) die5.check_click(event.pos) die6.check_click(event.pos) if button1.collidepoint(event.pos) and player_rolls_left[current_player] > 0: roll = True player_rolls_left[current_player] -= 1 draw_clicked = 0 if button2.collidepoint(event.pos) and something_selected and player_rolls_left[current_player] < 209: for i in range(len(player_choices[current_player])): if player_choices[current_player][i]: done[i] = True player_scores[current_player][i] = score player_choices[current_player][i] = False for i in range(len(player_selected[current_player])): player_selected[current_player][i] = False player_rolls_left[current_player] += 3 numbers = [7, 9, 11, 13, 17, 20] something_selected = False # Switch players current_player = 3 - current_player # Switch between 1 and 2 # Reset player-specific variables for the new player's turn player_selected[current_player] = [False] * 6 clicked = False draw_clicked = 30 if 0 <= event.pos[0] <= 155: if 200 < event.pos[1] < 381 or 470 < event.pos[1] < 890: if 200 < event.pos[1] < 230: clicked = 0 elif 230 < event.pos[1] < 260: clicked = 1 elif 260 < event.pos[1] < 290: clicked = 2 elif 290 < event.pos[1] < 320: clicked = 3 elif 320 < event.pos[1] < 350: clicked = 4 elif 350 < event.pos[1] < 380: clicked = 5 elif 470 < event.pos[1] < 500: clicked = 19 elif 500 < event.pos[1] < 530: clicked = 15 elif 530 < event.pos[1] < 560: clicked = 16 elif 560 < event.pos[1] < 590: clicked = 6 elif 590 < event.pos[1] < 620: clicked = 7 elif 620 < event.pos[1] < 650: clicked = 13 elif 650 < event.pos[1] < 680: clicked = 9 elif 680 < event.pos[1] < 710: clicked = 18 elif 710 < event.pos[1] < 740: clicked = 10 elif 740 < event.pos[1] < 770: clicked = 20 elif 770 < event.pos[1] < 800: clicked = 8 elif 800 < event.pos[1] < 830: clicked = 14 elif 830 < event.pos[1] < 860: clicked = 11 elif 860 < event.pos[1] < 890: clicked = 12 player_choices[current_player] = make_choice(clicked, player_choices[current_player], done) if roll: for number in range(len(numbers)): if not player_selected[current_player][number]: numbers[number] = random.randint(1, 6) roll = False for i in range(len(possible)): if player_choices[current_player][i] and not possible[i]: click_text = font.render('Choosing that option will give you a zero!', True, (155, 34, 34)) screen.blit(click_text, (230, 205)) if player_choices[current_player][i]: something_selected = True if game_over: if game_score_player1 > high_score: high_score = game_score_player1 if game_score_player2 > high_score: high_score = game_score_player2 if False not in done: game_over = True pygame.display.flip() pygame.quit()