介绍了Python贪吃蛇游戏的编写代码,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
代码如下:
# Write By Guobao
# 2017/4//7
#
# 贪吃蛇
# 用#做边界,*做食物,o做身体和头部
# python 3.6.1
import copy
import random
import os
import msvcrt
# the board class, used to put everything
class board:
__points =[]
def __init__(self):
self.__points.clear()
for i in range(22):
line = []
if i == 0 or i == 21:
for j in range(22):
line.append('#')
else:
line.append('#')
for j in range(20):
line.append(' ')
line.append('#')
self.__points.append(line)
def getPoint(self, location):
return self.__points[location[0]][location[1]]
def clear(self):
self.__points.clear()
for i in range(22):
line = []
if i == 0 or i == 21:
for j in range(22):
line.append('#')
else:
line.append('#')
for j in range(20):
line.append(' '</