Introduction:

​​

* * * * the Mid-Autumn festival

(one of the four traditional Festivals in China) Since ancient times, the Mid-Autumn Festival has folk customs such as offering sacrifices to the moon, appreciating the moon, eating moon cakes, playing lanterns, appreciating osmanthus flowers, drinking osmanthus wine and guessing lantern riddles, which has been handed down to us today and lasts for a long time.

Welcome to read about the upcoming Mid-Autumn Festival:

1. My God! To my surprise, you can make chocolate mooncakes with Python! [Source code]

2. I never expected a box of moon cakes to become popular! This secret Python mooncake is yours to take!

The goddess invited me to admire the moon! As soon as I saw that the Mid-Autumn Festival might rain, I wrote a moon viewing tool in Python!

Hahahaha! Ok, after introducing our Mid-Autumn Festival, let’s begin. Didn’t know everyone was going home this year? Remember to eat moon cakes

Besides moon cakes? What else can we talk about? In addition to the normal dinner and moon cakes, of course, you can enjoy the moon after dinner.

Guess what happens when Mid-Autumn Festival meets the lantern?

The body of the

Mid-Autumn festival is coming, in order to guess riddles to everyone! I wish everyone a happy Mid-Autumn Festival in advance

(1) Set parameters of the game start interface, etc.

class startInterface(): def __init__(self, screen, **kwargs): Self. text2 = 'start the game' self.text3 = 'end the game' self.text3 = 'end the game' self.text3 = 'end the game' self.screen = screen def start(self): button_groups = pygame.sprite.Group() button_start = Button(font_path=font_path, font_size=24, text=self.text2, position=(236, 300)) button_quit = Button(font_path=font_path, font_size=24, text=self.text3, position=(464, 300)) button_groups.add(button_start) button_groups.add(button_quit) font = pygame.font.Font(font_path, 48) clock = pygame.time.Clock() while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() elif event.type == pygame.MOUSEBUTTONDOWN: if event.button == 1: mouse_pos = pygame.mouse.get_pos() if button_start.rect.collidepoint(mouse_pos): return elif button_quit.rect.collidepoint(mouse_pos): pygame.quit() sys.exit() self.screen.fill((0, 0, 0)) title = font.render(self.text1, True, DeepSkyBlue) self.screen.blit(title, (302, 150)) button_groups.update() button_groups.draw(self.screen) pygame.display.update() clock.tick(60)Copy the code

As follows:

​​​​

(2) Set the end interface of the game.

class endInterface(): def __init__(self, screen, num_correct, num_total, **kwargs): Self. text2 = '%s' % num_correct self.text3 =' %s' % num_correct self.text3 = '%s' %s' % num_total self.text4 = 'correct: %.2f%%' % (num_correct*100/num_total) self.screen = screen def start(self): Button_groups = pygame.sprite.group () button_restart = Button(font_path=font_path, font_size=24, text=' restart ', Position =(236, 400) button_quit = Button(font_path=font_path, font_size=24, text=' quit ', position=(464, 400)) button_groups.add(button_restart) button_groups.add(button_quit) font_big = pygame.font.Font(font_path, 32) font = pygame.font.Font(font_path, 24) clock = pygame.time.Clock() while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() elif event.type == pygame.MOUSEBUTTONDOWN: if event.button == 1: mouse_pos = pygame.mouse.get_pos() if button_restart.rect.collidepoint(mouse_pos): startGuess() elif button_quit.rect.collidepoint(mouse_pos): pygame.quit() sys.exit() self.screen.fill((0, 0, 0)) text1_render = font_big.render(self.text1, True, DeepSkyBlue) text2_render = font.render(self.text2, True, DeepSkyBlue) text3_render = font.render(self.text3, True, DeepSkyBlue) text4_render = font.render(self.text4, True, DeepSkyBlue) self.screen.blit(text1_render, (250, 100)) self.screen.blit(text2_render, (250, 200)) self.screen.blit(text3_render, (250, 240)) self.screen.blit(text4_render, (250, 280)) button_groups.update() button_groups.draw(self.screen) pygame.display.update() clock.tick(60)Copy the code

As follows:

​​

(3) For each correct answer, use the if else loop to determine the correct answer.

If button_choice1. The rect. Collidepoint (mouse_pos) : flag = True if answer = = 0: text = 'congratulations, right subject num_correct + = 1 else: Text = 'I'm sorry, wrong subject' elif button_choice2. The rect. Collidepoint (mouse_pos) : flag = True if answer = = 1: Text = 'congratulations, right subject num_correct + = 1 else: text =' sorry, wrong subject 'elif button_choice3. The rect. Collidepoint (mouse_pos) : Flag = True if answer == 2: text = 'Congratuations to you, num_correct += 1 else: Text = 'I'm sorry, wrong subject' elif button_choice4. The rect. Collidepoint (mouse_pos) : flag = True if answer = = 3: 'num_correct += 1 else: text =' sorry, sorry, sorry 'Copy the code

(4) Set the number of lantern riddles to 25 and show 2 groups randomly here.

Data = [{' quesion ':' black mouth, the field of vortex, drinking water, less talk more (a stationery) ', 'options' : [' pen', 'brush pen, pencil,' ink '], "answer" : 1}, {' quesion: 'speech sound too light, the audience opinion (an idiom)', 'options' : [' have', 'all tastes',' disappointing ', 'inferior'], 'answer: 3},... omit...Copy the code

Effect:

​​

Lantern riddles guessing activities:

  • 1. The moon on The fifteenth day

  • 2) From Month to Chuseok (digital)

  • 3. Champagne on the Night of The Mid-Autumn Festival (Three characters folk custom)

  • 4. Enjoy the Mid-Autumn Moon in China

  • The sea rose the moon, the end of the world at this time

How was it? Was it a little difficult? Take a guess and leave your answers in the comments section (be sure to include the order of the puzzles).

conclusion

Finally, Mumuzi wishes all friends a happy holiday! Happy family reunion! Remember to like it three times

If you need the complete code, Python novice installation package, free activation code, and more Python information

Source code base: # private xiaobian 06# can be free source code!