Commit ba1459ae by BellCodeEditor

auto save

parent 2c7328ea
Showing with 91 additions and 12 deletions
import pygame
from pygame import locals
import random import random
player=input("请出拳:石头/剪刀/布:")# 玩家出拳
print("玩家出拳:"+player) pygame.init()
list=["石头","剪刀","布"] screen = pygame.display.set_mode((1000, 600))
computer=random.choice(list) FPS = pygame.time.Clock()
print("电脑出的是:"+computer)
if player==computer: background = pygame.image.load('bg.png')
print("平局") road = pygame.image.load('road.png')
elif player=="石头"and computer=="剪刀"or player=="剪刀"and computer=="布" or player=="布" and computer=="石头" stone = pygame.image.load('stone.png')
print("恭喜,你赢了") cacti = pygame.image.load('cacti.png')
else: bush = pygame.image.load('bush.png')
print("很遗憾,你输了") hole = pygame.image.load('hole.png')
\ No newline at end of file grass = pygame.image.load('grass.png')
heroes = [pygame.image.load('hero1.png'),pygame.image.load('hero2.png'),pygame.image.load('hero3.png'),pygame.image.load('hero4.png'),pygame.image.load('hero5.png'),]
##流程
state = "moving"
i=0
y=400
t=30
road_x=0
bg_x=0
class Block(pygame.sprite.Sprite):
def __init__(self,img1,img2,img3,img4,img5):
super().__init__()
self.image = random.choice([img1,img2,img3,img4,img5])
self.rect=self.image.get_rect()
self.rect.x=1000+self.rect.width
self.rect.y=500-self.rect.height
blocks=Block(grass,hole,stone,bush,cacti)
clocks=Block(grass,hole,stone,bush,cacti)
clocks.rect.x+=400+random.randint(-400,400)
while True:
##Shadow
shadow=1
if blocks.rect.x-450<=100 and state != "down":
state="up"
shadow=0
##Keys
for event in pygame.event.get():
if event.type == locals.QUIT:
exit()
if event.type == locals.KEYDOWN and shadow==1:
if state=="moving" and event.key==locals.K_UP:
state = "up"
if state=="down" and event.key==locals.K_DOWN:
pass
##Action
if state=="up":
if t>0:
y-=t
t-=2
else:
state="down"
if state=="down":
if t<=30:
y+=t
t+=2
else:
state="moving"
t-=2
bg_x-=10
if bg_x<-1000:
bg_x=0
road_x-=30
if road_x<-1000:
road_x=0
if i<4 and state == "moving":
i+=1
else:
i=0
if blocks.rect.x<0-blocks.rect.width:
blocks=Block(grass,hole,stone,bush,cacti)
blocks.rect.x-=30
if clocks.rect.x<0-clocks.rect.width:
clocks=Block(grass,hole,stone,bush,cacti)
clocks.rect.x+=400+random.randint(-400,400)
clocks.rect.x-=30
##Play
screen.blit(background, (bg_x, 0))
screen.blit(road, (road_x, 500))
screen.blit(heroes[i], (150, y))
screen.blit(blocks.image,(blocks.rect.x,blocks.rect.y))
screen.blit(clocks.image,(clocks.rect.x,clocks.rect.y))
pygame.display.update()
FPS.tick(20)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment