当前位置: 首页>>代码示例>>Python>>正文


Python alien.Alien类代码示例

本文整理汇总了Python中alien.Alien的典型用法代码示例。如果您正苦于以下问题:Python Alien类的具体用法?Python Alien怎么用?Python Alien使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Alien类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: alien_battle

def alien_battle():
  human = Human()
  alien = Alien()

  print("There is an human in front of you")
  action = input("What will you do run to ship or shot the human? (run / shoot): ")

  while alien.distance > 0 or human.health > 0 or alien.lifeForce > 0:

    if action == "run":
      alien.run()
      human.attack(human)
    elif action == "shoot":
      alien.alienAttack(human)
      human.attack(alien)
      

    if alien.distance == 0:
      print("You made it to the ship!")
      print("The Game is now over!")
      break
    elif human.health == 0:
      print("You killed the human!")
      print("The Game is now over!")
      break
    elif alien.lifeForce == 0:
      print("The human kills you!")
      print("The Game is now over!")
      break

    print("Distance to ship is: " + str(alien.distance) + " feet!")
    print("Human Life is: " + str(human.health))
    print("Alien life is: " + str(alien.lifeForce)) 

    action = input("What will you do run to bunker or shot the human? (run / shoot) ")
开发者ID:ravenusmc,项目名称:alienWar,代码行数:35,代码来源:battle.py

示例2: create_alien

def create_alien(ai_settings,screen,aliens,alien_number,row_number):
    alien = Alien(ai_settings,screen)
    alien_width = alien.rect.width
    alien.x = alien_width + 2*alien_width*alien_number
    alien.rect.x = alien.x
    alien.rect.y = alien.rect.height + 2*alien.rect.height*row_number
    aliens.add(alien)
开发者ID:FrankBrosnan,项目名称:PyGameInvaders,代码行数:7,代码来源:game_functions.py

示例3: TestAlien

class TestAlien(unittest.TestCase):
    def setUp(self):
        self.constraint = (1000, 1000)
        self.alien = Alien(self.constraint, 100, 100, Directions.left, 1)

    def test_init_no_params(self):
        alien = Alien(self.constraint)
        self.assertEqual(alien.x, 0)
        self.assertEqual(alien.direction, (1, 0))
        self.assertEqual(alien.kind, 'blue')
        self.assertEqual(alien.health, 100)
        self.assertEqual(alien.image_size, 160)
        self.assertEqual(alien.radius, 65)

    def test_init(self):
        self.assertEqual(self.alien.x, 100)
        self.assertEqual(self.alien.y, 100)
        self.assertEqual(self.alien.direction, Directions.left)
        self.assertEqual(self.alien.kind, 'lion')

    def test_hit(self):
        previous_health = self.alien.health
        self.alien.hit(10)
        self.assertEqual(self.alien.health, previous_health - 10)

    def test_is_dead(self):
        self.assertFalse(self.alien.is_dead())
        self.alien.health = 0
        self.assertTrue(self.alien.is_dead())
开发者ID:gvpavlov,项目名称:Insaniquarium,代码行数:29,代码来源:alien_test.py

示例4: create_alien

def create_alien(ai_settings, screen, aliens, alien_number, row_number):

	"""Create an alien and place it in the row."""

	

	alien = Alien(ai_settings, screen)
	
	alien.check_type()

	alien_width = alien.rect.width

	alien.x = ai_settings.randomint

	alien.rect.x = alien.x

	if alien.randomint1 <= 1:
		alien.rect.y = 694.75
		
	if alien.randomint1 >= 2 and alien.randomint1 < 4:	
		alien.rect.y = 400
		
	if alien.randomint1 >= 4:
		alien.rect.y =140
		
	aliens.add(alien)
开发者ID:InspectionXpert-Interns,项目名称:Brett,代码行数:26,代码来源:game_functions.py

示例5: create_an_alien

def create_an_alien(ai_settings, screen, aliens, row_num, column_num):
    alien = Alien(ai_settings, screen)
    alien_width = alien.rect.width
    alien.x = alien_width + 2 * alien_width * column_num
    alien.rect.x = alien.x
    alien.rect.y = alien.rect.height + 2 * alien.rect.height * row_num
    aliens.add(alien)
开发者ID:czqInNanjing,项目名称:SmallProject,代码行数:7,代码来源:game_functions.py

示例6: create_alien

def create_alien(ai_settings, screen, aliens, alien_number, row_number):
	"""Create an alien and place it in the row."""
	alien = Alien(ai_settings, screen)
	alien.x = alien.rect.width+2*alien.rect.width*alien_number
	alien.rect.x = alien.x
	alien.rect.y = alien.rect.height + 2 * alien.rect.height * row_number
	aliens.add(alien)
开发者ID:soviet47,项目名称:Alien-Invasion,代码行数:7,代码来源:game_functions.py

示例7: createAlien

def createAlien(aiSettings, screen, aliens, alienNumber, rowNumber):
		alien = Alien(aiSettings, screen)
		alienWidth = alien.rect.width
		alien.x = alienWidth + 2 * alienWidth * alienNumber
		alien.rect.x = alien.x
		alien.rect.y = alien.rect.height + 2 * alien.rect.height * rowNumber
		aliens.add(alien)
开发者ID:ndpark,项目名称:alienInvasion,代码行数:7,代码来源:game_functions.py

示例8: create_alien

def create_alien(ai_settings, screen, aliens, alien_number, row_number):
    """Utworzenie obcego i umieszczenie go w rzędzie."""
    alien = Alien(ai_settings, screen)
    alien_width = alien.rect.width
    alien.x = alien_width + 2 * alien_width * alien_number
    alien.rect.x = alien.x
    alien.rect.y = alien.rect.height + 2 * alien.rect.height * row_number
    aliens.add(alien)
开发者ID:gorczynski,项目名称:python-crash-course,代码行数:8,代码来源:game_functions.py

示例9: create_alien

def create_alien(ai_settings, screen, aliens, alien_number, row_number):
	# 创建一个外星人并将其加入当前行
	alien = Alien(ai_settings,screen)
	alien_width = alien.rect.width
	# 算当前外星人的x
	alien.x = alien_width + alien_width * 2 * alien_number
	alien.rect.x = alien.x
	# 根据第几行 计算y
	alien.rect.y = alien.rect.height + 2 * alien.rect.height * row_number
	aliens.add(alien)
开发者ID:zelsonia,项目名称:project,代码行数:10,代码来源:game_functions.py

示例10: create_alien

def create_alien(ai_settings, screen, aliens, alien_number, row_number):
	"""create an alien and place it in the row"""
	# create an alien and find the number of aliens in a row
	# spacing between each alien is equal to one alien width
	alien = Alien(ai_settings, screen)
	alien_width = alien.rect.width
	alien.x = alien_width + 2 * alien_width * alien_number
	alien.rect.x = alien.x
	alien.rect.y = alien.rect.height + 2 * alien.rect.height * row_number
	aliens.add(alien)
开发者ID:monicamow,项目名称:pythoncrashcourse,代码行数:10,代码来源:game_functions.py

示例11: create_alien

def create_alien(ai_settings, screen, aliens, alien_number, row_number):
    """Create an alien, and place it in the row."""
    alien = Alien(ai_settings, screen)
    alien_width = alien.rect.width
    alien.x = alien_width + 2 * alien_width * alien_number
    alien.rect.x = alien.x
    alien.rect.y = alien.rect.height + 2 * alien.rect.height * row_number
    aliens.add(alien)

    if alien_number == 0 or alien_number == 2 or alien_number == 4 or alien_number == 6 or alien_number == 8:
        alien.image =  pygame.image.load('images/alien.bmp')
开发者ID:KRob314,项目名称:alien-invasion,代码行数:11,代码来源:game_functions.py

示例12: create_fleet

def create_fleet(ai_settings, screen, aliens):
    """Create a full of aliens."""
    # Create a full fleet of aliens.
    # Spacing between each alien is equal to one alien width.
    alien = Alien(ai_settings, screen)
    alien_width = alien.rect.width
    available_space_x = ai_settings.screen_width - 2 * alien_width
    number_aliens_x = int(available_space_x/ (2 * alien_width))


    # Create the first row of aliens.
    for alien_number in range(number_aliens_x):
        # Create an alien and place it in the row.
        alien = Alien(ai_settings, screen)
        alien.x = alien_width + 2 * alien_width * alien_number
        alien.rect.x = alien.x
        aliens.add(alien)
开发者ID:jonnybarca,项目名称:Alien_Invasion,代码行数:17,代码来源:game_functions.py

示例13: create_fleet

def create_fleet(ai_settings, screen, aliens):

    """创建外星人群"""
    # 创建一个外星人, 并计算一行可容纳多少个外星人
    # 外星人间距为外星人宽度
    alien = Alien(ai_settings, screen)
    alien_width = alien.rect.width
    available_space_x = ai_settings.screen_width - 2*alien_width
    number_aliens_x = int(available_space_x/(2*alien_width))

    # 创建第一个外星人
    for alien_number in range(number_aliens_x + 1):
        # 创建一个外星人并将其加入当前行
        alien = Alien(ai_settings, screen)
        alien.x = alien_width + 2 * alien_width * alien_number
        alien.rect.x = alien.x
        aliens.add(alien)
开发者ID:gzzwinner,项目名称:alien_invasion,代码行数:17,代码来源:game_functions.py

示例14: loop

    def loop(self):
        count = 0
        while 1:
            count = (count+1)%50
            self.clock.tick(25)

            #handle input events
            ok = self.handle_keys()
            if ok == False:
                return

            if self.game_started == False:
                start_text = self.font.render('Press any key to start', 2, (0,0,0))
                self.screen.blit(start_text, (150, 200))
                pygame.display.flip()
                continue

            if self.game_paused == 1:
                start_text = self.font.render('Game paused', 2, (255,255,255))
                self.screen.blit(start_text, (150, 200))
                pygame.display.flip()
                continue

            new_enemies = self.level.getenemies() 

            for enemy_y in new_enemies:
                #if random.randint(0,50) == 0:
                alien = Alien(enemy_y)
                alien.set_target(self.ship)
                self.enemies.add(alien)

            #aliens damaging the player, remove them
            damage  = pygame.sprite.spritecollide(self.ship, self.enemies, True)

            self.process_powerups()

            #check colisions with stage
            if self.level.checkcollide(self.ship.rect):
                #add some fancy explosions in the damage area
                self.explosions.add(Explosion(pygame.Rect(self.ship.rect.x,self.ship.rect.y,0,0)))
                damage.append(1)

            #Apply damages to the player
            if len(damage) > 0:
                self.background.warning()
                self.ship.damage()
                self.lifemeter.shake()
                self.explosions.add(Explosion(self.ship.rect))
                self.sounds['warning'].play()
                self.lifemeter.life = self.ship.life
                if self.lifemeter.life < 1:
                    self.game_finished = True
                    self.sounds['warning'].stop()

            #print (pygame.sprite.spritecollide(ship, level, True))

            #aliens hit by the fire, remove them
            penetration = self.ship.powerup['penetrate']
            for fireball in self.fire:
                hit = pygame.sprite.spritecollide(fireball, self.enemies, True)
                for dead in hit:
                    if dead.has_powerup():
                        powerup = Powerup(dead.rect, dead.value)
                        self.powerups.add(powerup)
                    self.explosions.add(Explosion(pygame.Rect(dead.rect.x,dead.rect.y,0,0)))
                    self.score+=dead.value*1000
                    if penetration == False:
                        fireball.kill()

            #draw the level

            all_sprites = pygame.sprite.Group()
            all_sprites.add(self.player.sprites())
            all_sprites.add(self.enemies.sprites())
            all_sprites.add(self.powerups.sprites())
            all_sprites.add(self.fire.sprites())
            all_sprites.add(self.hud.sprites())
            all_sprites.add(self.explosions.sprites())
            all_sprites.update()
            self.level.update()
            self.background.update()

            #Move and draw the background

            score_text = 'Score: {0}'.format((self.score))

            text = self.font.render(score_text, 1, (255, 255, 255))
            text_shadow = self.font.render(score_text, 1, (0,0,0))

            self.screen.blit(self.background, (0, 0))
            self.screen.blit(self.level, (0, 0))
            self.screen.blit(text_shadow, (12, 12))
            self.screen.blit(text, (10, 10))

            if self.game_finished == True:
                gameover_text = self.font.render("Game Over", 2, (255, 255, 255))
                self.screen.blit(gameover_text, (280, 200))
                gameover_text = self.font.render("Press Esc", 2, (255, 255, 255))
                self.screen.blit(gameover_text, (280, 230))
            else:
#.........这里部分代码省略.........
开发者ID:codelurker,项目名称:VacuumFire,代码行数:101,代码来源:main.py

示例15: setUp

 def setUp(self):
     self.constraint = (1000, 1000)
     self.alien = Alien(self.constraint, 100, 100, Directions.left, 1)
开发者ID:gvpavlov,项目名称:Insaniquarium,代码行数:3,代码来源:alien_test.py


注:本文中的alien.Alien类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。