This commit is contained in:
parent
594492705a
commit
f2581a10ac
1 changed files with 11 additions and 1 deletions
|
@ -13,6 +13,7 @@ class SnakeAnimation(BubaAnimation):
|
||||||
self.width = 20
|
self.width = 20
|
||||||
self.height = 4
|
self.height = 4
|
||||||
self.grid = []
|
self.grid = []
|
||||||
|
self.body = []
|
||||||
# 0:Space
|
# 0:Space
|
||||||
self.charset = " "
|
self.charset = " "
|
||||||
# 1:up 2:right 3:down 4:left
|
# 1:up 2:right 3:down 4:left
|
||||||
|
@ -37,10 +38,12 @@ class SnakeAnimation(BubaAnimation):
|
||||||
x = random.randrange(self.width)
|
x = random.randrange(self.width)
|
||||||
y = random.randrange(self.height)
|
y = random.randrange(self.height)
|
||||||
d = random.randrange(4)
|
d = random.randrange(4)
|
||||||
self.grid[y][x] = 1 + d
|
|
||||||
for r in range(self.height):
|
for r in range(self.height):
|
||||||
self.buba.simple_text(0, r, 0, "") # clear display
|
self.buba.simple_text(0, r, 0, "") # clear display
|
||||||
|
self.grid[y][x] = 1 + d
|
||||||
|
self.body.append((x, y))
|
||||||
self.render()
|
self.render()
|
||||||
|
iterations = 0
|
||||||
while True:
|
while True:
|
||||||
if self.is_blocked(x, y, d):
|
if self.is_blocked(x, y, d):
|
||||||
end = True
|
end = True
|
||||||
|
@ -59,6 +62,13 @@ class SnakeAnimation(BubaAnimation):
|
||||||
self.grid[y][x] = 5 + (d % 2)
|
self.grid[y][x] = 5 + (d % 2)
|
||||||
(x, y) = self.next(x, y, d)
|
(x, y) = self.next(x, y, d)
|
||||||
self.grid[y][x] = 1 + d
|
self.grid[y][x] = 1 + d
|
||||||
|
iterations += 1
|
||||||
|
self.body.append((x, y))
|
||||||
|
if iterations % 3 == 0:
|
||||||
|
(tx, ty) = self.body.pop(0)
|
||||||
|
self.grid[ty][tx] = 0
|
||||||
|
(tx, ty) = self.body[0]
|
||||||
|
self.grid[ty][tx] = 11
|
||||||
self.render()
|
self.render()
|
||||||
sleep(0.5)
|
sleep(0.5)
|
||||||
sleep(5)
|
sleep(5)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue