Skip to content
This repository has been archived by the owner on Feb 12, 2018. It is now read-only.

Commit

Permalink
Alcoholic behaviour is improved
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderTolmachev committed Dec 9, 2012
1 parent 8adeb66 commit 08f70f1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
5 changes: 5 additions & 0 deletions tolmachev_co/actors/alcoholic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from actors.actor import Actor
from actors.bottle import Bottle

class AlcoholicState:
AWAKE = 1
Expand Down Expand Up @@ -28,5 +29,9 @@ def has_bottle(self):
def make_asleep(self):
self.__current_state = AlcoholicState.SLEEPING

def drop_a_bottle(self):
self.__has_bottle = False
return Bottle()

def draw(self):
print 'A',
23 changes: 23 additions & 0 deletions tolmachev_co/actors/visitors/actor_drawing_visitor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from actors.visitors.actor_visitor import ActorVisitor

class ActorDrawingVisitor(ActorVisitor):
def visit_alcoholic(self, alcoholic):
print 'A',

def visit_beggar(self, beggar):
print 'B',

def visit_pillar(self, pillar):
print '|',

def visit_lamp(self, lamp):
print 'O',

def visit_bottle(self, bottle):
print '~',

def visit_policeman(self, policeman):
print 'P',

def visit_tavern(self, tavern):
pass
6 changes: 3 additions & 3 deletions tolmachev_co/actors/visitors/actor_moving_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import random
from map.coordinate import Coordinate


class ActorMovingVisitor(ActorVisitor):
class MovingDirection:
UP = 0
Expand Down Expand Up @@ -40,8 +39,9 @@ def should_drop_a_bottle():
if not self.__map.has_actor_at(new_coord):
self.__map.remove(coordinate)
self.__map.put(new_coord, alcoholic)
if should_drop_a_bottle():
self.__map.put(coordinate, Bottle())
if should_drop_a_bottle() and alcoholic.has_bottle():
bottle = alcoholic.drop_a_bottle()
self.__map.put(coordinate, bottle)
else:
actor = self.__map.get(new_coord)
if isinstance(actor, Bottle) or isinstance(actor, Pillar) or\
Expand Down
6 changes: 4 additions & 2 deletions tolmachev_co/map/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from actors.pilllar import Pillar
from actors.policeman import Policeman
from actors.tavern import Tavern
from actors.visitors.actor_drawing_visitor import ActorDrawingVisitor
from actors.visitors.actor_moving_visitor import ActorMovingVisitor
from coordinate import Coordinate

Expand Down Expand Up @@ -31,14 +32,15 @@ def remove(self, coordinate):
del self.__actors_dictionary[coordinate]

def draw(self):
drawing_visitor = ActorDrawingVisitor()
for y in xrange(0, self.__height):
for x in xrange(0, self.__width):
coordinate = Coordinate(x, y)
if coordinate in self.__actors_dictionary:
actor = self.__actors_dictionary[coordinate]
actor.draw()
actor.accept_visitor(drawing_visitor)
else:
print ' ',
print '_',
print

def next_move(self):
Expand Down

0 comments on commit 08f70f1

Please sign in to comment.