收藏 分销(赏)

python贪吃蛇设计报告_用Python写一个贪吃蛇.pdf

上传人:鱼** 文档编号:851943 上传时间:2024-03-29 格式:PDF 页数:3 大小:35.34KB
下载 相关 举报
python贪吃蛇设计报告_用Python写一个贪吃蛇.pdf_第1页
第1页 / 共3页
python贪吃蛇设计报告_用Python写一个贪吃蛇.pdf_第2页
第2页 / 共3页
点击查看更多>>
资源描述
python贪吃蛇设计报告_Python写个贪吃蛇#Write By Guobao#2017/4/7#贪吃蛇#做边界,*做物,o做体和头部#python 3.6.1importcopyimportrandomimportosimportmsvcrt#the board class,used to put everythingclassboard:_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)defgetPoint(self,location):return self._pointslocation0location1defclear(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)defput_snake(self,snake_locations):#clear the boardself.clear()#put the snake pointsfor x insnake_locations:self._pointsx0 x1=o#the headx=snake_locationslen(snake_locations)-1self._pointsx0 x1=Odefput_food(self,food_location):self._pointsfood_location0food_location1=*defshow(self):os.system(cls)for i in range(22):for j in range(22):print(self._pointsij,end=)print()#the snake classclasssnake:_points=def _init_(self):for i in range(1,6):self._points.append(1,i)defgetPoints(self):return self._points#move to the next position#give the next headdefmove(self,next_head):self._points.pop(0)self._points.append(next_head)#eat the food#give the next headdefeat(self,next_head):self._points.append(next_head)#calc the next state#and return the directiondef next_head(self,direction=default):#need to change the value,so copy ithead=copy.deepcopy(self._pointslen(self._points)-1)#calc the default directionif direction=default:neck=self._pointslen(self._points)-2if neck0 head0:direction=upelif neck0direction=downelif neck1 head1:direction=leftelif neck1=15:self.show()print(Good Job)breakelse:self.new_food()self.show()#反向Q神仙elif new_head=self.snake.getPoints()len(self.snake.getPoints()-2:pass#rush the wallelif self.board.getPoint(new_head)=#or self.board.getPoint(new_head)=o:print(GG)break#normal moveelse:self.snake.move(new_head)self.show()op=msvcrt.getch()game().run()
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传
相似文档                                   自信AI助手自信AI助手

当前位置:首页 > 通信科技 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2025 宁波自信网络信息技术有限公司  版权所有

客服电话:4009-655-100  投诉/维权电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服