Python编程:从⼊门到实践,课后题13-5
⾃学Python两三个⽉了,深感智商的⽋缺,思维⽅式⽐较线性,毕竟是⼀个⼤学只学过⼀门VB的⼥同学 。所以学编程的道路上经常遇到障碍,笨笨……⼀个⼩问题都会牵出很深奥的知识。发现这本书的第⼆部分⽹上不到参考答案,就分享⼀个⾃⼰研究了很多天(真的是好⼏天,?),最后做的还算成功的13.5。编程真的很奇妙,虽然我学的很笨拙,但是成就感还是要爆了……
import pygame
import sys
from random import randint
from pygame.sprite import Sprite
酒店管理系统数据库设计from pygame.sprite import Group
pygame.init()
bg_color=(20,40,50)
screen=pygame.display.set_mode((1200,700))
random_number=randint(1,1200)
dropspeed=3
speed_factor=5
class Doll(Sprite):
"""docstring for Doll"""
def __init__(self, screen):
super(Doll, self).__init__()
self.screen = screen
c语言getstring函数的用法self.image=pygame.image.load('timg.bmp')
<=_rect()
self.screen_rect=_rect()
学python编程入门
def blitme(self):
self.screen.blit(self.)
def update(self):
ving_right ight<self.screen_rect.right:
ving_left left>0:
class Water(Sprite):
def __init__(self,screen,random_number):
super(Water, self).__init__()
self.screen=screen
孙侨潞在医院的图片self.image=pygame.image.load("raindrop.bmp")
<=_rect()
self.screen_rect=_rect()
self.y=)
def blitme(self):
self.screen.blit(self.)
def update(self):
北京java程序员工资self.y+=dropspeed
<=self.y
def fail(self):
op>=self.screen_rect.bottom:
print("no")
random_number=randint(1,1200)
water=Water(screen,random_number)
waters.add(water)
def catch_water(doll,water,waters):
catch=pygame.sprite.spritecollide(doll,waters,True,collided=None)
catch=pygame.sprite.spritecollide(doll,waters,True,collided=None)
#曾经前边有doll=Doll()……导致在只有移动娃娃才能接到⽔珠的情况下,⽔珠不消失
for water in waters:#之前丢了这句,就不是遍历了
op>=water.screen_rect.bottom:
if len(waters)==0:
random_number=randint(1,1200)
water=Water(screen,random_number)
waters.add(water)
def check_keydown_events(event,doll):
if event.key==pygame.K_RIGHT:
sol日历最新版
elif event.key==pygame.K_LEFT:
def check_keyup_events(event,doll):
if event.key==pygame.K_RIGHT:
elif event.key==pygame.K_LEFT:
def event_check(doll):
for event in ():
pe==pygame.QUIT:
pe==pygame.KEYDOWN:
check_keydown_events(event,doll)
pe==pygame.KEYUP:
check_keyup_events(event,doll)
def rungame():
water=Water(screen,random_number)
waters=Group()
waters.add(water)
doll=Doll(screen)
while True:
screen.fill(bg_color) #这⼀步很重要啊,要是挪到True以前,娃娃就会出现重影,擦掉背景⾊。  doll.blitme()
waters.draw(screen)
pygame.display.flip()
event_check(doll)
doll.update()
waters.update()
catch_water(doll,water,waters)
rungame()

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。