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

Commit

Permalink
Merge branch 'tolmachev'
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderTolmachev committed Dec 9, 2012
2 parents fbf86d1 + eea37de commit 9779e5f
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 29 deletions.
3 changes: 0 additions & 3 deletions tolmachev_co/actors/actor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
class Actor:
def accept_visitor(self, visitor):
raise NotImplementedError("Abstract method is called")

def draw(self):
raise NotImplementedError("Abstract method is called")
6 changes: 4 additions & 2 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,6 @@ def has_bottle(self):
def make_asleep(self):
self.__current_state = AlcoholicState.SLEEPING

def draw(self):
print 'A',
def drop_a_bottle(self):
self.__has_bottle = False
return Bottle()
5 changes: 1 addition & 4 deletions tolmachev_co/actors/beggar.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,4 @@ def is_walking_with_a_bottle(self):
return self.__current_state == BeggarState.WALKING_WITH_A_BOTTLE

def is_in_tavern(self):
return self.__current_state == BeggarState.AT_THE_TAVERN

def draw(self):
print 'B',
return self.__current_state == BeggarState.AT_THE_TAVERN
3 changes: 0 additions & 3 deletions tolmachev_co/actors/bottle.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,3 @@
class Bottle (Actor):
def accept_visitor(self, visitor):
visitor.visit_bottle(self)

def draw(self):
print '~',
3 changes: 0 additions & 3 deletions tolmachev_co/actors/lamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,3 @@
class Lamp (Actor):
def accept_visitor(self, visitor):
visitor.visit_lamp(self)

def draw(self):
print 'o',
3 changes: 0 additions & 3 deletions tolmachev_co/actors/pilllar.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,3 @@
class Pillar (Actor):
def accept_visitor(self, visitor):
visitor.visit_pillar(self)

def draw(self):
print '|',
3 changes: 0 additions & 3 deletions tolmachev_co/actors/policeman.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,3 @@ def is_walking_to_alcoholic(self):

def is_walking_with_alcoholic(self):
return self.__current_state == PolicemanState.WALKING_WITH_ALCOHOLIC

def draw(self):
print 'P',
3 changes: 0 additions & 3 deletions tolmachev_co/actors/tavern.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ def __init__(self):
def accept_visitor(self, visitor):
visitor.visit_tavern(self)

def draw(self):
pass

def is_time_to_generate_alcoholic(self):
return self.__steps_number_after_alcoholic_generation == 0

Expand Down
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 9779e5f

Please sign in to comment.