资源简介
基于python2的源码,python3无法使用
贪吃蛇小游戏源码
代码片段和文件信息
from Tkinter import *
import tkMessageBoxsys
from random import randint
class Grid(object):
def __init__(selfmaster=Nonewindow_width=800window_height=600grid_width=50offset=10):
self.height = window_height
self.width = window_width
self.grid_width = grid_width
self.offset = offset
self.grid_x = self.width/self.grid_width
self.grid_y = self.height/self.grid_width
self.bg = “#EBEBEE“
self.canvas = Canvas(master width=self.width+2*self.offset height=self.height+2*self.offset bg=self.bg)
self.canvas.pack()
self.grid_list()
def draw(self pos color):
x = pos[0]*self.grid_width + self.offset
y = pos[1]*self.grid_width + self.offset
self.canvas.create_rectangle(x y x+self.grid_width y+self.grid_widthfill=coloroutline=self.bg)
def grid_list(self):
grid_list = []
for y in range(0self.grid_y):
for x in range(0self.grid_x):
grid_list.append((xy))
self.grid_list = grid_list
class Food(object):
def __init__(self Grid):
self.grid = Grid
self.color = “#23D978“
self.set_pos()
def set_pos(self):
x = randint(0self.grid.grid_x - 1)
y = randint(0self.grid.grid_y - 1)
self.pos = (x y)
def display(self):
self.grid.draw(self.posself.color)
class Snake(object):
def __init__(self Grid):
self.grid = Grid
self.body = [(106)(107)(108)]
self.direction = “Up“
self.status = [‘run‘‘stop‘]
self.speed = 300
self.color = “#5FA8D9“
self.food = Food(self.grid)
self.display_food()
self.gameover = False
self.score = 0
def available_grid(self):
return [i for i in self.grid.grid_list if i not in self.body[2:]]
def change_direction(self direction):
self.direction = direction
def display(self):
for (xy) in self.body:
self.grid.dr
- 上一篇:python实现logistics的分叉图
- 下一篇:nulindai.py
相关资源
- python实现logistics的分叉图
- 对任意关键字爬虫对应图片代码
- 图虫网爬虫python实现
- 网站图片爬取代码
- SIFT算法特征提取的python实现
- 已知两点经纬度坐标,求距离函数
- 最新Python3.6网络爬虫实战案例5章(基
- 一个简单的全覆盖路径规划python
- 徐州地区及周边范围noaa气象数据数据
- python五子棋代码
- 社区发现算法 加权GN算法的Python实现
- 基于用户协同过滤usercf的python代码实
- 21天学通python.txt
- python实现视频直播
- python QQ第三方登陆
- tensorflow2.0实现mnist手写数字识别代码
- Python源码剖析_代码(pythonympx.rar)
- 豆瓣爬虫python
- 计算机视觉视频教程百度云盘资源
- Shapely-1.6.4.post1-cp36-cp36m-win_amd64.whl
- 回声状态网络源码实现
- python 战棋游戏六边形地图代码实现
- naive bayes代码实现(python版)
- springcloudpython
- MODIS_Mosaic.py
- 经典动量与反转交易策略python版
- Python习题集含答案
- Python实现一个简单的3层BP神经网络
- python-urx-master.zip
- Python3.x+Pyqt5实现绘图界面matplotlib绘图
评论
共有 条评论