见缝插针游戏是一款非常考验玩家手眼协调能力的休闲益智虐心虐脑小游戏,玩法很简单,但要过关却很有挑战性哟! 主要是将一系列的小球,插入到旋转的摩天轮转盘当中,插入过程中不能碰到旋转的摩天轮上的其他小球,全部插入即可过关!

核心程序代码
main.py

import pygame
import sys
import math
from tools import *pygame.init()
size = width, height = 620, 450
screen = pygame.display.set_mode(size)
pygame.display.set_caption("见缝插针-Python代码大全")
fps = 60
fclock = pygame.time.Clock()
WHITE = 255, 255, 255
bg_color = 139, 134, 167
PURPLE = 114, 100, 122
ball_group = []
font = pygame.font.Font(r"C:\Windows\Fonts\simsun.ttc", 18)
stage_font = pygame.font.Font(r"C:\Windows\Fonts\simsun.ttc", 30)
# 转轴的中心位置
shaft = x0, y0 = 310, 160
# 针的长度
length = 140
# 转动的角速度
angular_speed = 0.004 * math.pi
stage = 8
# 每关要插的针的数量
ball_num = [10, 14, 12, 20, 13, 14, 16, 26]
remain_ball = 0
stage1 = [0, math.pi / 2, math.pi, math.pi * 1.5]
stage2 = [0, math.pi / 2, math.pi, math.pi * 1.5]
stage3 = [0, math.pi / 3, math.pi * 2 / 3, math.pi, math.pi * 4 / 3, math.pi * 5 / 3]
stage4 = [0, math.pi]
stage5 = [0, math.pi / 3, math.pi * 2 / 3, math.pi, math.pi * 4 / 3, math.pi * 5 / 3]
stage6 = [0, math.pi / 4, math.pi / 2, math.pi, math.pi * 3 / 4, math.pi, math.pi * 5 / 4, math.pi * 3 / 2,math.pi * 7 / 4]
stage7 = [0, math.pi / 4, math.pi / 2, math.pi, math.pi * 3 / 4, math.pi, math.pi * 5 / 4, math.pi * 3 / 2,math.pi * 7 / 4]
stage8 = [0, math.pi]
all_stage = [stage1, stage2, stage3, stage4, stage5, stage6, stage7, stage8]
gaming = True
stage_pass = Falseclass Ball:"""针头"""def __init__(self, angle):self.x = x0self.y = y0 + lengthself.center = (self.x, self.y)self.radius = 12self.angle = angleball_group.append(self)def draw(self, surface):pygame.draw.line(surface, WHITE, shaft, self.center, 2)pygame.draw.circle(surface, WHITE, self.center, 12)def move(self, speed):"""围绕转轴做圆周运动:param speed: 转动的角速度:return:"""if self.angle < 2 * math.pi:self.angle += speedelse:self.angle = self.angle - 2 * math.piself.x = x0 - length * math.sin(self.angle)self.y = y0 + length * math.cos(self.angle)self.center = (self.x, self.y)def check_collide(new_ball):for ball in ball_group:distance = math.sqrt(abs(ball.x - new_ball.x) ** 2 + abs(ball.y - new_ball.y) ** 2)if ball is not new_ball and distance <= new_ball.radius * 2:return Truereturn Falsedef game_init():global stage, gaming, remain_ball, stage_passif stage == len(all_stage):stage = 1elif stage_pass:stage += 1ball_group.clear()for a in all_stage[stage - 1]:b = Ball(a)remain_ball = ball_num[stage - 1]pygame.time.delay(200)gaming = Truestage_pass = Falsebutton = Button('重新开始', color=(220, 0, 0))
button.rect.center = shaft
button.click_connect(game_init)def restart():for event in pygame.event.get():if event.type == pygame.QUIT:pygame.quit()sys.exit()button.get_click(event)def game_stage():global remain_ball, stage, gaming, stage_passif remain_ball == 0 and gaming:stage_pass = Truegaming = Falsedef update():screen.fill(bg_color)# 左上角关卡信息stage_num = stage_font.render('第{}关'.format(stage), True, WHITE)stage_rect = stage_num.get_rect()stage_rect.left = 5stage_rect.top = 5screen.blit(stage_num, stage_rect)# 绘制转轴的圆盘pygame.draw.circle(screen, WHITE, (310, 160), 42)# 绘制剩余针头提示pygame.draw.circle(screen, WHITE, (310, 380), 12)# 剩余针头数量remain_num = font.render('{}'.format(remain_ball), True, PURPLE)remain_rect = remain_num.get_rect()remain_rect.center = (310, 380)screen.blit(remain_num, remain_rect)for ball in ball_group:if gaming:ball.move(angular_speed)ball.draw(screen)if not gaming:if stage_pass and stage < len(all_stage):button.set_text('下一关')elif stage_pass and stage >= len(all_stage):button.set_text('重新开始')elif not stage_pass:button.set_text('重玩此关')button.draw(screen)def main():global gaming, remain_ball, stagewhile True:if gaming:for event in pygame.event.get():if event.type == pygame.QUIT:pygame.quit()sys.exit()if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:if remain_ball > 0:new_ball = Ball(0)remain_ball -= 1if check_collide(new_ball):gaming = Falseelse:restart()game_stage()update()pygame.display.update()fclock.tick(fps)if __name__ == '__main__':game_init()main()

完整程序下载地址:Python版见缝插针小游戏源代码

Python版见缝插针小游戏源代码,球球旋转大作战源程序相关推荐

  1. Python版经典小游戏愤怒的小鸟源代码,基于pygame+pymunk

    Python版经典小游戏愤怒的小鸟源代码,基于pygame+pymunk 程序依赖:pygame2.0.1, pymunk5.5.0 直接运行main.py 完整代码下载地址:Python版经典小游戏 ...

  2. Python版儿童识字游戏源代码,结合植物大战僵尸和儿童识字的小游戏,含学习模式和娱乐模式

    Python版儿童识字游戏源代码,结合植物大战僵尸和儿童识字的小游戏,含学习模式和娱乐模式. 娱乐模式下,僵尸会头顶不同的汉字,此时屏幕会提示要消灭的汉字,移动豌豆消灭对应汉字的僵尸,如果攻击非提示汉 ...

  3. Python魂斗罗小游戏源代码

    Python魂斗罗小游戏源代码源程序,主程序Contra.py,游戏简易使用说明:A:向左,D:向右,W:跳起,S:趴下,J:射击,P:退出程序. 程序运行截图: Contra.py ''' 公众号: ...

  4. 网页版打地鼠小游戏源代码,网页版打灰太狼小游戏源码

    网页版打地鼠小游戏源代码,网页版打灰太狼小游戏源码 完整代码下载地址:网页版打地鼠小游戏源代码,网页版打灰太狼小游戏源码 核心代码 <!DOCTYPE html> <html> ...

  5. Python打砖块小游戏源代码

    这次用Python实现的是一个接球打砖块的小游戏,最核心的就是:碰撞检测的数学模型 程序运行截图 其实,编程问题到最后就是数学问题,这个游戏涉及到2D圆形与矩形的碰撞检测问题: 碰撞检测原理:通过找出 ...

  6. python推箱子小游戏源代码_Python制作推箱子小游戏

    开发工具 Python版本:3.6.4 相关模块: pygame模块: 以及一些Python自带的模块. 环境搭建 安装Python并添加到环境变量,pip安装需要的相关模块即可. 原理简介 游戏简介 ...

  7. python打字游戏增加开始页面_Python实践项目大全之Python打字练习小游戏源代码

    from tkinter import *import randomimport stringfrom datetime import datetimeroot = Tk()root.title(&q ...

  8. Python地雷战小游戏源代码

    Python版地道战小游戏源代码,游戏中寻找所需要的五种合成地雷的原材料,并躲避敌人的抓捕,雷可以炸死敌方.程序运行截图: 主要程序代码: tunnel_war_game.py import pyga ...

  9. python双手打字_Python打字练习小游戏源代码

    Python打字练习小游戏源代码 Python代码狂人 Python代码大全 Python打字练习小游戏源程序,随机产生一串字符,可对打字练习的正确率和时间进行统计,运行截图如下: from tkin ...

最新文章

  1. java opengl书_GitHub - cy-cyx/OpenGlDome: OpenGl的使用练习(安卓 Java opengl3.0)
  2. Python——raise引发异常
  3. 腾讯8篇AI医疗论文入选国际学术顶会,涵盖癌症图像分类、CT病灶检测等领域...
  4. DFT实训教程笔记4(bibili版本)- ATPG
  5. iOS再现安全漏洞 “1970变砖”问题仍未解决
  6. js,jquery字符串转换json,兼容各种浏览器
  7. [USACO15FEB]Superbull (最小生成树)
  8. 鸿蒙系统太烂,一加终于觉醒!变相承认系统太烂,魅族的吐槽一针见血
  9. 哈佛大学计算机生物科学,生命科学专业
  10. java 静态变量的使用_java的static静态变量是不是不安全的?应该如何正确的使用他呢...
  11. 技术干货丨隐私保护下的迁移算法
  12. IT入门?推荐首选学习HTML5大前端
  13. Netflix:当你按下“播放”的时候发生了什么?
  14. 启动XP出现“Operating System Not Found”
  15. 应用程式中夜间模式的Android DayNight主题
  16. eclipse汉化方法取消汉化退回英文版
  17. thinkphp5json对象转数组
  18. C语言:实数类型。2021-02-15
  19. IP变更导致redis集群不可用解决办法
  20. c语言如何宏定义枚举型结构体,C语言学习笔记--枚举结构体

热门文章

  1. ernieSAGE:PGL at TextGraphs 2020 Shared Task: Explanation Regeneration using Language and Graph Lear
  2. c语言与汇编语言混合编程
  3. 视觉定位毕设项目日记 2
  4. 在学生信息结构体中再添加一个计算平均值和按照平均值排序以及删除指定学号的学生信息
  5. 合肥师范学院计算机科学与技术专业怎么样,2021年合肥师范学院专业排行榜,哪个专业就业比较好...
  6. 太阳能板清洗机器人科沃斯_科沃斯地宝说明书 清洁机器人介绍
  7. VS中sln和suo的区别
  8. 【HEC-RAS】05 特点、使用场景及防洪评价案例
  9. 纵横网络靶场社区 MMS协议分析
  10. GB28181SDK 开源源码