0% found this document useful (0 votes)
4 views

Development Journal - Day 11

Uploaded by

aksharpatel1715
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Development Journal - Day 11

Uploaded by

aksharpatel1715
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Major Tasks:

- Allow the player to roll the dice after answering the question

Date: 3/18/2024
Tasks to work on:
- Getting the player to roll the dice after answering the questions

Problems discovered: runtime error

Problem solved: I was able to get the player to roll the dice after answering the questions
correctly.

def display_question():
question = random.choice(list(questions_answers.keys()))

font = pygame.font.Font(None, 36)


text = font.render(question, True, (0, 0, 0))
text_rect = text.get_rect(center=(850 // 2, 700 // 2 - 50))
screen.blit(text, text_rect)
pygame.display.update()

input_box = pygame.Rect(300, 350, 200, 32)


color_inactive = pygame.Color('lightskyblue3')
color_active = pygame.Color('dodgerblue2')
color = color_inactive
active = False
text = ''
clock = pygame.time.Clock()

waiting = True
while waiting:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
if event.type == pygame.MOUSEBUTTONDOWN:
if input_box.collidepoint(event.pos):
active = not active
else:
active = False
color = color_active if active else color_inactive
if event.type == pygame.KEYDOWN:
if active:
if event.key == pygame.K_RETURN:
waiting = False
elif event.key == pygame.K_BACKSPACE:
text = text[:-1]
else:
text += event.unicode
screen.fill((30, 30, 30))
pygame.draw.rect(screen, color, input_box)
font = pygame.font.Font(None, 32)
txt_surface = font.render(text, True, (255, 255, 255))
width = max(200, txt_surface.get_width() + 10)
input_box.w = width
screen.blit(txt_surface, (input_box.x + 5, input_box.y + 5))
pygame.draw.rect(screen, (255, 255, 255), input_box, 2)
pygame.display.flip()
clock.tick(30)
return text.strip()

You might also like