-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathgame.py
More file actions
41 lines (33 loc) · 879 Bytes
/
Copy pathgame.py
File metadata and controls
41 lines (33 loc) · 879 Bytes
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
import curses
import time
import sys
from random import randint
from classes import Field
from classes import Snake
def main(screen):
# Configure screen
screen.timeout(0)
# Init snake & field
field = Field(10)
snake = Snake("Joe")
snake.set_field(field)
speed = 0.4
while(True):
# Get last pressed key
ch = screen.getch()
if ch != -1:
# If some arrows did pressed - change direction
snake.set_direction(ch)
# Move snake
hit = snake.move()
if hit == 1:
# we ate a food
if randint(1,10) > 6:
# incrase speed every now and then...
speed -= 0.05
# Render field
field.render(screen)
screen.refresh()
time.sleep(speed)
if __name__=='__main__':
curses.wrapper(main)