-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathName.py
More file actions
62 lines (52 loc) · 1.52 KB
/
Name.py
File metadata and controls
62 lines (52 loc) · 1.52 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
59
60
61
62
import os
import time
import msvcrt
def main():
score = 0
height = 10
width = 40
dino_y = height - 1
cactus_x = width - 1
gameover = False
jump_stage = 0
while not gameover:
if msvcrt.kbhit():
key = msvcrt.getch()
if key == b' ' and dino_y == height - 1:
jump_stage = 1
if jump_stage > 0:
if jump_stage <= 4: dino_y = height - 2
elif jump_stage <= 8: dino_y = height - 3
elif jump_stage <= 12: dino_y = height - 2
else:
dino_y = height - 1
jump_stage = 0
if jump_stage != 0: jump_stage += 1
else:
dino_y = height - 1
cactus_x -= 1
if cactus_x < 0:
cactus_x = width - 1
score += 1
if cactus_x == 0 and dino_y == height - 1:
gameover = True
output = []
for i in range(height):
line = ""
for j in range(width):
if i == dino_y and j == 0:
line += "O"
elif i == height - 1 and j == cactus_x:
line += "X"
elif i == height - 1:
line += "-"
else:
line += " "
output.append(line)
os.system('cls')
print("\n".join(output))
print(f"Score: {score}")
time.sleep(0.05)
print(f"Game over! Your score is {score}.")
if __name__ == "__main__":
main()