-
Notifications
You must be signed in to change notification settings - Fork 1
/
game.py
101 lines (84 loc) · 3.54 KB
/
game.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
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import engine
from vector import Vector
from pirate import Pirate
class Game:
MAX_AMOUNT_OF_PIRATES=6;
direaction = {
"0" : Vector(0,0 ) ,
"e" : Vector(1, 0) ,
"w" : Vector(-1,0),
"n" : Vector(0 ,1),
"s" : Vector(0,-1) }
'each player has his own "game" instanse'
def __init__(self ,player):
''' * engine is the phsical world that stores all the ships and islands.
* player is the instanse that this game belongs to.'''
self.player = player
def get_my_pirates(self):
'returns all of the pirates belonging to that player '
return [i for i in self.player._pirates if i in engine.living_pirates]
def get_my_dead_pirates(self):
'returns a list with all dead pirates'
return [i for i in self.player._pirates if i in engine.dead_pirates]
def get_enemy_pirates(self):
'returns all the enemy pirates'
enemy= list()
for player in engine.players:
if player != self.player:
enemy+=player._pirates
return enemy
def get_islands(self):
'returns all islands'
return engine.islands
def get_my_islands(self):
'returns all of the islands that belong to this player'
return [i for i in engine.islands if i.get_owner() == self.player]
def get_not_my_islands(self):
'returns all of the islands that do not belong to this players'
return [i for i in engine.islands if i.get_owner() != self.player]
def get_enemy_islands(self):
return [i for i in engine.islands if ((i.get_owner() != self.player) and (i.get_owner() != None)) ]
def set_sail(self,pirate,direaction):
if not isinstance(direaction , list):
direaction = [direaction]
for dire in direaction:
for p in engine.pirates:
if p.uniq != pirate.uniq :
p_next_location = p.location + Game.direaction[p.current_direaction]
if pirate.location+Game.direaction[dire] == p_next_location:
direaction.remove(dire)
break
if len(direaction) > 0 :
direaction = direaction[0]
pirate.current_direaction = direaction
direaction=Game.direaction[direaction]
engine.tasks.append(('MOVE',pirate,direaction))
return True
else :
return False
def get_directions(self,obja,objb):
toret=list()
num_of_south = obja.location.y - objb.location.y
num_of_north = objb.location.y - obja.location.y
num_of_east = objb.location.x - obja.location.x
num_of_weast = obja.location.x - objb.location.x
if num_of_south > 0 :
toret += (['s'] * num_of_south)
if num_of_weast > 0:
toret += (['w'] * num_of_weast)
if num_of_north > 0:
toret += (['n'] * num_of_north)
if num_of_east > 0 :
toret += (['e'] * num_of_east)
'''
for dire in toret:
for p in engine.pirates:
if p.uniq != obja.uniq :
p_next_location = p.location + Game.direaction[p.current_direaction]
if obja.location+Game.direaction[dire]== p_next_location:
toret.remove(dire)
break
if isinstance(obja ,Pirate) and len(toret) > 0:
obja.current_direaction = toret[0]
'''
return toret