def test_lion_full_creation(self):
     try:
         lion = l.Lion(s.full)
         self.assertEqual(s.full, lion.state, 'Wrong state of created lion')
         self.assertEqual(None, lion.action, 'Wrong action of created lion')
     except ValueError:
         self.fail("Exception during lion creation")
 def test_input_objects_on_full_lion(self):
     lion = l.Lion(s.full)
     objects = [o.antelope, o.hunter, o.hunter, o.antelope, o.tree, o.antelope, o.antelope]
     try:
         for ob in objects:
             lion.meet(ob)
     except:
         self.fail('Exception on correct input')
Esempio n. 3
0
 def main(self):
     WillieWolf = Wolf(FeedWithFear)
     WhinnyWolf = Wolf(FeedWithFear)
     CarlCat = Cat()
     CindyCat = Cat()
     DougDog = Dog(FeedWithCare)
     DippyDog = Dog(FeedWithCare)
     EllyElephant = Elephant()
     EarlElephant = Elephant()
     HarryHippo = Hippo()
     HenryHippo = Hippo()
     LillyLion = Lion()
     LarryLion = Lion()
     RyanRhino = Rhino()
     RandyRhino = Rhino()
     TonyTiger = Tiger()
     TimmyTiger = Tiger()
     ZaneZooKeeper = ZooKeeper()
     ZaneZooKeeper.Add(WillieWolf)
     ZaneZooKeeper.Add(WhinnyWolf)
     ZaneZooKeeper.Add(CarlCat)
     ZaneZooKeeper.Add(CindyCat)
     ZaneZooKeeper.Add(DougDog)
     ZaneZooKeeper.Add(DippyDog)
     ZaneZooKeeper.Add(EllyElephant)
     ZaneZooKeeper.Add(EarlElephant)
     ZaneZooKeeper.Add(HarryHippo)
     ZaneZooKeeper.Add(HenryHippo)
     ZaneZooKeeper.Add(LillyLion)
     ZaneZooKeeper.Add(LarryLion)
     ZaneZooKeeper.Add(RyanRhino)
     ZaneZooKeeper.Add(RandyRhino)
     ZaneZooKeeper.Add(TonyTiger)
     ZaneZooKeeper.Add(TimmyTiger)
     ZaneZooKeeper.WakeUp()
     ZaneZooKeeper.RollCall()
     ZaneZooKeeper.Roam()
     ZaneZooKeeper.Eat()
     ZaneZooKeeper.Sleep()
    ## setting with stragey pattern
    WillieWolf = Wolf(FeedWithFear())
    WhinnyWolf = Wolf(FeedWithFear())

    CarlCat = Cat()
    CindyCat = Cat()
    ## setting with stragey pattern
    DougDog = Dog(FeedWithCare())
    DippyDog = Dog(FeedWithCare())

    EllyElephant = Elephant()
    EarlElephant = Elephant()
    HarryHippo = Hippo()
    HenryHippo = Hippo()
    LillyLion = Lion()
    LarryLion = Lion()
    RyanRhino = Rhino()
    RandyRhino = Rhino()
    TonyTiger = Tiger()
    TimmyTiger = Tiger()

    ZaneZooKeeper = ZooKeeper()

    WakeObserver = ObserverWakeUp()
    ZaneZooKeeper.attach(WakeObserver)

    RollCallObserver = ObserverRollCall()
    ZaneZooKeeper.attach(RollCallObserver)

    RoamCallObserver = ObserverRoam()
Esempio n. 5
0
class Zookeeper:

    # list of Animals is kept as an attribute of Zookeeper class
    animalsList = [
        Cat('Carl'),
        Cat('Candy'),
        Dog('Doris'),
        Dog('Dan'),
        Elephant('Eric'),
        Elephant('Earl'),
        Hippo('Harry'),
        Hippo('Humphrey'),
        Lion('Leopold'),
        Lion('Larry'),
        Rhino('Rory'),
        Rhino('Rodger'),
        Tiger('Terrance'),
        Tiger('Time'),
        Wolf('Wallace'),
        Wolf('Wendy')
    ]

    def main(self):

        if not os._exists(
                'out'):  # if out folder doesn't exist, then create one
            os.mkdir('out')

        sys.stdout = open(os.path.join('out', 'dayAtTheZoo.out'),
                          'w')  # write all print statements to a file

        # call wakeAnimals(), rollCallAnimals(), feedAnimals(), letAnimalsRoam(), putAnimalsToBed() in the same order
        print("The Zookeeper is waking up the animals:\n---")
        self.wakeAnimals()
        print("\nThe Zookeeper is doing roll call:\n---")
        self.rollCallAnimals()
        print("\nThe Zookeeper is feeding the animals:\n---")
        self.feedAnimals()
        print("\nThe Zookeeper is letting the animals roam about:\n---")
        self.letAnimalsRoam()
        print("\nThe Zookeeper is putting the animals to bed:\n---")
        self.putAnimalsToBed()

        return

    def wakeAnimals(self):
        '''
        :return: wakeUp() list of Animals one at a time
        '''
        for animal in self.animalsList:
            animal.wakeUp()
        return

    def feedAnimals(self):
        '''
        :return: feedAnimals() list of Animals one at a time
        '''
        for animal in self.animalsList:
            animal.eat()
        return

    def letAnimalsRoam(self):
        '''
        :return: lets list of Animals roam one at a time
        '''
        for animal in self.animalsList:
            animal.roam()
        return

    def rollCallAnimals(self):
        '''
        :return: allows roll call list of Animals one at a time.
        '''
        for animal in self.animalsList:
            animal.makeNoise()
        return

    def putAnimalsToBed(self):
        '''
        :return: allows list of Animals put to bed one at a time.
        '''
        for animal in self.animalsList:
            animal.sleep()
        return
Esempio n. 6
0
class Zookeeper:

    zoo_announcers = []

    animalsList = [
        Cat('Carl'),
        Cat('Candy'),
        Dog('Doris'),
        Dog('Dan'),
        Elephant('Eric'),
        Elephant('Earl'),
        Hippo('Harry'),
        Hippo('Humphrey'),
        Lion('Leopold'),
        Lion('Larry'),
        Rhino('Rory'),
        Rhino('Rodger'),
        Tiger('Terrance'),
        Tiger('Time'),
        Wolf('Wallace'),
        Wolf('Wendy')
    ]

    def add_observer(self, zoo_announcer: 'ZooAnnouncer'):
        self.zoo_announcers.append(zoo_announcer)

    def notify_observers(self, task: Task):
        for announcer in self.zoo_announcers:
            announcer.update(task)

    def remove_observer(self, zoo_announcer: 'ZooAnnouncer'):
        self.zoo_announcers.remove(zoo_announcer)

    def wakeAnimals(self):
        self.notify_observers(Task.WAKEUP)
        for animal in self.animalsList:
            animal.wakeUp()
        return

    def feedAnimals(self):
        self.notify_observers(Task.FEED)
        for animal in self.animalsList:
            animal.eat()
        return

    def letAnimalsRoam(self):
        self.notify_observers(Task.LETROAM)
        for animal in self.animalsList:
            animal.roam()
        return

    def rollCallAnimals(self):
        self.notify_observers(Task.ROLLCALL)
        for animal in self.animalsList:
            animal.makeNoise()
        return

    def putAnimalsToBed(self):
        self.notify_observers(Task.PUTTOBED)
        for animal in self.animalsList:
            animal.sleep()
        return
 def test_actions(self):
     for state, input_object in automate:
         lion = l.Lion(state)
         lion.meet(input_object)
         none, true_action = automate[(state, input_object)]
         self.assertEqual(true_action, lion.action, 'Wrong lion state')
 def test_states(self):
     for state, input_object in automate:
         lion = l.Lion(state)
         lion.meet(input_object)
         true_state, none = automate[(state, input_object)]
         self.assertEqual(true_state, lion.state, 'Wrong lion state')
 def test_input_wrong_objects(self):
     objects = [None, 55, a.eat, object]
     lion = l.Lion(s.hungry)
     for i in objects:
         self.assertRaises(ValueError, lion.meet, i)
Esempio n. 10
0
from ZooKeeperInterface import *

if __name__ == "__main__":
    Cody = Cat("Cody")
    Code = Cat("Code")
    Code.setStatus()
    Donald = Dog("Donald")
    Dash = Dog("Dash")
    Dash.setStatus()
    Eric = Elephant("Eric")
    Edward = Elephant("Edward")
    Edward.setStatus()
    Heman = Hippo("Heman")
    Heather = Hippo("Heather")
    Heather.setStatus()
    Luke = Lion("Luke")
    Lisa = Lion("Lisa")
    Lisa.setStatus()
    Rosy = Rhino("Rosy")
    Rambo = Rhino("Rambo")
    Rambo.setStatus()
    Todd = Tiger("Todd")
    Toby = Tiger("Toby")
    Toby.setStatus()
    William = Wolf("William")
    Watson = Wolf("Watson")
    Watson.setStatus()
    list1 = []
    #     Adding the list of all the animals to a list
    list1.append(Cody)
    list1.append(Code)
Esempio n. 11
0
import pygame
pygame.init()
from Tapir import *
from Lion import *

screen_info = pygame.display.Info()
print(screen_info)

w = pygame.display.set_mode((800, 600))
c = pygame.time.Clock()
color = (0, 255, 0)

Player1 = Tapir((20, 300))
Player2 = Lion((780, 300))


def main():
    while True:
        for event in pygame.event.get():
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_RIGHT:
                    Player1.speed[0] = 10
                if event.key == pygame.K_DOWN:
                    Player1.speed[1] = 10
                if event.key == pygame.K_UP:
                    Player1.speed[1] = -10
                if event.key == pygame.K_LEFT:
                    Player1.speed[0] = -10
                if event.key == pygame.K_d:
                    Player2.speed[0] = 10
                if event.key == pygame.K_s: