10个python经典小游戏(上)

您所在的位置:网站首页 python初中生简单项目 10个python经典小游戏(上)

10个python经典小游戏(上)

2024-07-13 07:14:09| 来源: 网络整理| 查看: 265

🐚作者简介:苏凉(专注于网络爬虫,数据分析) 🐳博客主页:苏凉.py的博客 👑名言警句:海阔凭鱼跃,天高任鸟飞。 📰要是觉得博主文章写的不错的话,还望大家三连支持一下呀!!! 👉关注✨点赞👍收藏📂

这些游戏你玩过几个? 1.贪吃蛇2.吃豆人3.加农炮4.四子棋5. Fly Bird6.记忆:数字对拼图游戏(欢迎挑战!用时:2min)7.乒乓球8.上课划水必备-井字游戏(我敢说100%的人都玩过)9.将数字滑动到位的拼图游戏10.迷宫(我己经晕了,你们来) 结语

1.贪吃蛇

👉游戏规则:使用方向键控制蛇去吃球。每吃一次球,蛇身就长出一格。吃到自己或者出界游戏结束。

from random import randrange from turtle import * from freegames import square, vector food = vector(0, 0) snake = [vector(10, 0)] aim = vector(0, -10) def change(x, y): """Change snake direction.""" aim.x = x aim.y = y def inside(head): """Return True if head inside boundaries.""" return -200 'red': 'yellow', 'yellow': 'red'} state = {'player': 'yellow', 'rows': [0] * 8} def grid(): """Draw Connect Four grid.""" bgcolor('light blue') for x in range(-150, 200, 50): line(x, -200, x, 200) for x in range(-175, 200, 50): for y in range(-175, 200, 50): up() goto(x, y) dot(40, 'white') update() def tap(x, y): """Draw red or yellow circle in tapped row.""" player = state['player'] rows = state['rows'] row = int((x + 200) // 50) count = rows[row] x = ((x + 200) // 50) * 50 - 200 + 25 y = count * 50 - 200 + 25 up() goto(x, y) dot(40, player) update() rows[row] = count + 1 state['player'] = turns[player] setup(420, 420, 370, 0) hideturtle() tracer(False) grid() onscreenclick(tap) done()

游戏演示:

在这里插入图片描述

5. Fly Bird

👉 游戏规则:点击屏幕来拍打鸟的翅膀。飞过屏幕被黑色乌鸦碰到,游戏结束。

from random import * from turtle import * from freegames import vector bird = vector(0, 0) balls = [] def tap(x, y): """Move bird up in response to screen tap.""" up = vector(0, 30) bird.move(up) def inside(point): """Return True if point on screen.""" return -200 1: 0, 2: 0} def move(player, change): """Move player position by change.""" state[player] += change def rectangle(x, y, width, height): """Draw rectangle at (x, y) with given width and height.""" up() goto(x, y) down() begin_fill() for count in range(2): forward(width) left(90) forward(height) left(90) end_fill() def draw(): """Draw game and move pong ball.""" clear() rectangle(-200, state[1], 10, 50) rectangle(190, state[2], 10, 50) ball.move(aim) x = ball.x y = ball.y up() goto(x, y) dot(10) update() if y 200: aim.y = -aim.y if x } neighbors = [ vector(100, 0), vector(-100, 0), vector(0, 100), vector(0, -100), ] def load(): """Load tiles and scramble.""" count = 1 for y in range(-200, 200, 100): for x in range(-200, 200, 100): mark = vector(x, y) tiles[mark] = count count += 1 tiles[mark] = None for count in range(1000): neighbor = choice(neighbors) spot = mark + neighbor if spot in tiles: number = tiles[spot] tiles[spot] = None tiles[mark] = number mark = spot def square(mark, number): """Draw white square with black outline and number.""" up() goto(mark.x, mark.y) down() color('black', 'white') begin_fill() for count in range(4): forward(99) left(90) end_fill() if number is None: return elif number 0.5: line(x, y, x + 40, y + 40) else: line(x, y + 40, x + 40, y) update() def tap(x, y): """Draw line and dot for screen tap.""" if abs(x) > 198 or abs(y) > 198: up() else: down() width(2) color('red') goto(x, y) dot(4) setup(420, 420, 370, 0) hideturtle() tracer(False) draw() onscreenclick(tap) done()

游戏演示:

在这里插入图片描述

结语

以上就是今天的小游戏分享了,后续出下篇。 关注我咱们下期再见!!



【本文地址】

公司简介

联系我们

今日新闻


点击排行

实验室常用的仪器、试剂和
说到实验室常用到的东西,主要就分为仪器、试剂和耗
不用再找了,全球10大实验
01、赛默飞世尔科技(热电)Thermo Fisher Scientif
三代水柜的量产巅峰T-72坦
作者:寞寒最近,西边闹腾挺大,本来小寞以为忙完这
通风柜跟实验室通风系统有
说到通风柜跟实验室通风,不少人都纠结二者到底是不
集消毒杀菌、烘干收纳为一
厨房是家里细菌较多的地方,潮湿的环境、没有完全密
实验室设备之全钢实验台如
全钢实验台是实验室家具中较为重要的家具之一,很多

推荐新闻


图片新闻

实验室药品柜的特性有哪些
实验室药品柜是实验室家具的重要组成部分之一,主要
小学科学实验中有哪些教学
计算机 计算器 一般 打孔器 打气筒 仪器车 显微镜
实验室各种仪器原理动图讲
1.紫外分光光谱UV分析原理:吸收紫外光能量,引起分
高中化学常见仪器及实验装
1、可加热仪器:2、计量仪器:(1)仪器A的名称:量
微生物操作主要设备和器具
今天盘点一下微生物操作主要设备和器具,别嫌我啰嗦
浅谈通风柜使用基本常识
 众所周知,通风柜功能中最主要的就是排气功能。在

专题文章

    CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭