コード例 #1
0
ファイル: weapon_test.py プロジェクト: dsspasov/HackBulgaria
 def test_critical_hit_true_and_false(self):
     new_weapon = Weapon("Mighty Axe", 25, 0.2)
     results = []
     for i in range(10):
         results.append(new_weapon.critical_hit())
     self.assertIn(True, results)
     self.assertIn(False, results)
コード例 #2
0
ファイル: bomb.py プロジェクト: ccl2of4/Zombie-Hunting
	def __init__(self, pos = (0,0), **images) :
		Projectile.__init__ (self, pos, **images)
		Weapon.__init__ (self, pos, **images)
		self._has_been_launched = False
		self.set_knockback_factor (5)
		self._damage = 5
		self._name = "Bomb"
コード例 #3
0
ファイル: ammunition.py プロジェクト: karidon/Tabel
	def automat_catridges(self):
		'''
		5,45 и 7,62 мм автоматные патроны.
		:return: int
		'''
		return int(
			(Weapon.automat(self) * 246) + (Weapon.hand_gun(self) * 750))
コード例 #4
0
class TestWeapon(unittest.TestCase):

    def setUp(self):
        self.sword = Weapon('Sword', 15, 0.4)

    def test_init_weapon(self):
        self.assertEqual(self.sword.type, 'Sword')
        self.assertEqual(self.sword.damage, 15)
        self.assertEqual(self.sword.critical_strike_percent, 0.4)

    def test_critical_hit(self):
        critical_hit_used = False
        critical_hit_not_used = False
        while True:
            if self.sword.critical_hit():
                critical_hit_used = True
                return
        while True:
            if not self.sword.critical_hit():
                critical_hit_not_used = True
                return
        self.assertTrue(critical_hit_used)
        self.assertFalse(critical_hit_not_used)

    def test_critical_raises_error(self):
        with self.assertRaises(ValueError):
            axe = Weapon('Axe', 25, 2)
コード例 #5
0
class WeaponTest(unittest.TestCase):

    def setUp(self):
        self.weapon = Weapon("Spike", 200)

    def test_is_instance(self):
        self.assertTrue(isinstance(self.weapon, Weapon))

    def test_valid_members(self):
        self.assertEqual(self.weapon.name, "Spike")
        self.assertEqual(self.weapon.damage, 200)

    def test_str(self):
        expected = "{} with damage = {}"
        expected = expected.format(self.weapon.name, self.weapon.damage)
        self.assertEqual(str(self.weapon), expected)

    def test_get_functions(self):
        self.assertEqual(self.weapon.get_name(), "Spike")
        self.assertEqual(self.weapon.get_damage(), 200)

    def test_prepare_json(self):
        data = {
            "name": "Spike",
            "damage": 200
        }
        self.assertEqual(self.weapon.prepare_json(), data)
コード例 #6
0
ファイル: ammunition.py プロジェクト: karidon/Tabel
	def rubber_bullet(self):
		'''
		Патрон с резиновой пулей.
		:return: int
		'''
		return int(
			(Weapon.special_carbine(self) * 250) + (Weapon.guns(self) * 48))
コード例 #7
0
ファイル: test_weapon.py プロジェクト: mihail-nikolov/hackBG
 def test_critical_hit(self):
     weapon = Weapon("axe", 10, 0.5)
     results = []
     for x in range(1000):
         results.append(weapon.critical_hit())
     self.assertTrue(True in results)
     self.assertTrue(False in results)
コード例 #8
0
ファイル: ammunition.py プロジェクト: karidon/Tabel
	def pistol_catridges(self):
		'''
		Пистолетные патроны.
		:return: int
		'''
		return int((Weapon.guns(self) * 24) + (
			Weapon.pistol_gun(self) * 100))
コード例 #9
0
ファイル: dnp_tests.py プロジェクト: didoman/prog101tasks
 def test_weapon_no_crit(self):
     new_weapon = Weapon("alwayscrit", 10, 0)
     for i in range(0, 1000):
         iscrit = new_weapon.critical_hit()
         if iscrit:
             break
     self.assertFalse(iscrit)
コード例 #10
0
ファイル: dnp_tests.py プロジェクト: didoman/prog101tasks
 def test_weapon_critical_hit(self):
     new_weapon = Weapon("alwayscrit", 10, 1)
     for i in range(0, 10):
         iscrit = new_weapon.critical_hit()
         if not iscrit:
             break
     self.assertTrue(iscrit)
コード例 #11
0
ファイル: firearm.py プロジェクト: ccl2of4/Zombie-Hunting
	def update (self) :
		assert (self._cooldown_frames_left >= 0)

		if self._cooldown_frames_left > 0 :
			self._cooldown_frames_left -= 1

		Weapon.update (self)
コード例 #12
0
ファイル: gravis.py プロジェクト: bpittman/pydnd
 def __init__(self):
    Weapon.__init__(self)
    self.enhancement = 2
    self.damageDie = 'd8'
    self.numDie = 0
    self.extraCrit = '2d6'
    self.weaponType = 'implement'
    self.keywords = ['implement',]
コード例 #13
0
ファイル: gravis.py プロジェクト: bpittman/pydnd
 def __init__(self):
    Weapon.__init__(self)
    self.enhancement = 0
    self.damageDie = 'd8'
    self.numDie = 1
    self.damageType = 'str'
    self.weaponType = 'mace'
    self.keywords = ['mace','weapon']
コード例 #14
0
ファイル: firearm.py プロジェクト: ccl2of4/Zombie-Hunting
	def __init__(self, pos = (0,0), **images) :
		Weapon.__init__ (self, pos,**images)
		self._firing_velocity = 20
		self._magazine = []
		self._cooldown = 30
		self._name = "Firearm"

		#used for timing
		self._cooldown_frames_left = 0
コード例 #15
0
class WeaponTest(unittest.TestCase):
    def setUp(self):
        self.weapon = Weapon("gun", 40)

    def test_damage(self):
        self.assertEqual(self.weapon.get_damage(), 40)

    def test_name(self):
        self.assertEqual(self.weapon.get_name(), 'gun')
コード例 #16
0
ファイル: linder.py プロジェクト: bpittman/pydnd
 def __init__(self):
     Weapon.__init__(self)
     self.enhancement = 2
     self.damageDie = "d4"
     self.numDie = 1
     self.critDamage = ""
     self.damageType = "str"
     self.weaponType = "dagger"
     self.keywords = ["dagger", "lightBlade"]
     self.extraCrit = "2d6"
コード例 #17
0
ファイル: linder.py プロジェクト: bpittman/pydnd
 def __init__(self):
     Weapon.__init__(self)
     self.enhancement = 1
     self.damageDie = "d6"
     self.numDie = 1
     self.critDamage = ""
     self.damageType = "dex"
     self.weaponType = "handCrossbow"
     self.keywords = ["handCrossbow", "ranged"]
     self.extraCrit = "1d6"
コード例 #18
0
ファイル: linder.py プロジェクト: bpittman/pydnd
 def __init__(self):
     Weapon.__init__(self)
     self.enhancement = 3
     self.damageDie = "d8"
     self.numDie = 1
     self.critDamage = "3d6"
     self.damageType = "str"
     self.weaponType = "dagger"
     self.keywords = ["dagger", "lightBlade", "radiant"]
     self.extraCrit = "3d6"
コード例 #19
0
ファイル: linder.py プロジェクト: bpittman/pydnd
 def __init__(self):
     Weapon.__init__(self)
     self.enhancement = 0
     self.damageDie = "d4"
     self.numDie = 1
     self.critDamage = ""
     self.damageType = "str"
     self.weaponType = "fist"
     self.keywords = ["unarmed"]
     self.extraCrit = ""
コード例 #20
0
 def test_weapon_critical(self):
     new_weapon = Weapon("Ico", 100, 0.2)
     self.assertEqual(new_weapon.name, "Ico")
     self.assertEqual(new_weapon.damage, 100)
     self.assertEqual(new_weapon.critical_strike_percent, 0.2)
     weapontests = []
     for n in range(1, 11):
         weapontests.append(new_weapon.critical_hit())
     self.assertIn(200, weapontests)
     self.assertIn(False, weapontests)
コード例 #21
0
ファイル: test_weapon.py プロジェクト: kkashev/hackbulgaria
 def test_critical_hit(self):
     test_weapon = Weapon("axe", 20, 0.2)
     is_False = False
     is_True = False
     for i in range(100):
         if test_weapon.critical_hit():
             is_True = True
         else:
             is_False = True
     self.assertTrue(is_True)
     self.assertTrue(is_False)
コード例 #22
0
ファイル: basicturret.py プロジェクト: mjard/nanobiotics
    def update(self, *args):
        Weapon.update(self, *args)

        if self.cooldown > 0:
            self.cooldown -= 1
            return

        self.cooldown = 5

        if self.engaged:
            bp = self.pos
            bv = (self.target_pos - bp).normal * 1400
            if bv.x != 0 or bv.y != 0:
                self.fire_sound.play()
                bullet.pool.fire(bp.x, bp.y, bv.x, bv.y) 
コード例 #23
0
ファイル: test_mathhammer.py プロジェクト: hoylemd/Warhelper
def test_boltgun():
    boltgun = Weapon("Boltgun", 24, 4, 5, ["rapid fire"])
    expected  = "        Range S  AP Type\n"
    expected += "Boltgun  24\"  4  5  rapid fire"

    output = boltgun.print_statline()

    result = output == expected

    if not result:
        print "expected:"
        print expected
        print output
        print "^- output"

    assert result
コード例 #24
0
ファイル: ammunition.py プロジェクト: karidon/Tabel
	def cartridge_lighting(self):
		'''
		26 мм патрон осветительный.
		26 мм патроны красного, зеленого, желтого огня каждого вида.
		:return: int
		'''
		return int(Weapon.signal_pistol(self) * 5)
コード例 #25
0
ファイル: ammunition.py プロジェクト: karidon/Tabel
	def signal_catridges(self):
		'''
		Патроны сигнальные 18,5х60С.
		Патроны осветительные 18,5х60О.
		:return: int
		'''
		return int(Weapon.guns(self) * 4)
コード例 #26
0
ファイル: weapon_test.py プロジェクト: stoilov/Programming101
class TestWeapon(unittest.TestCase):

    def setUp(self):
        self.axe = Weapon("Mighty Axe", 25, 0.2)

    def test_weapon_init(self):
        self.assertEqual(self.axe.type, "Mighty Axe")
        self.assertEqual(self.axe.damage, 25)
        self.assertEqual(self.axe.critical_strike_percent, 0.2)

    def test_value_error(self):
        with self.assertRaises(ValueError):
            Weapon("Mighty Axe", 25, 2)

    def test_critical_hit(self):
        has_been_true = False
        has_been_false = False
        for i in range(1000):
            if self.axe.critical_hit():
                has_been_true = True
            else:
                has_been_false = True

        self.assertTrue(has_been_true)
        self.assertTrue(has_been_false)
コード例 #27
0
ファイル: entity.py プロジェクト: skdls-/Python
 def __init__(self, name, health):
     self.name = name
     self.health = health
     self.max_health = health
     self.weapon = Weapon("Axe", 6, 0.5)
     self.i_coord = 0
     self.j_coord = 0
コード例 #28
0
ファイル: test_mathhammer.py プロジェクト: hoylemd/Warhelper
def test_plasmagun():
    weapon = Weapon("Plasmagun", 24, 7, 2, ["rapid fire", "gets hot"])
    expected  = "          Range S  AP Type\n"
    expected += "Plasmagun  24\"  7  2  rapid fire,\n"
    expected += "                      gets hot"

    output = weapon.print_statline()

    result = output == expected

    if not result:
        print "expected:"
        print expected
        print output
        print "^- output"

    assert result
コード例 #29
0
ファイル: twinturret.py プロジェクト: mjard/nanobiotics
    def update(self, *args):
        Weapon.update(self, *args)

        # if self.cooldown > 0:
        #     self.cooldown -= 1
        #     return

        self.cooldown = 1

        if self.engaged:
            bv = (self.target_pos - self.pos).normal * 2000
            bp = self.pos
            if bv.x != 0 or bv.y != 0:
                self.fire_sound.play()
                # jitter
                bv.x += random.randrange(-100,100)
                bv.y += random.randrange(-100,100)    
                bullet.pool.fire(bp.x, bp.y, bv.x, bv.y) 
コード例 #30
0
 def setUp(self):
     self.hero = Hero(name="Bron",
                      title="Dragonslayer",
                      health=100, mana=100,
                      mana_regeneration_rate=2)
     self.weapon = Weapon(name="The Axe of Destiny", damage=20)
     self.spell = Spell(name="Fireball",
                        damage=30,
                        mana_cost=50,
                        cast_range=2)
コード例 #31
0
    def get_name(self):
        return self.name

    def is_alive(self):
        if self.current_health <= 0:
            return False
        else:
            return True

    def add_weapon(self, weapon):
        '''Add weapon to self.abilities'''
        self.abilities.append(weapon)

    def add_kill(self, num_kills):
        ''' Update self.kills by num_kills amount'''
        self.kills += num_kills

    def add_death(self, num_deaths):
        ''' Update deaths with num_deaths'''
        self.deaths += num_deaths


if __name__ == "__main__":
    # If you run this file from the terminal
    # this block is executed.
    hero = Hero("Wonder Woman")
    weapon = Weapon("Lasso of Truth", 90)
    hero.add_weapon(weapon)
    print(hero.attack())
コード例 #32
0
 def test_Weapon_init(self):
     my_weapon = Weapon("Axe", 31, 0.2)
     self.assertEqual(my_weapon.typeW, "Axe")
     self.assertEqual(my_weapon.damage, 31)
     self.assertEqual(my_weapon.critical_strike_percent, 0.2)
コード例 #33
0
 def test_Weapon_critical_hit(self):
     my_weapon = Weapon("Axe", 31, 1)
     self.assertTrue(my_weapon.critical_hit())
コード例 #34
0
 def test_equip_weapon(self):
     axe = Weapon('Axe', 25, 0.5)
     self.entity.equip_weapon(axe)
     self.assertTrue(self.entity.has_weapon())
コード例 #35
0
 def test_get_damage_source_weapon_and_spell_wepaon_higher_damage(self):
     self.setUp()
     n = self.test_soldier
     n.equip_weapon(Weapon(name='asd', damage=50))
     n.learn_spell(self.default_spell)
     self.assertEqual(n.get_damage_source(), 'weapon')
コード例 #36
0
    def test_eq_method(self):
        weapon1 = Weapon('Ivan', 20)
        weapon2 = Weapon('Ivan', 20)

        self.assertTrue(weapon1 == weapon2, 'Weapons are equal')
コード例 #37
0
    def create_weapon(self):
        weapon_name = input("What is the weapon's name? ")
        weapon_damage = input("What is the max damage of the weapon? ")

        return Weapon(weapon, weapon_damage)
コード例 #38
0
    def update(self, user_pos, enemies_pos):

        perimeter = lambda x, y: (x - door.rect.center[1] )**2 + (y - door.rect.center[0] )**2

        for door in self.doors:
            # Open the door:
            if perimeter(self.rect.center[1], self.rect.center[0]) <= ( 1 * conf.tile_size ) ** 2:
                door.change_status(conf.door_open_image)
                self._map[ door.rect.center[1] // conf.tile_size, door.rect.center[0] // conf.tile_size ] = 0
                door.status = 'open'
                break

        # Note: Future use in enemy path finding logic
        self.user_pos = user_pos

        # Enemy sprite logic:
        self.count = self.count + 1
        if self.count == self.nframes * 10:
            self.count = 0

        # Looking for the new enemy state
        self.change_state( user_pos )

        row = self.state
        col = self.count // 10

        #####################
        #   DAMAGE STATE
        #####################

        if self.state == self.DAMAGE:

            self.damage_animation_count += 1
            row = self.state

            # Rotate Image:
            angle_deg, angle_rad = self.get_angle(user_pos)
            self.image = py.transform.rotozoom(self.matrix[row][col], angle_deg + self.desfase, 1)

            # Note: The enemy rotates around the same point as the old rect
            self.rect = self.image.get_rect(center=self.rect.center)

            if self.damage_animation_count > 8:
                self.state = self.ATTACK
                self.damage_animation_count = 0

            # While the enemy is been attacked he's allowed to defend himself
            # Verify if there is any object in the way: (obstacles, walls, enemies):
            if self.object_in_the_way(user_pos):

                # Fisrt Shot:
                if self.first:
                    self.first = False
                    self.attack_spam = time.time()

                    angle_deg, angle_rad = self.get_angle(user_pos)

                    return Weapon(self.weapon['matrix'], self.rect.center, self._map, [ self.weapon['velocity'], self.weapon['size'], [angle_deg, angle_rad], self.weapon['dispersion'], self.weapon['damage'], self.weapon['damage_end'] ], self._id)

                # Next Shot
                elif time.time() - self.attack_spam >= self.weapon['time_spam']:
                    self.attack_spam = time.time()

                    angle_deg, angle_rad = self.get_angle(user_pos)

                    return Weapon(self.weapon['matrix'], self.rect.center, self._map, [ self.weapon['velocity'], self.weapon['size'], [angle_deg, angle_rad], self.weapon['dispersion'], self.weapon['damage'], self.weapon['damage_end'] ], self._id)




        #####################
        #   DEAD STATE
        #####################

        elif self.state == self.DEAD and self.dead_state_update:

            # Rotate Image:
            angle_deg, angle_rad = self.get_angle(user_pos)
            self.image = py.transform.rotozoom(self.matrix[row][col], angle_deg + self.desfase, 1)

            # Note: The enemy rotates around the same point as the old rect
            self.rect = self.image.get_rect(center=self.rect.center)

            # Do not change angle ever again.
            self.dead_state_update = False


        #####################
        #   FOLLOW STATE
        #####################

        elif self.state == self.FOLLOW:

            if not self.curved_coord:

                # Calcule ""from"" and ""_to"":
                _from = [ coord // conf.tile_size for coord in self.rect.center][::-1]
                _to =  [ coord // conf.tile_size for coord in user_pos][::-1]

                # Replace ""_to"" by the last ""_to"" position known
                if  _to not in self.M_Graph:
                    _to = self._to

                try:
                    self.path = self.M_Graph.find_path(_from, _to)[:4]
                    self.curved_coord = self.get_curved_path()
                    self._to = _to
                except:
                    return None
                    #self.curved_coord = [tuple(coord / conf.tile_size for coord in self.rect.center)]

            self.next_pos = self.curved_coord.pop(0)
            self.next_pos = [coord * conf.tile_size for coord in self.next_pos][::-1]

            # Rotate Image:
            angle_deg, angle_rad = self.get_angle(user_pos)
            self.image = py.transform.rotozoom(self.matrix[row][col], angle_deg + self.desfase, 1)

            # Note: The enemy rotates around the same point as the old rect
            self.rect = self.image.get_rect(center=self.rect.center)

            # Taking into account only the ennemies with more privileges than the current enemy were are studying:
            self.privilege = [item[0] for item in enemies_pos].index(self._id)

            # Note: If no other enemy is in the position then:
            if not any( self.action(self.next_pos, enemy[1], enemy[2]) for enemy in enemies_pos[:self.privilege] if enemy[0] != self._id):

                # No checking for collision is required because the enemy path is already taken from a none collision path function
                col_add, row_add = ( self.next_pos[0] - self.rect.center[0], self.next_pos[1] - self.rect.center[1])
                self.rect = self.rect.move(col_add, row_add)

            # Someone in position already rerun secuence:
            else:
                self.state = self.WAITING

            # While the enemy is moving he will be allowed to defend himself
            # Note: Because of the movement of the enemy the shots will take longer
            if self.object_in_the_way(user_pos):

                # Fisrt Shot:
                if self.first:
                    self.first = False
                    self.attack_spam = time.time()

                    angle_deg, angle_rad = self.get_angle(user_pos)

                    return Weapon(self.weapon['matrix'], self.rect.center, self._map, [ self.weapon['velocity'], self.weapon['size'], [angle_deg, angle_rad], self.weapon['dispersion'], self.weapon['damage'], self.weapon['damage_end'] ], self._id)

                # Next Shot
                elif time.time() - self.attack_spam >= self.weapon['time_spam'] + conf.enemy_movement_penalty:
                    self.attack_spam = time.time()

                    angle_deg, angle_rad = self.get_angle(user_pos)

                    return Weapon(self.weapon['matrix'], self.rect.center, self._map, [ self.weapon['velocity'], self.weapon['size'], [angle_deg, angle_rad], self.weapon['dispersion'], self.weapon['damage'], self.weapon['damage_end'] ], self._id)



        #####################
        #   WAITING STATE
        #####################

        elif self.state == self.WAITING:

            # Rotate Image:
            angle_deg, angle_rad = self.get_angle(user_pos)
            self.image = py.transform.rotozoom(self.matrix[row][col], angle_deg + self.desfase, 1)

            # Note: The enemy rotates around the same point as the old rect
            self.rect = self.image.get_rect(center=self.rect.center)

            # Note: If no other enemy is in the position then:
            if not any( self.action(self.next_pos, enemy[1], enemy[2]) for enemy in enemies_pos[:self.privilege] if enemy[0] != self._id):

                # No checking for collision is required because the enemy path is already taken from a none collision path function
                col_add, row_add = ( self.next_pos[0] - self.rect.center[0], self.next_pos[1] - self.rect.center[1])
                self.rect = self.rect.move(col_add, row_add)
                self.state = self.FOLLOW

            # Someone in position already rerun secuence:
            else:
                self.state = self.WAITING


        #####################
        #   ATTACK STATE
        #####################

        elif self.state == self.ATTACK:

            # Rotate Image:
            angle_deg, angle_rad = self.get_angle(user_pos)
            self.image = py.transform.rotozoom(self.matrix[row][col], angle_deg + self.desfase, 1)

            # Note: The enemy rotates around the same point as the old rect
            self.rect = self.image.get_rect(center=self.rect.center)

            # Verify if there is any object in the way: (obstacles, walls, enemies):
            if self.object_in_the_way(user_pos):

                # Fisrt Shot:
                if self.first:
                    self.first = False
                    self.attack_spam = time.time()

                    angle_deg, angle_rad = self.get_angle(user_pos)

                    return Weapon(self.weapon['matrix'], self.rect.center, self._map, [ self.weapon['velocity'], self.weapon['size'], [angle_deg, angle_rad], self.weapon['dispersion'], self.weapon['damage'], self.weapon['damage_end'] ], self._id)

                # Next Shot
                elif time.time() - self.attack_spam >= self.weapon['time_spam']:
                    self.attack_spam = time.time()

                    angle_deg, angle_rad = self.get_angle(user_pos)

                    return Weapon(self.weapon['matrix'], self.rect.center, self._map, [ self.weapon['velocity'], self.weapon['size'], [angle_deg, angle_rad], self.weapon['dispersion'], self.weapon['damage'], self.weapon['damage_end'] ], self._id)


        #####################
        #   PATROL STATE
        #####################

        elif self.state == self.PATROL:

            if not self.curved_coord:

                # Calcule ""from"" and ""_to"":
                _from = [ coord // conf.tile_size for coord in self.rect.center][::-1]
                _to = rd.choice(list(self.M_Graph.M.neighbors( self.M_Graph._map_list[_from[0]][_from[1]] ) ) )
                _to = rd.choice(list(self.M_Graph.M.neighbors( self.M_Graph._map_list[_to.row][_to.col] ) ) )
                _to = rd.choice(list(self.M_Graph.M.neighbors( self.M_Graph._map_list[_to.row][_to.col] ) ) )

                try:
                    self.path = self.M_Graph.find_path(_from, _to)[:4]
                    self.curved_coord = self.get_curved_path()
                    self._to = _to
                except:
                    return None
                    #self.curved_coord = [tuple(coord / conf.tile_size for coord in self.rect.center)]

            self.next_pos = self.curved_coord.pop(0)
            self.next_pos = [coord * conf.tile_size for coord in self.next_pos][::-1]

            # Rotate Image:
            angle_deg, angle_rad = self.get_angle(self.next_pos)
            self.image = py.transform.rotozoom(self.matrix[row][col], angle_deg + self.desfase, 1)

            # Note: The enemy rotates around the same point as the old rect
            self.rect = self.image.get_rect(center=self.rect.center)

            # No checking for collision is required because the enemy path is already taken from a none collision path function
            col_add, row_add = ( self.next_pos[0] - self.rect.center[0], self.next_pos[1] - self.rect.center[1])
            self.rect = self.rect.move(col_add, row_add)
コード例 #39
0
    def testSetters(self):
        weapon = Weapon("Bombchu")

        #change the size of the bag
        new_bag_size = 40
        weapon.icreaseBag(new_bag_size)
        self.assertEqual(weapon.bagSize, new_bag_size)

        #make sure I can't overfill the bag
        weapon.refill(50)
        self.assertEqual(weapon.quantity, new_bag_size)

        #I should not be able to fire unless I have aquired the weapon, it has been assigned a C direction, and it is in use
        weapon.fire()
        self.assertEqual(weapon.quantity, new_bag_size)

        #the quantity should decrease when it's fired
        weapon.beenAcquired()
        weapon.applyC("right")
        weapon.using()
        for i in range(10):
            weapon.fire()
        self.assertEqual(weapon.quantity, new_bag_size - 10)

        #the quantity cannot go below zero
        for i in range(50):
            weapon.fire()
        self.assertEqual(weapon.quantity, 0)
コード例 #40
0
 def test_value_error(self):
     with self.assertRaises(ValueError):
         Weapon("", 25, 20)
コード例 #41
0
 def test_equip_weapon(self):
     new_weapon = Weapon("Bazuka", 15, 3)
     self.orc.equip_weapon(new_weapon)
     self.assertEqual(new_weapon, self.orc.weapon)
コード例 #42
0
 def test_equip_weapon(self):
     old_weapon = Weapon("Axe", 20, 0.5)
     self.entity.equip_weapon(old_weapon)
     self.assertTrue(self.entity.has_weapon())
     self.assertEqual(old_weapon, self.entity.weapon)
コード例 #43
0
 def __init__(self):
     self.name = ''
     self.health = 0
     self.power_level = 0
     self.weapon = Weapon()
コード例 #44
0
 def test_equip_new_weapon(self):
     old_weapon = Weapon("Axe", 20, 0.5)
     self.entity.equip_weapon(old_weapon)
     new_weapon = Weapon("Sopa", 30, 0.8)
     self.entity.equip_weapon(new_weapon)
     self.assertEqual(new_weapon, self.entity.weapon)
コード例 #45
0
 def create_weapon(self):
     name = input("What is the weapon name?  ")
     max_damage = input("What is the max damage of the weapon?  ")
     return Weapon(name, max_damage)
コード例 #46
0
 def test_attack_with_weapon(self):
     weapon = Weapon("Axe", 20, 0.5)
     self.entity.equip_weapon(weapon)
     self.assertEqual(20, self.entity.attack())
コード例 #47
0
    def test_lt_method(self):
        weapon1 = Weapon('Ivan', 20)
        weapon2 = Weapon('Ivan', 40)

        self.assertTrue(weapon1 < weapon2,
                        'First weapon is greater than second weapon')
コード例 #48
0
ファイル: entity_test.py プロジェクト: stoilov/Programming101
 def test_has_weapon_yes(self):
     self.born_entity.weapon = Weapon("Mighty Axe", 25, 0.2)
     self.assertTrue(self.born_entity.has_weapon())
コード例 #49
0
 def test_has_weapon(self):
     self.weapon = Weapon('Axe', 25, 0.5)
コード例 #50
0
ファイル: entity_test.py プロジェクト: stoilov/Programming101
 def test_equip_weapon(self):
     weapon = Weapon("Mighty Axe", 25, 0.2)
     self.born_entity.equip_weapon(weapon)
     self.assertEqual(self.born_entity.weapon, weapon)
コード例 #51
0
 def test_attack_with_weapon(self):
     axe = Weapon('Axe', 25, 0.5)
     self.entity.equip_weapon(axe)
     self.assertEqual(self.entity.attack(), 25)
コード例 #52
0
ファイル: test_dungeon.py プロジェクト: mihail-nikolov/hackBG
 def test_check_for_equal_weapon_coordinates_false2(self):
     axe = Weapon("axe", 10, 0.5)
     self.paladin.equip_weapon(axe)
     answer = self.single_loc_map._check_for_equal_player_coordinates(
         "player_1")
     self.assertFalse(answer)
コード例 #53
0
 def setUp(self):
     self.test_soldier = Unit(health=200, mana=100)
     self.default_weapon = Weapon()
     self.default_spell = Spell()
コード例 #54
0
ファイル: arena.py プロジェクト: oconda90/Team-dueler
 def create_armor(self):
     name_of_armor = input("What is this armors name ?")
     max_health = input("What is the armors max health?")
     return Weapon(name_of_armor, max_health)
コード例 #55
0
 def setUp(self):
     self.the_weapon = Weapon("Mighty Axe", 25, 0.2)
コード例 #56
0
 def test_eqiup_weapon(self):
     weapon = Weapon("hammer", 20, 0.5)
     self.test_entity.equip_weapon(weapon)
     self.assertTrue(self.test_entity.has_weapon())
コード例 #57
0
class Hero(Player):
    def __init__(self, game_settings, screen, hero, weapon):
        path = '../resources/' + hero + '/' + hero + '_m'
        self.name = hero
        super().__init__(game_settings, screen, path)

        self.rect.centerx = self.screen_rect.centerx / 3
        self.rect.bottom = self.screen_rect.bottom - game_settings.floor
        self.center = float(self.rect.centerx)

        self.hit_sound = pygame.mixer.Sound(
            '../resources/heroes/sword_stab-18.wav')
        self.swing_sound = pygame.mixer.Sound(
            '../resources/heroes/sword_swing-18.wav')

        self.hit = 0
        self.hp = self.baseHp = self.mana = self.baseMana = 0

        # Sets character hp/mana/weapon through dictionaries in settings
        for char in game_settings.characters:
            if hero == char['NAME']:
                self.hp = self.baseHp = char['HP']

                if weapon in char["WEAPONS"]:
                    self.weapon = Weapon(screen, game_settings, self.rect,
                                         weapon)
                else:
                    self.weapon = Weapon(screen, game_settings, self.rect,
                                         char['WEAPONS'][0])

        if hero not in [char['NAME'] for char in game_settings.characters]:
            self.name = hero = game_settings.characters[0]['NAME']
            self.hp = self.baseHp = game_settings.characters[0]['HP']
            self.weapon = Weapon(screen, game_settings, self.rect,
                                 game_settings.characters[0]['WEAPONS'][0])

        self.npc = False
        self.ui = UI(screen, game_settings)

    def left(self):
        super().left()
        self.weapon.face_left()

    def right(self):
        super().right()
        self.weapon.face_right()

    def use_weapon(self):
        self.weapon.using = True
        if not self.weapon.collision:
            self.swing_sound.play(0, 2000, 1000)

    def check_collision(self, sprite):
        if pygame.sprite.collide_mask(self.weapon, sprite):
            self.collision = True
            self.weapon.collision = True

            self.hit %= 5

            if self.weapon.using and self.hit == 1:
                self.hit_sound.play(0, 2000, 1000)
                sprite.hp -= self.weapon.damage
                if sprite.hp < 0:
                    sprite.hp = 0

            self.hit += 1
        else:
            self.weapon.collision = False

    def update(self):
        super().update()
        self.weapon.update(self.rect, self.rect.centery, self.facing_right)

    def blitme(self):
        self.ui.blitme((self.hp / self.baseHp))
        self.weapon.blitme()
        super().blitme()
コード例 #58
0
 def test_attack(self):
     weapon = Weapon("hammer", 20, 0.5)
     self.test_entity.equip_weapon(weapon)
     self.assertEqual(self.test_entity.attack(), 20)
コード例 #59
0
        def create_weapon(self):
        '''Prompt user for Weapon information
            return Weapon with values from user input.
        '''
        weapon_name = input("what is the name of your weapon")
        weapon_description = input("What does this weapon do?")
        return Weapon(weapon_name, weapon_description)

        def create_armor(self):
        '''Prompt user for Armor information
          return Armor with values from user input.
        '''

          armor_name = input("what piesce of armor do you want")
          armor_specs = input("what materails do you need")
          return Armor(armor,armor_specs)

        def create_hero(self):
        '''Prompt user for Hero information
          return Hero with values from user input.
        '''
        hero_name = input("Hero's name: ")
        hero = Hero(hero_name)
        add_item = None

        while add_item != "4":
           add_item = input("[1] Add ability\n[2] Add weapon\n[3] Add armor\n[4] Done adding items\n\nYour choice: ")
           if add_item == "1":
               ability = self.create_ability()
               hero.create_ability()
               
           elif add_item == "2":
               weapon = self.create_weapon()
               hero.create_weapon()
           elif add_item == "3":
               armor = self.create_armor()
               hero.create_armor()
        return hero

           
    def build_team_one(self):
        '''Prompt the user to build team_one '''
        numOfTeamMembers = int(input("How many members would you like on Team One?\n"))
        for i in range(numOfTeamMembers):
            hero = self.create_hero()
            self.team_one.add_hero(hero)
            
    
    def build_team_two(self):
        '''Prompt the user to build team_two'''
        numOfTeamMembers2 = int(input("How many members would you like on Team two?\n"))
        for i in range(numOfTeamMembers2):
            hero = self.create_hero()
            self.team_two.add_hero(hero)
  
    def team_battle(self):
        '''Battle team_one and team_two together.'''
        team_one.attack(team_two)

    def show_stats(self):
        '''Prints team statistics to terminal.'''

        print("\n")
    print(self.team_one.name + " statistics: ")
    self.team_one.stats()
    print("\n")
    print(self.team_two.name + " statistics: ")
    self.team_two.stats()
    print("\n")

    # This is how to calculate the average K/D for Team One
    team_kills = 0
    team_deaths = 0
    for hero in self.team_one.heroes:
        team_kills += hero.kills
        team_deaths += hero.deaths
    if team_deaths == 0:
        team_deaths = 1
    print(self.team_one.name + " average K/D was: " + str(team_kills/team_deaths))

    # Now display the average K/D for Team Two
    team_kills = 0
    team_deaths = 0
    for hero in self.team_two.heroes:
        team_kills += hero.kills
        team_deaths += hero.deaths
    if team_deaths == 0:
        team_deaths = 1
    print(self.team_two.name + " average K/D was: " + str(team_kills/team_deaths))

    # Here is a way to list the heroes from Team One that survived
    for hero in self.team_one.heroes:
        if hero.deaths == 0:
            print("survived from " + self.team_one.name + ": " + hero.name)

    
    #Now list the heroes from Team Two that survived
     for hero in self.team_two.heroes:
        if hero.deaths == 0:
            print("survived from " + self.team_two.name + ": " + hero.name)


    if __name__ == "__main__":
    game_is_running = True

    # Instantiate Game Arena
    arena = Arena()

    #Build Teams
    arena.build_team_one()
    arena.build_team_two()

    while game_is_running:

        arena.team_battle()
        arena.show_stats()
        play_again = input("Play Again? Y or N: ")

        #Check for Player Input
        if play_again.lower() == "n":
            game_is_running = False

        else:
            #Revive heroes to play again
            arena.team_one.revive_heroes()
            arena.team_two.revive_heroes()git 
コード例 #60
0
 def test_has_weapon(self):
     self.entity.weapon = Weapon("Axe", 20, 0.5)
     self.assertTrue(self.entity.has_weapon())