forked from andrejbauer/snakes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbolivianAnaconda.py
34 lines (29 loc) · 1.13 KB
/
bolivianAnaconda.py
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
import random
from snake import *
# Barva glave in repa
COLOR_HEAD = 'red'
COLOR_TAIL = 'orange'
class BolivianAnaconda(Snake):
def __init__(self, field, x, y, dx, dy):
# Poklicemo konstruktor nadrazreda
Snake.__init__(self,
field = field,
color_head = COLOR_HEAD,
color_tail = COLOR_TAIL,
x = x, y = y, dx = dx, dy = dy)
# V konstruktor lahko dodate se kaksne atribute
def turn(self):
"""Igrica poklice metodo turn vsakic, preden premakne kaco. Kaca naj se tu odloci, ali se
bo obrnila v levo, v desno, ali pa bo nadaljevala pot v isti smeri.
* v levo se obrne s self.turn_left()
* v desno se obrne s self.turn_right()
* koordinate glave so self.coords[0]
* smer, v katero potuje je (self.dx, self.dy)
* spisek koordinat vseh misk je self.field.mice.keys()
* spisek vseh kac je self.field.snakes
"""
if random.randint(0,10) < 5:
if random.randint(0,1) == 1:
self.turn_left()
else:
self.turn_right()