======== Make a game for your little sister at school to play: .
The game of marbles is largely determined by the coordinates xy, the length of the splice plate, and the radius of the ball:
# -*- coding: utf-8 -*-
# @Author : Codeooo
# @Time : 2022/04/29
import sys
import time
import random
import pygame as pg
print(""" Welcome to the Codeooo Gaming Platform!
1. Login account password, correct direct access 2, if you enter 3 times can also enter, but prompted to enter as a visitor.
2. The system generates random numbers from 1-20, guess correctly and go directly to 3, or guess incorrectly 6 times can also enter, but suggests that the level has not been passed.
3. Catch the small ball game, every three times speed up, double the score.
******** Thanks for watching *******
""")
def game_login():
count = 0
while count < 3:
name = str(input("Please enter an account number"))
passwd = str(input("Please enter a password"))
if (name != "codeooo" or passwd != "666"):
count += 1
s = 3 - count
print("Input error, %d chances left\n" % s)
if s == 0:
print("You are logged in as a guest")
else:
print("Dear VIP Codeooo, login successful, directly into the game \n")
break
def game_random():
count = 0
number = random.randint(1, 20)
print(""" ###### The system is about to generate a random number from 1-20 ######
######### Guess correctly and go straight to the game ###############
######## Guess the big one suggests big, guess the small one suggests small now ########
### 6 wrong guesses can also enter the game, but this game is not passed ####
""")
print(number)
while True:
num = int(input("Please enter the number you want to guess"))
count += 1
if (count <= 6):
if (num == number):
print("You passed the level, a total of %d entries \n" % (count))
print("Success, go to next game\n")
break
elif (num < number):
print("You have entered small, please guess again\n")
else:
print("You have entered a large number, please guess again\n")
else:
print(""" ****** This level is not cleared *********
******* has been entered 6 times***
********* Go to the next game ************
""")
break
def boll_game():
pg.init() # perform initialization operations on the module
game_window = pg.display.set_mode((600, 500)) # Draw the window, with the method, this method can generate a game window, the parameters inside need to give a tuple, the two elements of the tuple are the window width and height respectively
pg.display.set_caption(' Catch the ball ') # title
window_color = (0, 0, 255) # Elements inside a blue rgb tuple, represented as rgb
ball_color = (255, 165, 0) # Yellow rgb value
rect_color = (255, 0, 0)
score = 0
font = pg.font.SysFont('arial', 70)
ball_x = random.randint(20, 580) # Generate a random number using the random module to keep the ball from being fixed Define two variables to hold the position of the ball, with the radius of the ball defined as 20
ball_y = 20 # Variable of the ball on the y-axis
move_x = 1 # Save the value via a variable, change the speed of the ball by changing the variable size
move_y = 1
point = 1
count = 0
print("\n")
print("Game on \n")
while True:
game_window.fill(window_color) # pass the parameter
for event in pg.event.get(): # can exit, it's a status
if event.type == pg.QUIT: #
sys.exit() # method inside the sys module
mouse_x, mouse_y = pg.mouse.get_pos() # used to receive xy coordinates from mouse
pg.draw.circle(game_window, ball_color, (ball_x, ball_y), 20) #
pg.draw.rect(game_window, rect_color, (mouse_x, 490, 100, 10)) # abbreviation for rectangle, draw a rectangle
my_text = font.render(str(score), False, (255, 255, 255))
game_window.blit(my_text, (500, 30)) # This position is debugged and feels more appropriate
ball_x += move_x # add 1 to the horizontal and vertical coordinates each time, so it looks faster and like the ball is moving
ball_y += move_y
if ball_x <= 20 or ball_x >= 580:
move_x = -move_x # Changing plus to minus is moving in the opposite direction
if ball_y <= 20:
move_y = -move_y
elif mouse_x - 20 < ball_x < mouse_x + 120 and ball_y >= 470:
move_y = -move_y
score += point # need a variable to hold the number of points added each time
count += 1
if count == 3: # need a variable to store the number of times each catch is made
count = 0 # reset it to 0
point += point
if move_x > 0:
move_x += 1
else:
move_x -= 1
move_y -= 1
elif ball_y >= 480 and (ball_x <= mouse_x - 20 or ball_x >= mouse_x + 120):
print("Game Over")
time.sleep(3)
break
pg.display.update() # update the window
time.sleep(0.005) # If you feel it's slow, you can adjust it yourself.
def run():
game_login()
game_random()
boll_game()
if __name__ == '__main__':
run()