请用PYTHON编一个小游戏,如五子棋,连连看,贪吃蛇,扫雷,计算器等等

麻烦给我一个.py的文件,有代码的,谢谢!好啦给高悬赏!... 麻烦给我一个.py的文件,有代码的,谢谢!
好啦给高悬赏!
展开
 我来答
百度网友87b2a52
推荐于2018-02-11 · 知道合伙人软件行家
百度网友87b2a52
知道合伙人软件行家
采纳数:523 获赞数:3490
毕业于南京大学,硕士学位。10年软件研发经验。现任信息系统架构师。

向TA提问 私信TA
展开全部
#!/usr/bin/python
from Tkinter import *
import random
class snake(Frame):
        def __init__(self, master=None):
                Frame.__init__(self, master)
                self.body = [(0,0)]
                self.bodyid = []
                self.food = [ -1, -1 ]
                self.foodid = -1
                self.gridcount = 10
                self.size = 500
                self.di = 3
                self.speed = 500
                self.top = self.winfo_toplevel()
                self.top.resizable(False, False)
                self.grid()
                self.canvas = Canvas(self)
                self.canvas.grid()
                self.canvas.config(width=self.size, height=self.size,relief=RIDGE)
                self.drawgrid()
                s = self.size/self.gridcount
                id = self.canvas.create_rectangle(self.body[0][0]*s,self.body[0][1]*s,
                        (self.body[0][0]+1)*s, (self.body[0][1]+1)*s, fill="yellow")
                self.bodyid.insert(0, id)
                self.bind_all("<KeyRelease>", self.keyrelease)
                self.drawfood()
                self.after(self.speed, self.drawsnake)
        def drawgrid(self):
                s = self.size/self.gridcount
                for i in range(0, self.gridcount+1):
                        self.canvas.create_line(i*s, 0, i*s, self.size)
                        self.canvas.create_line(0, i*s, self.size, i*s)
        def drawsnake(self):
                s = self.size/self.gridcount
                head = self.body[0]
                new = [head[0], head[1]]
                if self.di == 1:
                        new[1] = (head[1]-1) % self.gridcount
                elif self.di == 2:
                        new[0] = (head[0]+1) % self.gridcount
                elif self.di == 3:
                        new[1] = (head[1]+1) % self.gridcount
                else:
                        new[0] = (head[0]-1) % self.gridcount
                next = ( new[0], new[1] )
                if next in self.body:
                        exit()
                elif next == (self.food[0], self.food[1]):
                        self.body.insert(0, next)
                        self.bodyid.insert(0, self.foodid)
                        self.drawfood()
                else:
                        tail = self.body.pop()
                        id = self.bodyid.pop()
                        self.canvas.move(id, (next[0]-tail[0])*s, (next[1]-tail[1])*s)
                        self.body.insert(0, next)
                        self.bodyid.insert(0, id)
                self.after(self.speed, self.drawsnake)
        def drawfood(self):
                s = self.size/self.gridcount
                x = random.randrange(0, self.gridcount)
                y = random.randrange(0, self.gridcount)
                while (x, y) in self.body:
                        x = random.randrange(0, self.gridcount)
                        y = random.randrange(0, self.gridcount)
                id = self.canvas.create_rectangle(x*s,y*s, (x+1)*s, (y+1)*s, fill="yellow")
                self.food[0] = x
                self.food[1] = y
                self.foodid = id
        def keyrelease(self, event):
                if event.keysym == "Up" and self.di != 3:
                        self.di = 1
                elif event.keysym == "Right" and self.di !=4:
                        self.di = 2
                elif event.keysym == "Down" and self.di != 1:
                        self.di = 3
                elif event.keysym == "Left" and self.di != 2:
                        self.di = 4
app = snake()
app.master.title("Greedy Snake")
app.mainloop()

贪食蛇

dooodong
2013-05-20 · TA获得超过158个赞
知道答主
回答量:139
采纳率:100%
帮助的人:55.3万
展开全部
这些游戏都不小啊,很体现功力的。贪吃蛇好象看到过C语言版本的,python的应该了有。
不过很多需要先安装pygame包的。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2018-02-11
展开全部

五子棋、贪吃蛇、扫雷、俄罗斯方块、坦克大战、FlappyBird,

源码地址github

已赞过 已踩过<
你对这个回答的评价是?
评论 收起
chassic
2013-05-19
知道答主
回答量:1
采纳率:0%
帮助的人:1496
追问
你能帮我下了,在上传给我么?
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
eurasiazyl
2013-05-20
知道答主
回答量:8
采纳率:0%
帮助的人:8.3万
展开全部
这个真的没有,你百度吧
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
收起 更多回答(3)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式