用户:与竹独行查看:0 回复:0 评论:0 创建时间:2020-01-06T15:51:01
【作品展示】

【作品介绍】
自己做的小游戏大全弹球游戏和海龟走路游戏
支持全屏
图片无法上传,要自己去找
一共两张图片
一张是黑底的笑脸(或者弹球)
一张是白底的走路的海龟
注:所需图片跟我帖子中的背景无关
运行需要保存到本地运行
且图片与.py文件需在一个文件夹内
加油1
【作品源代码】
import random
import math
import easygui
import pygame
from pygame.locals import *
pygame.init()
ab_u = random.randint(2331, 21323)
ba_p = random.randint(324, 4321)
print("游客登录用户名:",ab_u)
print("游客登录密码:",ba_p)
user = ["2170044100", str(ab_u),"1"]
passward = ["20080508", str(ba_p),"5"]
msg = ["游戏开始", "玩游戏吗?", "玩什么游戏?", "请输入","用户名错误", "密码错误", "您有0508小游戏用户名吗?", "注册成功","用户名或密码未输入完整"]
title = ["温馨提示", "问答", "0508小游戏登录框", "0508小游戏首页", "0508小游戏注册框"]
botton = "确定"
fieldNames = ["0508小游戏用户名", "密码"]
def prepare_keep():
ww = 0
while True:
c = easygui.multpasswordbox(msg[3], title[2], fieldNames)
if c == None:
ww = 1
break
elif c[0] == user[0]:
if c[1] == passward[0]:
break
else:
easygui.msgbox(msg[5], title[0], botton)
elif c[0] == user[1]:
if c[1] == passward[1]:
break
else:
easygui.msgbox(msg[5], title[0], botton)
elif c[0] == user[2]:
if c[1] == passward[2]:
break
else:
easygui.msgbox(msg[5], title[0], botton)
else:
easygui.msgbox(msg[4], title[0], botton)
if ww == 0:
keep_going()
else:
easygui.msgbox("拜拜", title[0], botton)
def keep_going():
b = easygui.ccbox(msg[2], title[1], ("弹球", "海龟走路"))
if b:
easygui.msgbox(msg[0], title[0], botton)
a = 800
b = 600
size = [a, b]
screen = pygame.display.set_mode(size)
pictrue = pygame.image.load("笑脸.png")
position = pictrue.get_rect()
keep_Going = True
time = pygame.time.Clock()
picx = 0
picy = 0
speedx = 5
speedy = 5
speed = [speedx, speedy]
paddlew = 200
paddleh = 25
paddlex = 300
paddley = 450
picw = 100
pich = 100
while keep_Going:
for event in pygame.event.get():
if event.type == pygame.QUIT:
keep_Going = False
if event.type == VIDEORESIZE: # 对屏幕进行大小的更改,并且输出当前调整的屏幕的大小,并且更新当前的screen的大小
size = event.size
a, b = size
print(size)
screen = pygame.display.set_mode(size, RESIZABLE)
if position.bottom > b:
position.bottom = b
if position.right > a:
position.right = a
if position.top < 0:
position.top = 0
if position.left < 0:
position.left = 0
position = position.move(speed)
picx += speedx
picy += speedy
if picx <= 0 or picx >= 800:
speedx = -speedx
if picy <= 0 or picy >= 600:
speedy = -speedy
screen.fill((0, 0, 0))
spot = pygame.mouse.get_pos()
x = spot[0]
y = 450
w = 200
h = 25
pygame.draw.rect(screen, [255, 255, 255], (x, y, w, h))
if picx > x and picx < x + 200 and picy + 100 > 450 and speedy > 0:
speedy = -speedy
time.tick(60)
screen.blit(pictrue, (picx, picy))
pygame.display.update()
pygame.quit()
else:
easygui.msgbox(msg[0], title[0], botton)
size = width, height = 600, 400
speed = [-2, 1]
bg = (255, 255, 255)
fullscreen = False
screen = pygame.display.set_mode(size, RESIZABLE)
pygame.display.set_caption("Hello")
turtle = pygame.image.load("海龟.png")
position = turtle.get_rect()
l_head = turtle
r_head = pygame.transform.flip(turtle, True, False)
keep_going = True
while keep_going:
for event in pygame.event.get():
if event.type == pygame.QUIT:
keep_going = False
if event.type == KEYDOWN:
if event.key == K_LEFT:
turtle = l_head
speed = [-1, 0]
speed = [-2, -1]
if event.key == K_RIGHT:
turtle = r_head
speed = [1, 0]
speed = [2, 1]
if event.key == K_UP:
speed = [2, -1]
if event.key == K_DOWN:
speed = [-2, 1]
if event.key == K_F11:
fullscreen = not fullscreen
if fullscreen:
screen = pygame.display.set_mode(
(1024, 768), FULLSCREEN | HWSURFACE)
width, height = 1024, 768
else:
screen = pygame.display.set_mode(size)
if event.type == VIDEORESIZE:
size = event.size
width, height = size
print(size)
screen = pygame.display.set_mode(size, RESIZABLE)
if position.bottom > height:
position.bottom = height
if position.right > width:
position.right = width
if position.top < 0:
position.top = 0
if position.left < 0:
position.left = 0
position = position.move(speed)
if position.left < 0 or position.right > width:
turtle = pygame.transform.flip(turtle, True, False)
speed[0] = -speed[0]
if position.top < 0 or position.bottom > height:
speed[1] = -speed[1]
screen.fill(bg)
screen.blit(turtle, position)
pygame.display.flip()
pygame.time.delay(10)
pygame.quit()
pass
a = easygui.ynbox(msg[1], title[1], ("玩", "不玩"))
if a:
d = easygui.ynbox(msg[6], title[3], ("我有,可以登录", "我没有,来注册吧"))
if d:
prepare_keep()
else:
e = easygui.multpasswordbox(msg[3], title[4], fieldNames)
if e == None:
easygui.msgbox("拜拜", title[0], botton)
else:
user[2] = e[0]
passward[2] = e[1]
easygui.msgbox(msg[7], title[0], botton)
prepare_keep()
else:
easygui.msgbox("拜拜", title[0], botton)
pass
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn