发现了一个好玩的休闲小游戏

考反应,考敏捷,拍代码累了,就来休闲一会吧。。。

下载地址:http://www.gamersky.com/Soft/201201/32475.shtml

                                                                   

                                                                   
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这里给出一个基于Python Turtle模块的小游戏,叫做“躲避球”(Dodgeball)。 游戏规则: 1. 控制一个小球躲避落下的球。 2. 落下的球速度逐渐加快,难度逐渐增加。 3. 如果小球被击中,游戏结束,显示得分。 代码如下: ```python import turtle import random # 设置窗口大小和标题 wn = turtle.Screen() wn.title("Dodgeball") wn.bgcolor("black") wn.setup(width=600, height=600) # 创建玩家小球 player = turtle.Turtle() player.shape("circle") player.color("white") player.penup() # 设置落下的球列表和速度 balls = [] ball_speed = 1 # 创建落下的球 def create_ball(): ball = turtle.Turtle() ball.shape("circle") ball.color("red") ball.penup() ball.goto(random.randint(-280, 280), 280) balls.append(ball) # 移动玩家小球 def move_left(): x = player.xcor() x -= 20 player.setx(x) def move_right(): x = player.xcor() x += 20 player.setx(x) # 绑定键盘事件 wn.listen() wn.onkeypress(move_left, "Left") wn.onkeypress(move_right, "Right") # 循环游戏 score = 0 while True: # 创建落下的球 if random.randint(1, 10) == 1: create_ball() # 移动落下的球 for ball in balls: y = ball.ycor() y -= ball_speed ball.sety(y) # 判断是否击中玩家小球 if ball.distance(player) < 20: wn.bgcolor("red") player.hideturtle() ball.hideturtle() print("Game Over! Score:", score) wn.exitonclick() # 判断是否落到底部 if y < -280: ball.hideturtle() balls.remove(ball) # 加速落下的球 ball_speed += 0.001 score += 1 ``` 运行代码,就可以开始玩“躲避球”小游戏啦!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值