-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv0-0.py
More file actions
58 lines (50 loc) · 1.45 KB
/
v0-0.py
File metadata and controls
58 lines (50 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from random import randrange
import pygame
import sys
pygame.init()
display = pygame.display.set_mode((10, 10))
velkost = 10
priestor = [" "] * velkost
hrac = "X"
okraj = "#"
posLO = velkost // 4
sirka = velkost // 2
posH = velkost // 2
priestor[posLO] = okraj
priestor[posLO + sirka] = okraj
priestor[posH] = hrac
hrame = True
skore = 0
def posunZnaku(pos, posun, znak, delta=0):
global priestor
if 0 <= pos + posun < velkost and 0 <= pos + posun + delta < velkost:
priestor[pos] = " "
priestor[pos + posun] = znak
return posun
return 0
while hrame:
skore += 1
hodiny = pygame.time.Clock()
print("|" + "".join(priestor) + "| " + str(skore))
for udalost in pygame.event.get():
if udalost.type == pygame.QUIT:
pygame.quit()
sys.exit()
if udalost.type == pygame.KEYDOWN:
if udalost.key == pygame.K_a:
posH += posunZnaku(posH, -1, hrac)
if udalost.key == pygame.K_d:
posH += posunZnaku(posH, 1, hrac)
zmena = randrange(-1, 2)
posunZnaku(posLO, zmena, okraj, sirka)
# priestor[posLO] = " "
# priestor[posLO + zmena] = okraj
posLO += posunZnaku(posLO + sirka, zmena, okraj, -sirka)
# priestor[posLO + sirka] = " "
# priestor[posLO + sirka + zmena] = okraj
# posLO += zmena
if hrac not in priestor:
print("havaria " + str(skore))
hrame = False
hodiny.tick(2)
pygame.quit()