Esempio n. 1
0
	def test_check_player_end_attack(self):
		#setup
		x = 100
		y = 100
		w = 10
		h = 10
		dx = 0
		dy = 0
		s = 10
		hg = 15
		vg= 15
		self.player = Player(x,y,w,h,dx,dy,s,hg,vg,"right",(0,0))
		self.expectedSwordX = -100
		self.expectedSwordY = -100
		self.expectedSwordW = 0
		self.expectedSwordH = 0
		#stimulus
		self.player.attack()
		result = self.player.endAttack()

		#result
		self.assertEqual( result.getX(), self.expectedSwordX)
		self.assertEqual( result.getY(), self.expectedSwordY)
		self.assertEqual( result.getWidth(), self.expectedSwordW)
		self.assertEqual( result.getHeight(), self.expectedSwordH)
Esempio n. 2
0
class TestPlayer(unittest.TestCase):

	def test_check_player_attack_right(self):
		#setup
		x = 100
		y = 100
		w = 10
		h = 10
		dx = 0
		dy = 0
		s = 10
		hg = 15
		vg= 15
		self.player = Player(x,y,w,h,dx,dy,s,hg,vg,"right",(0,0))
		self.expectedSwordX = int(x+w)
		self.expectedSwordY = int(y + (h/2.75))
		self.expectedSwordW = int(w/2)
		self.expectedSwordH = int(h/3)
		#stimulus
		result = self.player.attack()

		#result
		self.assertEqual( result.getX(), self.expectedSwordX)
		self.assertEqual( result.getY(), self.expectedSwordY)
		self.assertEqual( result.getWidth(), self.expectedSwordW)
		self.assertEqual( result.getHeight(), self.expectedSwordH)

	def test_check_player_end_attack(self):
		#setup
		x = 100
		y = 100
		w = 10
		h = 10
		dx = 0
		dy = 0
		s = 10
		hg = 15
		vg= 15
		self.player = Player(x,y,w,h,dx,dy,s,hg,vg,"right",(0,0))
		self.expectedSwordX = -100
		self.expectedSwordY = -100
		self.expectedSwordW = 0
		self.expectedSwordH = 0
		#stimulus
		self.player.attack()
		result = self.player.endAttack()

		#result
		self.assertEqual( result.getX(), self.expectedSwordX)
		self.assertEqual( result.getY(), self.expectedSwordY)
		self.assertEqual( result.getWidth(), self.expectedSwordW)
		self.assertEqual( result.getHeight(), self.expectedSwordH)
Esempio n. 3
0
    def test_negative_health_loss_does_nothing(self):
        #setup
        self.p = Player(480,
                        250,
                        50,
                        50,
                        0,
                        0,
                        0,
                        0,
                        0,
                        'right',
                        roomXY=(0, 0))
        self.mExpectedHealth = 100

        #stimulus
        self.p.looseHealth(-1)
        result = self.p.getHealth()

        #result
        self.assertEqual(result, self.mExpectedHealth)
Esempio n. 4
0
    def test_check_player_takes_correct_damage2(self):
        #setup
        self.mHealth = 100
        self.mExpectedHealth = 99
        self.p = Player(480,
                        250,
                        50,
                        50,
                        0,
                        0,
                        0,
                        0,
                        0,
                        'right',
                        roomXY=(0, 0))

        #stimulus
        self.p.looseHealth(1)
        result = self.p.getHealth()

        #result
        self.assertEqual(result, self.mExpectedHealth)
Esempio n. 5
0
    def test_Object_list_updates_correct_object_room_2_0(self):
        #setup
        self.mWidth = 500
        self.mHeight = 500
        VerticleDoorHeight = self.mHeight
        VerticleDoorWidth = 3
        HorizontalDoorHeight = 3
        HorizontalDoorWidth = self.mWidth

        self.mObjects = []
        self.mDoors = []
        self.mActiveObjects = []

        self.mDoor0 = adventurelib.objects.Door( self.mWidth - VerticleDoorWidth , 0, VerticleDoorWidth, VerticleDoorHeight, (0, 0), (1, 0))
        self.mDoor0Invert = adventurelib.objects.Door( 0 , self.mHeight/2 - (VerticleDoorHeight / 2), VerticleDoorWidth, VerticleDoorHeight, (1, 0), (0, 0))

        self.mDoor1 = adventurelib.objects.Door( (self.mWidth / 2) - (HorizontalDoorWidth / 2) , 0, HorizontalDoorWidth, HorizontalDoorHeight, (1, 0), (1, 1) )
        self.mDoor1Invert = adventurelib.objects.Door( (self.mWidth/2) - (HorizontalDoorWidth / 2) , self.mHeight - ( HorizontalDoorHeight) , HorizontalDoorWidth, HorizontalDoorHeight, (1, 1), (1, 0))

        self.mDoor2 = adventurelib.objects.Door( (self.mWidth / 2) - (HorizontalDoorWidth / 2) , 0, HorizontalDoorHeight, HorizontalDoorWidth, (2, 0), (2, 1) )
        self.mDoor2Invert = adventurelib.objects.Door( (self.mWidth/2) - (HorizontalDoorWidth / 2) , self.mHeight - ( HorizontalDoorHeight), HorizontalDoorHeight, HorizontalDoorWidth, (2, 1), (2, 0))

        self.mActiveObjects.append( self.mDoor0 )

        self.mDoors.append( self.mDoor0 )
        self.mDoors.append( self.mDoor0Invert )
        self.mDoors.append( self.mDoor1 )
        self.mDoors.append( self.mDoor1Invert )
        self.mDoors.append( self.mDoor2 )
        self.mDoors.append( self.mDoor2Invert )

        self.mObjects.append( self.mDoors)

        self.game = adventureGame.AdventureGame( 500, 500, 50 )

        self.mPlayer = Player( 480, 250, 50, 50, 0, 0, 0, 0, 0, 'right', roomXY = (2, 0))
        self.mHealth = 100
        self.mExpectedHealth = 99

        #stimulus
        self.mActiveObjects = []
        AdventureGame.add_current_obj_in_lists_to_active_objects(self, self.mObjects )

        result = len(self.mActiveObjects)
        self.mExpectedNunberOfObjects = 1
        self.assertEqual( result, self.mExpectedNunberOfObjects  )



        
Esempio n. 6
0
class TestHealth(unittest.TestCase):
    def test_check_player_takes_correct_damage2(self):
        #setup
        self.mHealth = 100
        self.mExpectedHealth = 99
        self.p = Player(480,
                        250,
                        50,
                        50,
                        0,
                        0,
                        0,
                        0,
                        0,
                        'right',
                        roomXY=(0, 0))

        #stimulus
        self.p.looseHealth(1)
        result = self.p.getHealth()

        #result
        self.assertEqual(result, self.mExpectedHealth)

    def test_check_player_takes_correct_damage50(self):
        #setup
        self.mHealth = 100
        self.mExpectedHealth = 50
        self.p = Player(480,
                        250,
                        50,
                        50,
                        0,
                        0,
                        0,
                        0,
                        0,
                        'right',
                        roomXY=(0, 0))

        #stimulus
        self.p.looseHealth(50)
        result = self.p.getHealth()

        #result
        self.assertEqual(result, self.mExpectedHealth)

    def test_negative_health_loss_does_nothing(self):
        #setup
        self.p = Player(480,
                        250,
                        50,
                        50,
                        0,
                        0,
                        0,
                        0,
                        0,
                        'right',
                        roomXY=(0, 0))
        self.mExpectedHealth = 100

        #stimulus
        self.p.looseHealth(-1)
        result = self.p.getHealth()

        #result
        self.assertEqual(result, self.mExpectedHealth)