求大神编一个python 200-300行的小游戏(比如贪食蛇 俄罗斯方块 剪刀石头布一类的)求速度 真的 就4天

作者&投稿:琦逸 (若有异议请与网页底部的电邮联系)
用java可以编写小游戏,比如连连看、五指棋、扫雷、剪刀石头布、贪食蛇、俄罗斯方块等,还有哪些?~

欢乐斗地主、纸牌

#!/usr/bin/pythonfrom Tkinter import *import randomclass 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("", 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 = 4app = snake()app.master.title("Greedy Snake")app.mainloop()贪食蛇

skier_images = ["skier_down.png", "skier_right1.png", "skier_right2.png",
"skier_left2.png", "skier_left1.png"]
# class for the skier sprite
class SkierClass(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load("skier_down.png")
self.rect = self.image.get_rect()
self.rect.center = [320, 100]
self.angle = 0

def turn(self, direction):
# load new image and change speed when the skier turns
self.angle = self.angle + direction
if self.angle < -2: self.angle = -2
if self.angle > 2: self.angle = 2
center = self.rect.center
self.image = pygame.image.load(skier_images[self.angle])
self.rect = self.image.get_rect()
self.rect.center = center
speed = [self.angle, 6 - abs(self.angle) * 2]
return speed

def move(self, speed):
# move the skier right and left
self.rect.centerx = self.rect.centerx + speed[0]
if self.rect.centerx < 20: self.rect.centerx = 20
if self.rect.centerx > 620: self.rect.centerx = 620

# class for obstacle sprites (trees and flags)
class ObstacleClass(pygame.sprite.Sprite):
def __init__(self, image_file, location, type):
pygame.sprite.Sprite.__init__(self) #call Sprite initializer
self.image_file = image_file
self.image = pygame.image.load(image_file)
self.location = location
self.rect = self.image.get_rect()
self.rect.center = location
self.type = type
self.passed = False

def scroll(self, terrainPos):
self.rect.centery = self.location[1] - terrainPos
# create one "screen" of terrain: 640 x 640
# use "blocks" of 64 x 64 pixels, so objects aren't too close together
def create_map(start, end):
obstacles = pygame.sprite.Group()
locations = []
gates = pygame.sprite.Group()
for i in range(10): # 10 obstacles per screen
row = random.randint(start, end)
col = random.randint(0, 9)
location = [col * 64 + 20, row * 64 + 20] #center x, y for obstacle
if not (location in locations): # prevent 2 obstacles in the same place
locations.append(location)
type = random.choice(["tree", "flag"])
if type == "tree": img = "skier_tree.png"
elif type == "flag": img = "skier_flag.png"
obstacle = ObstacleClass(img, location, type)
obstacles.add(obstacle)
return obstacles
# redraw the screen, including all sprites
def animate():
screen.fill([255, 255, 255])
pygame.display.update(obstacles.draw(screen))
screen.blit(skier.image, skier.rect)
screen.blit(score_text, [10, 10])
pygame.display.flip()
def updateObstacleGroup(map0, map1):
obstacles = pygame.sprite.Group()
for ob in map0: obstacles.add(ob)
for ob in map1: obstacles.add(ob)
return obstacles
# initialize everything
pygame.init()
screen = pygame.display.set_mode([640,640])
clock = pygame.time.Clock()
skier = SkierClass()
speed = [0, 6]
map_position = 0
points = 0
map0 = create_map(20, 29)
map1 = create_map(10, 19)
activeMap = 0
# group for all obstacles to do collision detection
obstacles = updateObstacleGroup(map0, map1)
# font object for score
font = pygame.font.Font(None, 50)
# main Pygame event loop
while True:
clock.tick(30)
for event in pygame.event.get():
if event.type == pygame.QUIT: sys.exit()
if event.type == pygame.KEYDOWN: # check for key presses
if event.key == pygame.K_LEFT: # left arrow turns left
speed = skier.turn(-1)
elif event.key == pygame.K_RIGHT: #right arrow turns right
speed = skier.turn(1)
skier.move(speed)
map_position += speed[1] # scroll the terrain

# manage terrain maps, switch between them,
# and create new terrain at the bottom
if map_position >=640 and activeMap == 0:
activeMap = 1
map0 = create_map(20, 29)
obstacles = updateObstacleGroup(map0, map1)
if map_position >=1280 and activeMap == 1:
activeMap = 0
for ob in map0:
ob.location[1] = ob.location[1] - 1280 # wrap around to top
map_position = map_position - 1280 #
map1 = create_map(10, 19)
obstacles = updateObstacleGroup(map0, map1)

for obstacle in obstacles:
obstacle.scroll(map_position)

# check for hitting trees or getting flags
hit = pygame.sprite.spritecollide(skier, obstacles, False)
if hit:
if hit[0].type == "tree" and not hit[0].passed: #crashed into tree
points = points - 100
skier.image = pygame.image.load("skier_crash.png") # crash image
animate()
pygame.time.delay(1000)
skier.image = pygame.image.load("skier_down.png") # resume skiing
skier.angle = 0
speed = [0, 6]
hit[0].passed = True
elif hit[0].type == "flag" and not hit[0].passed: # got a flag
points += 10
obstacles.remove(hit[0]) # remove the flag

score_text = font.render("Score: " +str(points), 1, (0, 0, 0))
animate()

图片自己找,滑雪人

好好学习,不抄作业

以发,请查收


pythson输入字符串,为其每个字符的ASCII码形成列表并输出
s=input("请输入字符串:")a=[]for i in s:a.append(ord(i))print(a)

pymouse库使用时提示ImportError: No module named 'windows'
这说明你没有安装win32api for python 去网站http:\/\/www.lfd.uci.edu\/~gohlke\/pythonlibs\/下载 你python几位我不知道,只知道是3.5,那就选cp35的两个试试看,运行pip install somefile.whl 注:somefile是上述两个文件之一,whl是一种zip压缩包格式,pip是包管理器,pip已经包含在你的python3....

大学生在读期间,如何考证?
第三个就是计算机证书,分为三个等级,一级为操作技能,就为平常的办公软件、图形图像软件等,二级为程序设计,办公软件高级应用级,三级为工程师预备级,面向职位的岗位专业技能,四级就是大神了,工程师级别,考核计算机专业课程,工程师岗位证书 计算机等级考试一级考试科目:算机基础及MS Office应用、计...

郴州市13747888095: 求帮我编一个简单的python程序 -
鱼炕得斯: #!/usr/bin/python def Test(): Ca=0.34 Cr=float(raw_input('Cr:')) m=float(raw_input('m:')) C=Cr-Ca if C<0.06 : print 'gas-emission scope error' else : Q=(60*m*C)/0.66 print Q T=float(raw_input('T:')) W=Q*T print W if "__main__"==__name__ : Test() 无聊随便写了下,结果没问题,自己可以润色下...

郴州市13747888095: 求python大神编写一段程序,要求如下:去除一段字符串中的数字,然后把字符按abcde...排序 -
鱼炕得斯: def f(s, c): count = 0 while len(s) > 0: index = s.find(c) if index == -1: break count += 1 s = s[index+len(c):] return count def g(s, c): cs = "" while True: cs += c count = f(s, cs) if count > 0: print count, cs else: break a="...

郴州市13747888095: 如何编写第一个python程序 -
鱼炕得斯: 现在,了解了如何启动和退出Python的交互式环境,我们就可以正式开始编写Python代码了.在写代码之前,请千万不要用“复制”-“粘贴”把代码从页面粘贴到你自己的电脑上.写程序也讲究一个感觉,你需要一个字母一个字母地把代码自...

郴州市13747888095: 大神帮我编个Python程序:写入URL即可保存图片(requests模块我有),或者教教我也行,怎么编? -
鱼炕得斯: 发get请求,根据contenttype,把爬下来的数据按照格式,二进制保存.

郴州市13747888095: python用for循环编程求1 - 200之间能被7整 除但不能同时被5整除的所有整数每行输出5个数字 -
鱼炕得斯: 1 2 3 4 5 6 7 8 9if__name__ =="__main__":t =0print("符合要抄求的2113整数5261有4102:1653")forind inrange(1, 201):ifind %7==0andind %5!=0:print(ind, end=" ")t +=1ift %5==0:print("\n")

郴州市13747888095: 用python编写一个程序 -
鱼炕得斯: lst_q = [3, -4, 1, 0, -1, 0, 5, 7, -9, -1000] lst_negative = [] lst_zero = [] lst_positive = [] for i in lst_q: if ilst_negative.append(i) elif i == 0: lst_zero.append(i) else: lst_positive.append(i) print(lst_negative) print(lst_zero) print(lst_positive) 》》》》[-4, -1, -9, -1000] [0, 0] [3, 1, 5, 7]

郴州市13747888095: 求出2到200之间的素数并按5个一行输出 -
鱼炕得斯: 1、一个N值,从2到N遍历取模,如果可以取余,就不是素数. 2、python实例 #!/usr/bin/python def is_prime(num):res=Truefor x in range(2,num-1):if num%x==0:res=Falsereturn resreturn res for x in range(2,1000):if is_prime(x):print x 3...

郴州市13747888095: 求大神帮忙,编写程序,统计200到400所有满足三个数字之积为42,三个数字之和为12的数的个数! -
鱼炕得斯: include include void main() { int i,j,k; int num=0; for(i=2;i for(j=0;j for(k=0;k { if (i*j*k == 42) && (i+j+k == 12){ num++; printf("%d\t",i*100+j*10+k); // 将该三位数打印出来,数之间间隔一个TAB以方便查看 if (num%5 == 0) printf("\n"); // 每行打印5个数,以使打印的数据看起来整齐美观 } } printf("\n"); printf("Total: %d\n",num); // 打印统计的结果 }

郴州市13747888095: 求一段Python编程语言 求设计一段Python编程语言,解答下列问题. 输入两个点,建立起直线 -
鱼炕得斯: 回炉了一下几何,图形学用到 import math class Point:def __init__(self):self.x=0self.y=0def input(self,pname):self.x=int(input("Enter the x of point {0}: ".format(pname)))self.y=int(input("Enter the y of point {0}: ".format(pname))) a=Point() ...

郴州市13747888095: 求一个Python编的小程序,
鱼炕得斯: 用什么?tkinter、pyQt、GTK、wxPython...都可以写

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网