Example #1
0
File: game.py Project: jdob/venture
class Game:

    def __init__(self):
        self.config = None
        self.console = None
        self.engine = None

        self.objects = None
        self.map = None

        self.player = None
        self.mob_generator = None

    def initialize(self):
        self.config = VentureConfig()
        self.console = VentureConsole(self.config)

        self.objects = Objects()

        self.map = Tomb(self, 5, 4, 1)
        self.map.generate()

        self.console.initialize()
        self.console.initialize_fov(self.map)

        self.player = Player(self)
        self.player.x, self.player.y = self.map.player_start_location()
        self.objects.append(self.player)

        self.mob_generator = SimpleMobGenerator(self)
        added_mobs = self.mob_generator.add_mobs(self.map.rooms)
        self.objects.extend(added_mobs)

        self.engine = VentureEngine(self)
Example #2
0
class ObjectsTests(unittest.TestCase):

    def setUp(self):
        super(ObjectsTests, self).setUp()
        self.game = game()
        self.game.initialize()
        self.objects = Objects()

    def test_at_found(self):
        # Setup
        self.objects.append(Object(self.game, name='yes', x=0, y=0))
        self.objects.append(Object(self.game, name='no', x=1, y=0))
        self.objects.append(Object(self.game, name='no', x=0, y=1))

        # Test
        found = self.objects.at(0, 0)

        # Verify
        self.assertTrue(found is not None)
        self.assertEqual('yes', found.name)

    def test_at_not_found(self):
        # Setup
        self.objects.append(Object(self.game, name='yes', x=0, y=0))
        self.objects.append(Object(self.game, name='no', x=1, y=0))
        self.objects.append(Object(self.game, name='no', x=0, y=1))

        # Test
        found = self.objects.at(10, 10)

        # Verify
        self.assertTrue(found is None)

    def test_at_multiple(self):
        # Setup
        self.objects.append(Object(self.game, name='first', x=0, y=0))
        self.objects.append(Object(self.game, name='second', x=0, y=0))
        self.objects.append(Object(self.game, name='no', x=0, y=1))

        # Test
        found = self.objects.at(0, 0)

        # Verify
        self.assertTrue(found is not None)
        self.assertEqual('first', found.name)