Esempio n. 1
0
class CommandTests(unittest.TestCase):

    def setUp(self):
        GRID_MAX = 5
        self.GRID_MAX = GRID_MAX
        self.grid = Grid(GRID_MAX, GRID_MAX)


        for y in range(0, self.grid.length + 1):
            for x in range(0, GRID_MAX):
                gridMember = Room(x = x, y = y) 
                self.grid.addRoom(gridMember)


        self.player = Entity(name = 'player', x = 2, y = 2)
        self.grid.get(*self.player.position).inventory.add(self.player)
        self.console = Console(grid = self.grid, member = self.player)

    def test_west(self):
        originalPosition = self.player.position
        self.assertTrue(self.console.command('west'))
        self.assertEqual(self.player.position[0], originalPosition[0] - 1)

    def test_east(self):
        originalPosition = self.player.position
        self.assertTrue(self.console.command('east'))
        self.assertEqual(self.player.position[0], originalPosition[0] + 1)

    def test_north(self):
        originalPosition = self.player.position
        self.assertTrue(self.console.command('north'))
        self.assertEqual(self.player.position[1], originalPosition[1] + 1)

    def test_south(self):
        originalPosition = self.player.position
        self.assertTrue(self.console.command('south'))
        self.assertEqual(self.player.position[1], originalPosition[1] - 1)
        
    def test_flubbingIt(self):
        self.player.position = 5, 5
        originalPosition = self.player.position
        self.assertFalse(self.console.command('east'))
        self.assertEqual(self.player.position, originalPosition)
Esempio n. 2
0
class InventoryTests(unittest.TestCase):
    
    def setUp(self):
        GRID_MAX = 5
        self.GRID_MAX = GRID_MAX
        self.grid = Grid(GRID_MAX, GRID_MAX)

        for y in range(0, self.grid.length + 1):
            for x in range(0, GRID_MAX):
                gridMember = Room(x = x, y = y) 
                self.grid.addRoom(gridMember)

        self.player = Entity(name = 'yo momma', x = 2, y = 2)
        room = self.grid.get(2, 2)
        sampleItem = Item(  name = 'sample item', description = 'asdf',
                            x = room.x, y = room.y)
        room.inventory.add(sampleItem)
        room.inventory.add(self.player)
        self.console = Console(grid = self.grid, member = self.player)

    def test_getting(self):
        self.console.command('get sample item')
        self.console.command('inventory')
Esempio n. 3
0
    def setUp(self):
        GRID_MAX = 5
        self.GRID_MAX = GRID_MAX
        self.grid = Grid(GRID_MAX, GRID_MAX)


        for y in range(0, self.grid.length + 1):
            for x in range(0, GRID_MAX):
                gridMember = Room(x = x, y = y) 
                self.grid.addRoom(gridMember)


        self.player = Entity(name = 'player', x = 2, y = 2)
        self.grid.get(*self.player.position).inventory.add(self.player)
        self.console = Console(grid = self.grid, member = self.player)
Esempio n. 4
0
    def setUp(self):
        self.grid = Grid(10, 10)


        for counter in range(self.X_MIN, self.X_MAX):
            gridMember = Room(x = counter, y = self.Y_MIN) 
            self.grid.addRoom(gridMember)

        for counter in range(self.Y_MIN, self.Y_MAX):
            gridMember = Room(x = self.X_MAX, y = counter) 
            self.grid.addRoom(gridMember)

        self.player = Entity(x = self.X_MAX, y = self.Y_MAX - 1, name = 'yo momma')
        self.grid.get(*self.player.position).inventory.add(self.player)
        self.console = Console(grid = self.grid, member = self.player)
Esempio n. 5
0
    def setUp(self):
        GRID_MAX = 5
        self.GRID_MAX = GRID_MAX
        self.grid = Grid(GRID_MAX, GRID_MAX)

        for y in range(0, self.grid.length + 1):
            for x in range(0, GRID_MAX):
                gridMember = Room(x = x, y = y) 
                self.grid.addRoom(gridMember)

        self.player = Entity(name = 'yo momma', x = 2, y = 2)
        room = self.grid.get(2, 2)
        sampleItem = Item(  name = 'sample item', description = 'asdf',
                            x = room.x, y = room.y)
        room.inventory.add(sampleItem)
        room.inventory.add(self.player)
        self.console = Console(grid = self.grid, member = self.player)
Esempio n. 6
0
class TestGrid(unittest.TestCase):

    X_MIN = 3
    X_MAX = 7
    Y_MIN = 2
    Y_MAX = 5
    def setUp(self):
        self.grid = Grid(10, 10)


        for counter in range(self.X_MIN, self.X_MAX):
            gridMember = Room(x = counter, y = self.Y_MIN) 
            self.grid.addRoom(gridMember)

        for counter in range(self.Y_MIN, self.Y_MAX):
            gridMember = Room(x = self.X_MAX, y = counter) 
            self.grid.addRoom(gridMember)

        self.player = Entity(x = self.X_MAX, y = self.Y_MAX - 1, name = 'yo momma')
        self.grid.get(*self.player.position).inventory.add(self.player)
        self.console = Console(grid = self.grid, member = self.player)

    def test_addingMover(self):
        
        #self.assertEqual(self.grid.get(self.player.x, self.player.y), self.player,'Retrieved player from grid after adding')
        #self.assertTrue(self.player in self.grid.get(self.player.x, self.player.y))
        room = self.grid.get(self.player.x, self.player.y)
        self.assertTrue(room.inventory.get(self.player.name))

    def test_moving(self):
        success = self.console.move(member = self.player, x = self.player.x, y = self.player.y - 1)
        playerPosition = self.player.position
        #self.assertEqual(str(self.grid.get(*playerPosition)), str(self.player), 'Retrieved player from grid after moving')
        room = self.grid.get(self.player.x, self.player.y)
        self.assertTrue(room.inventory.get(self.player.name))

        self.assertTrue(success)
         
    def test_movingBackAndForth(self):
        self.console.move(member = self.player, x = self.player.x, y = self.player.y - 1)
        playerPosition = self.player.position
        #self.assertEqual(str(self.grid.get(*playerPosition)), str(self.player), 'Retrieved player from grid after moving')
        room = self.grid.get(self.player.x, self.player.y)
        self.assertTrue(room.inventory.get(self.player.name))
        #self.assertTrue(self.player in self.grid.get(self.player.x, self.player.y))
        success = self.console.move(member = self.player, x = self.player.x, y = self.player.y + 1)
        self.assertTrue(success, 'moving off a square didnt fritz that square')


    def test_blockedMoving(self):
        preMovePosition = self.player.position
        success = self.console.move(member = self.player, x = self.player.x + 1, y = self.player.y)        
        playerPosition = self.player.position
        self.assertEqual(playerPosition, preMovePosition, 'failed move meant that player position remained unchanged')
        self.assertFalse(success)

    def test_gettingNone(self):
        self.assertTrue(self.grid.get(10, 10) is None)

    def test_drawing(self):
        self.grid.draw()
        self.assertTrue(True)