How to write the example code of realizing ball evasion with Pygame
Pygame implementation of ball avoidance example code how to write, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
Foreword:
In the Python class this semester, there is really a lot to write code.
Experiment 1 of the course is a backgammon, but the code is sent.
As for the quality of the code, I changed it directly according to the structure divided by myself.
Complain here (the code really sent out is terrible)
I changed it for almost 4 hours and then I don't want to add any more functions.
Write it yourself this time. Then write something like that.
Structural division
I divided it into
Run entrance
Setting Settin
Main master logic
Utils warehouse
In fact, what I want to do is to set it all on the page, but be lazy ~ (I'm going to get a grade point at the end of the term)
Start posting code directly.
Run.pyimport sysfrom main import mainbanner = "" _ _ _ | _ | if _ name__ = ='_ main__': print (banner) print ("Author: HengYi") print ("[*] simple: enter 1") print ("[*] normal: enter 2") print ("[*] difficult: enter 3") try: num = int (input ( "Please select difficulty:") if num in [1 two, 3]: main (num) else: print ("unable to handle ~") sys.exit () except Exception as e: raise Exception ("unable to handle ~") setting.pyWIDTH = 900 # wide HEIGHT = 600 # high SCORE = 0 # fractional TIME = 0 # time FIRST_STEP = 10 # arrival time SECOND_STEP = 20 # time to reach the third level FPS = 60 # refresh rate BG_COLOR = (255) 239,213) # background color utils.py#-*-coding: utf-8-*-import pygamefrom setting import FIRST_STEP, SECOND_STEP, BG_COLOR, WIDTH, HEIGHT# Note: generate corresponding balls according to difficulty # Time: 8:35 on 2021-12-17 # Author: HengYidef ballNum (ladderNum, time): index = 0 if FIRST_STEP