-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChicken.py
39 lines (30 loc) · 1006 Bytes
/
Chicken.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
35
36
37
import Yard
import random
class Chicken:
def __init__(self, yard: Yard, name, color, x, y):
self.yard = yard
self.name = name
self.color = color
self.x = x
self.y = y
def __str__(self):
return self.name + '(' + str(self.x) + ',' + str(self.y) + ')'
def step(self):
xMove = random.randint(-1, 1)
yMove = random.randint(-1, 1)
self.x += xMove
self.y += yMove
if self.x < 0:
self.x = 0
elif self.x > self.yard.width:
self.x = self.yard.width
if self.y < 0:
self.y = 0
elif self.y > self.yard.lenght:
self.y = self.yard.lenght
def getSamePositionChickens(self):
samePositionChickens = []
for chick in self.yard.chickens:
if chick != self and chick.x == self.x and chick.y == self.y and type(chick) is Chicken:
samePositionChickens.append(chick)
return samePositionChickens