-
Notifications
You must be signed in to change notification settings - Fork 3
/
action.py
88 lines (72 loc) · 2.72 KB
/
action.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
import pygame
import colors
import event as e
import flower
import manager
from terrain import Terrain
import unit
import rabbit
class Action( unit.Unit ):
def __init__( self, terrain, executor ):
unit.Unit.__init__( self, terrain )
self.active_listeners = manager.init_listener()
self.active_listeners.update( [
(e.FLOWER_SEED, self.action_seed),
(e.FLOWER_THORN, self.action_thorns),
(e.FLOWER_POISON, self.action_poison),
(e.FLOWER_CANCEL, self.action_cancel),
] )
self.executor = executor
manager.restore_default()
manager.update_current( unit.Unit.active().active_listeners )
def action_seed( self, event ):
if self.terrain.contains_unit(unit_type = flower.Flower):
return
elif self.terrain.contains_unit(unit_type = flower.Obstacle):
return
elif self.terrain.contains_unit(unit_type = rabbit.Rabbit):
self.terrain.say_unit().growth += 2
else:
flower.Flower( self.terrain )
self.delete( None )
e.Event( e.NEXT_ACTIVE )
def action_thorns( self, event ):
#if self.executor.growth < 3:
#return
if self.terrain.contains_unit(unit_type = flower.Flower):
return
elif self.terrain.contains_unit(unit_type = flower.Obstacle):
return
else:
#self.executor.growth -= 3
unit = flower.Thorn( self.terrain )
unit.counter = 3
self.delete( None )
e.Event( e.NEXT_ACTIVE )
def action_poison( self, event ):
#if self.executor.growth < 3:
#return
if self.terrain.contains_unit(unit_type = flower.Obstacle):
return
elif self.terrain.contains_unit(unit_type = flower.Flower):
#self.executor.growth -= 3
self.terrain.say_unit().counter = 5
self.terrain.say_unit().hit = 2
elif self.terrain.contains_unit(unit_type = rabbit.Rabbit):
#self.executor.growth -=3
self.terrain.say_unit().counter = 5
self.terrain.say_unit().hit = 2
else:
#self.executor.growth -= 3
unit = flower.Poison( self.terrain )
unit.counter = 5
self.delete( None )
e.Event( e.NEXT_ACTIVE )
def action_cancel( self, event ):
self.delete( None )
manager.restore_default()
manager.update_current( unit.Unit.active().active_listeners )
def draw( self, screen ):
if self is unit.Unit.active():
self.terrain.draw_border(screen, colors.BLUE)
self.executor.terrain.draw_border(screen, colors.RED)