Chtěl bych poprosit o nějakou konstruktivní kritiku k mé "hře" ...
# -*- coding: cp1250 -*-
import pygame, sys
from pygame.locals import *
import math
import random
import time
pygame.init()
obrazovka = pygame.display.set_mode((501, 501))
pygame.display.set_caption("Polarski´s green Snake")
pygame.draw.polygon(obrazovka, pygame.color.Color("white"), [[0,0], [501,0], [501,501], [0,501]])
class Clanky:
def __init__(self, X, Y, xove, yove, pohyby, barva):
self.X=X
self.Y=Y
self.xove = xove
self.yove = yove
self.pohyby = pohyby
self.barva = barva
def ctverec(x1, x2, y1, y2, barva):
pygame.draw.polygon(obrazovka, barva, [[x1,y1], [x2,y1], [x2,y2], [x1,y2]])
def text(co, velikost, xove, yove, barva, rotace):
Fnt = pygame.font.SysFont("Times New Roman", velikost, bold=0, italic=0)
osd = Fnt.render (co, 0, barva)
osd=pygame.transform.rotate(osd, rotace)
obrazovka.blit(osd, (xove, yove))
poprve = 0
def start():
global poprve
global body
global clanky
global korist
global cas
barvy=["Polarski´s green Snake"]
stisknuto=0
pygame.draw.polygon(obrazovka, pygame.color.Color("white"), [[0,0], [501,0], [501,501], [0,501]])
text(u"Polarski´s", 55, 35, 15, [0,110,0], 0)
text(u"green", 55, 265, 48, [0,180,0], -90)
text(u"Snake", 55, 285, 170, [165,255,165], 0)
text(u"2008", 20, 390, 90, [0,0,0], -90)
text(u"Start", 20, 80, 115, [0,0,0], 0)
text(u"Konec", 20, 150, 185, [0,0,0], 0)
text(u"Den za dnem plouží se tak mdlý, tak mdlý, ...", 20, 45, 265, [0,0,0], 0)
text(u"A duše znavena se smutkem všeho splývá.", 20, 105, 290, [0,0,0], 0)
text(u"Získali jste :", 35, 100, 350, [0,0,0], 0)
if poprve==0:
text(u"0 bodů", 35, 220, 400, [0,0,0], 0)
else:
text(str(body)+u" bodů", 35, 220, 400, [0,0,0], 0)
pygame.display.update()
while 1:
for udalost in pygame.event.get():
"Nevim"
poz=pygame.mouse.get_pos()
print poz
if pygame.mouse.get_pressed()[0]==1:
if poz[0]> 75 and poz[0]< 120 and poz[1]> 120 and poz[1]< 140:
break
elif poz[0]> 145 and poz[0]< 200 and poz[1]> 190 and poz[1]< 250:
sys.exit()
body=5
clanky = []
for n in range(5):
c=Clanky(10-n, 10, 1, 0, [], "nic")
##c.pohyby.append([15-n, 0, 1])
clanky.append(c)
for c in clanky:
if clanky.index(c)>len(clanky)/2:
cervena=((255/(len(clanky)/2))*clanky.index(c))/2
c.barva=[int(cervena), 255, int(cervena)]
else:
zelena=((255/(len(clanky)/2))*clanky.index(c))
c.barva=[0, int(zelena), 0]
korist=[12, 12]
cas=0
for r in range(25):
pygame.draw.aaline(obrazovka, pygame.color.Color("grey"), [r*20,0], [r*20,501])
pygame.draw.aaline(obrazovka, pygame.color.Color("grey"), [0,r*20], [501,r*20])
start()
delitel=3
stisknuto = 0
while 1:
dobaTrvani=time.time()
pygame.draw.polygon(obrazovka, pygame.color.Color("white"), [[0,0], [501,0], [501,501], [0,501]])
for r in range(25):
pygame.draw.aaline(obrazovka, pygame.color.Color("grey"), [r*20,0], [r*20,501])
pygame.draw.aaline(obrazovka, pygame.color.Color("grey"), [0,r*20], [501,r*20])
if cas%delitel==0:
for c in clanky:
for n in c.pohyby:
if n[0]==0:
c.xove=n[1]
c.yove=n[2]
n[0]=n[0]-1
for n in c.pohyby:
if n[0]<0:
c.pohyby.remove(n)
c.X=c.X+c.xove
c.Y=c.Y+c.yove
if cas%delitel==0:
if clanky[0].X==korist[0] and clanky[0].Y==korist[1]:
body=body+1
d=Clanky(clanky[-1].X-clanky[-1].xove, clanky[-1].Y-clanky[-1].yove, clanky[-1].xove, clanky[-1].yove, [], "nic")
for [x,y,z] in clanky[-1].pohyby:
d.pohyby.append([x+1,y,z])
clanky.append(d)
while 1:
for udalost in pygame.event.get():
"Nevim"
x=random.randint(0,24)
y=random.randint(0,24)
jo=0
for c in clanky:
if x==c.X and y==c.Y:
jo=1
break
if jo==0:
korist=[x,y]
break
for c in clanky:
if clanky.index(c)>len(clanky)/2:
cervena=((255/(len(clanky)/2))*clanky.index(c))/2
c.barva=[int(cervena), 255, int(cervena)]
else:
zelena=((255/(len(clanky)/2))*clanky.index(c))
c.barva=[0, int(zelena), 0]
ctverec((20*korist[0])+1, (20*korist[0])+19, (20*korist[1])+1, (20*korist[1])+19, [0, 0, 0])
for c in clanky:
ctverec((20*c.X)+1, (20*c.X)+19, (20*c.Y)+1, (20*c.Y)+19, c.barva)
ctverec((20*clanky[0].X)+1, (20*clanky[0].X)+19, (20*clanky[0].Y)+1, (20*clanky[0].Y)+19, [255, 0, 0])
ctverec((20*clanky[-1].X)+8, (20*clanky[-1].X)+13, (20*clanky[-1].Y)+8, (20*clanky[-1].Y)+13, [255, 0, 0])
text(str(body), 40, 10, 10, [0,0,0], 0)
for udalost in pygame.event.get():
"Nevim"
##-------------ZADAVANI-SMERU------------------------------------------------------------------##
if pygame.key.get_pressed()[K_RIGHT]==1 and clanky[0].xove==0 and [0, 1, 0] not in clanky[0].pohyby:
poradi=0
for c in clanky:
c.pohyby.append([poradi, 1, 0])
poradi=poradi+1
elif pygame.key.get_pressed()[K_LEFT]==1 and clanky[0].xove==0 and [0, -1, 0] not in clanky[0].pohyby:
poradi=0
for c in clanky:
c.pohyby.append([poradi, -1, 0])
poradi=poradi+1
elif pygame.key.get_pressed()[K_DOWN]==1 and clanky[0].yove==0 and [0, 0, 1] not in clanky[0].pohyby:
poradi=0
for c in clanky:
c.pohyby.append([poradi, 0, 1])
poradi=poradi+1
elif pygame.key.get_pressed()[K_UP]==1 and clanky[0].yove==0 and [0, 0, -1] not in clanky[0].pohyby:
poradi=0
for c in clanky:
c.pohyby.append([poradi, 0, -1])
poradi=poradi+1
##-------------ZADAVANI-SMERU-KONEC-----------------------------------------------------------------##
if cas%delitel==0:
for c in clanky:
for d in clanky:
if c!=d:
if c.X==d.X and c.Y==d.Y:
poprve=1
start()
for c in clanky:
if c.X>24 or c.X<0 or c.Y>24 or c.Y<0:
poprve=1
start()
if pygame.key.get_pressed()[K_SPACE]==0 and stisknuto==1:
text("Pauza", 30, 85, 20, [0,0,0], 0)
pygame.display.update()
stisknuto=0
while 1:
for udalost in pygame.event.get():
"Nevim"
if pygame.key.get_pressed()[K_SPACE]==0 and stisknuto==1:
break
if pygame.key.get_pressed()[K_SPACE]==1:
stisknuto=1
else:
stisknuto=0
if pygame.key.get_pressed()[K_SPACE]==1:
stisknuto=1
else:
stisknuto=0
cas=cas+1
pockat=(10-(time.time()-dobaTrvani))/1000.0
time.sleep(pockat)
pygame.display.update()
programováno v python 2.4, pygame 1.7