Ejemplo n.º 1
0
    def create_fighters(self):
        list_of_fighters_name = [
            "Goro", "Quan Chi", "Scorpion", "Ermac", "Sub-Zero", "Nub"
        ]

        list_of_fighters = []
        for name in list_of_fighters_name:
            list_of_fighters.append(
                fighter.Fighter(name, self.fighting_style_generator()))

        return list_of_fighters
Ejemplo n.º 2
0
    def execute(self):
        name = input("Give a name to this fighter: ")

        while True:
            choice_type = ways_to_choose.WaysToChoose

            print("How do you want to choose  fighting style.")
            user_choice = options_to_choose.OptionsToChoose().offering_options(
                choice_type)

            subclasses = self.fighting_style_type_classes()
            fighting_style_of_user_choice = factory.FactoryForAttackMainClass(
            ).create(user_choice, choice_type, subclasses)
            print(fighting_style_of_user_choice)
            costume_fighter = fighter.Fighter(name,
                                              fighting_style_of_user_choice)
            return costume_fighter
Ejemplo n.º 3
0
    def fighter(self):
        if self.START:  #初始化战机的位置在中心
            self.me1_rect = aircraftimage.me1.get_rect()
            self.fighterposition = ((self.width - self.me1_rect.width) // 2,
                                    self.height - self.me1_rect.height)
            self.me1_rect.center = (self.width // 2,
                                    self.height - self.me1_rect.height // 2)
            self.our_fighter.rect = self.me1_rect
            self.our_fighter.rect.center = self.me1_rect.center
            self.fighters.append(self.our_fighter)
            self.START = False
        else:
            self.me1_rect = self.me1_rect.move(self.fighter_move_speed)
            if self.me1_rect.top > self.height - self.me1_rect.height:
                self.me1_rect.top = self.height - self.me1_rect.height
            if self.me1_rect.left + self.me1_rect.width > self.width:
                self.me1_rect.left = self.width - self.me1_rect.width
            if self.me1_rect.top < 0:
                self.me1_rect.top = 0
            if self.me1_rect.left < 0:
                self.me1_rect.left = 0
            self.fighterposition = (self.me1_rect.left, self.me1_rect.top)
            self.our_fighter.rect = self.me1_rect

        for each in self.fighters:
            self.screen.blit(each.image, self.fighterposition)
        if len(self.fighters) == 0:
            self.LAUNCHBULLET = False
        if self.SHIELD:
            self.shield_position = (self.me1_rect.left -
                                    self.me1_rect.width // 4,
                                    self.me1_rect.top -
                                    self.me1_rect.height // 8)
            self.our_fighter = fighter.Fighter(self.shield_img,
                                               self.shield_position)
            self.screen.blit(self.shield_img, self.shield_position)
        bullet_position = (self.fighterposition[0] + self.me1_rect.width // 2,
                           self.fighterposition[1])
        speed = [0, -40]
        bullet_img = aircraftimage.bullet3
        if self.LAUNCHBULLET:
            self.launch_bullet(bullet_img, bullet_position, speed)
Ejemplo n.º 4
0
    def initiate_game(self):
        level = self.menu_system.level_selected
        leveldata = self.menu_system.database.leve_loader.get_Level(level)

        for i in range(leveldata[0]):
            figh = fighter.Fighter()
            figh.launched_missiles = self.missiles
            self.fighters.add(figh)
            figh.otherFighters = self.fighters
            figh.pos = [(i + 1) * -400, (i + 1) * 231]

        for i in range(leveldata[1]):
            figh = fighter.EmpFighter()
            self.fighters.add(figh)
            figh.active_emp = self.emps
            figh.otherFighters = self.fighters
            figh.pos = [(i + 1) * -800, (i + 1) * -400]

        self.player = player.Player()
        self.player.pos = [500, 0]
Ejemplo n.º 5
0
    def get_fighter(initial, agent_class, agent_params):
        """
        Creates a Fighter with the specified initial conditions and agent.

        Args:
            initial (string): path to the json file specifying the initial
              conditions for the fighter
            agent_class (string): qualified name of the class of the agent
            agent_params (string): path to the json file specifying any
              parameters required by the agent

        Returns:
            (Fighter): an initialised fighter entity
        """
        AgentClass = get_class(agent_class)
        if not issubclass(AgentClass, Agent):
            # TODO: replace with logger warning
            print("Warning: Agent class specified in scenario is not a " +
                  "subclass of Agent '" + agent_class + "'")
        pilot = AgentClass(params_filename=agent_params)
        assert pilot is not None
        return fighter.Fighter(initial, pilot)
Ejemplo n.º 6
0
class AircraftWar:
    EIXT = False  #游戏是否退出
    GAMEOVER = False  #游戏是否结束
    LAUNCHBULLET = True  #战机发是否处于战斗状态
    our_bullets = []  #子弹列表
    enemys = []  #敌机列表
    enemys_img = [
        aircraftimage.enemy1_down1, aircraftimage.enemy1_down2,
        aircraftimage.enemy1_down3, aircraftimage.enemy1_down4
    ]
    START = True  #是否是游戏初始化,用于放置初始战机的位置

    fighter_img = aircraftimage.me1
    shield_img = aircraftimage.shield01
    shield_position = (0, 0)
    our_fighter = fighter.Fighter(fighter_img, shield_position)
    fighters = []
    fighterposition = (0, 0)  #战机位置
    me1_rect = (0, 0, 0, 0)  #战机的矩形
    fighter_move_speed = [0, 0]  #键盘控制战机的移动速度
    SHIELD = False  #防护罩是否开启

    def __init__(self):
        pygame.init()
        pygame.mixer.init()

        self.bgsize = self.width, self.height = 520, 600
        self.screen = pygame.display.set_mode(self.bgsize)
        self.title = pygame.display.set_caption('飞机大战', 'icon/title_icon.jpg')

        #设置背景音乐
        pygame.mixer.music.load('sound/game_music.ogg')
        pygame.mixer.music.set_volume(0.5)
        pygame.mixer.music.play()

        self.clock = pygame.time.Clock()

        #设置鼠标图标
        self.mouse_iocn = pygame.image.load('icon/hand_meitu_2.png').convert()
        self.mouse_iocn.set_colorkey((255, 255, 255))
        #pygame.mouse.set_visible(False)

    def event_processing(self):
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit(0)
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_SPACE:
                    self.GAMEOVER = True
                if event.key == pygame.K_UP:
                    self.fighter_move_speed = [0, -10]
                if event.key == pygame.K_DOWN:
                    self.fighter_move_speed = [0, 10]
                if event.key == pygame.K_LEFT:
                    self.fighter_move_speed = [-10, 0]
                if event.key == pygame.K_RIGHT:
                    self.fighter_move_speed = [10, 0]
            if event.type == pygame.KEYUP:
                if event.key == pygame.K_UP:
                    self.fighter_move_speed = [0, 0]
                if event.key == pygame.K_DOWN:
                    self.fighter_move_speed = [0, 0]
                if event.key == pygame.K_LEFT:
                    self.fighter_move_speed = [0, 0]
                if event.key == pygame.K_RIGHT:
                    self.fighter_move_speed = [0, 0]

    def background_fill(self):
        self.screen.blit(backgroundload.background_2, (0, 0))

    '''己方战机'''

    def fighter(self):
        if self.START:  #初始化战机的位置在中心
            self.me1_rect = aircraftimage.me1.get_rect()
            self.fighterposition = ((self.width - self.me1_rect.width) // 2,
                                    self.height - self.me1_rect.height)
            self.me1_rect.center = (self.width // 2,
                                    self.height - self.me1_rect.height // 2)
            self.our_fighter.rect = self.me1_rect
            self.our_fighter.rect.center = self.me1_rect.center
            self.fighters.append(self.our_fighter)
            self.START = False
        else:
            self.me1_rect = self.me1_rect.move(self.fighter_move_speed)
            if self.me1_rect.top > self.height - self.me1_rect.height:
                self.me1_rect.top = self.height - self.me1_rect.height
            if self.me1_rect.left + self.me1_rect.width > self.width:
                self.me1_rect.left = self.width - self.me1_rect.width
            if self.me1_rect.top < 0:
                self.me1_rect.top = 0
            if self.me1_rect.left < 0:
                self.me1_rect.left = 0
            self.fighterposition = (self.me1_rect.left, self.me1_rect.top)
            self.our_fighter.rect = self.me1_rect

        for each in self.fighters:
            self.screen.blit(each.image, self.fighterposition)
        if len(self.fighters) == 0:
            self.LAUNCHBULLET = False
        if self.SHIELD:
            self.shield_position = (self.me1_rect.left -
                                    self.me1_rect.width // 4,
                                    self.me1_rect.top -
                                    self.me1_rect.height // 8)
            self.our_fighter = fighter.Fighter(self.shield_img,
                                               self.shield_position)
            self.screen.blit(self.shield_img, self.shield_position)
        bullet_position = (self.fighterposition[0] + self.me1_rect.width // 2,
                           self.fighterposition[1])
        speed = [0, -40]
        bullet_img = aircraftimage.bullet3
        if self.LAUNCHBULLET:
            self.launch_bullet(bullet_img, bullet_position, speed)

    '''敌方战机'''

    def enemy_fighters(self):
        if random.randint(0, 5) == 1:
            position = (random.randint(1, self.width), 0)
            self.screen.blit(aircraftimage.enemy1, position)
            enemy_img = aircraftimage.enemy1
            speed = [0, 5]
            enemy_obj = enemy.Enemy(enemy_img, position, speed, self.bgsize)
            self.enemys.append(enemy_obj)

        for each in self.enemys:
            if each.move():
                self.screen.blit(each.image, (each.rect[0], each.rect[1]))
            else:
                self.enemys.remove(each)

    '''检测子弹与战机是否碰撞'''

    def detect_collision(self, source, destination, dest_img):
        source_need_remove = []
        destination_need_remove = []
        for i in source:
            for j in destination:
                if (math.sqrt((i.rect.center[0] - j.rect.center[0])**2 +
                              (i.rect.center[1] - j.rect.center[1])**2) <
                        i.rect.height // 2 + j.rect.height // 2):
                    source_need_remove.append(i)
                    j.collide_count += 1
                    if j.collide_count < len(dest_img) + 1:
                        j.image = dest_img[j.collide_count - 1]
                    elif j.collide_count == len(dest_img) + 1:
                        destination_need_remove.append(j)
        for each in source_need_remove:
            try:
                source.remove(each)
            except:  #这里抛出异常的原因是,这个子弹已经被我在launch_bullet函数里处理掉了,一旦子弹超出屏幕我就会处理掉
                pass
        for each in destination_need_remove:
            destination.remove(each)

    '''检测战机与敌机是否碰撞'''

    def detect_fighter_enemy_collision(self, source, destination, dest_img):
        source_need_remove = []
        destination_need_remove = []
        for i in source:
            for j in destination:
                if (i.rect.left > j.rect.left  and i.rect.left + i.rect.width < j.rect.left + j.rect.width) and \
                        (i.rect.top > j.rect.top and i.rect.top + i.rect.height < j.rect.top + j.rect.height):
                    source_need_remove.append(i)
                    j.collide_count += 1
                    if j.collide_count < len(dest_img) + 1:
                        j.image = dest_img[j.collide_count - 1]
                    else:
                        destination_need_remove.append(j)
        for each in source_need_remove:
            try:
                source.remove(each)
            except:
                pass
        for each in destination_need_remove:
            destination.remove(each)

    '''发射子弹'''

    def launch_bullet(self, bullet_img, position, speed):
        bullet_obj = bullet.Bullet(bullet_img, position, speed, self.bgsize)
        self.our_bullets.append(bullet_obj)
        for each in self.our_bullets:
            if each.move():
                self.screen.blit(each.image, (each.rect[0], each.rect[1]))
            else:
                self.our_bullets.remove(each)

    def run(self):
        while not self.EIXT:
            self.event_processing()
            self.background_fill()

            self.fighter()
            self.enemy_fighters()
            self.detect_collision(self.our_bullets, self.enemys,
                                  self.enemys_img)
            if not self.SHIELD:
                self.detect_fighter_enemy_collision(
                    self.enemys, self.fighters, [
                        aircraftimage.me_destroy_1, aircraftimage.me_destroy_2,
                        aircraftimage.me_destroy_3, aircraftimage.me_destroy_4
                    ])
            else:
                pass

            if self.LAUNCHBULLET:
                promptsound.bullet.play()
                promptsound.bullet.set_volume(0.1)

            if self.GAMEOVER:
                position = pygame.mouse.get_pos()
                self.screen.blit(self.mouse_iocn, position)
                promptsound.me_down.play()
                promptsound.me_down.set_volume(0.4)
                self.LAUNCHBULLET = False
                self.GAMEOVER = False

            #检查背景音乐是否在播放,如果没有播放则开启播放
            if not pygame.mixer.music.get_busy():
                pygame.mixer.music.play()

            pygame.display.update()
            self.clock.tick(20)
Ejemplo n.º 7
0
import glob, os, random

import game, fighter

DIR = os.path.dirname(__file__)

# get a list of available fighters
fighters = glob.glob(os.path.join(DIR, "fighters", "*"))

# create a fighting roster
for fighter_path1 in fighters:
    for fighter_path2 in fighters:
        # create the left fighter
        f1 = fighter.Fighter(fighter_path1)
        # create the right fighter
        f2 = fighter.Fighter(fighter_path2)
        # launch the game
        game.Game(f1, f2).process()
Ejemplo n.º 8
0
	def handler(self,pickedClass):
		if pickedClass == 'barbarian':
			self.tab_window.main_window.classes=barbarian.Barbarian(['Nature','Perception'],['Great-Axe','Two Handaxe','Explorer Pack with 4 Javelins'])	
			self.label.setText("Barbarian\n{}".format(self.tab_window.main_window.classes.__str__()))
			self.classSelected = True

		elif pickedClass == 'bard':
			self.tab_window.main_window.classes=bard.Bard(['Persuasion', 'Stealth','Nature'],['Rapier','Diplomat Pack'],['Flute'],['Dancing Lights','Viscous Mockery'],['Charm Person','Detect Magic','Healing Word','Thunderwave'])			
			self.label.setText("Bard\n{}".format(self.tab_window.main_window.classes.__str__()))


		elif pickedClass == 'cleric':
			self.tab_window.main_window.classes=cleric.Cleric(['Persuasion','Religion'],['Mace','Scale Mail','Light Crossbow','Priest Pack','Shield'],['Guidance','Light','Mending'],['Command','Identify'],'Light Domain')			
			self.label.setText("Cleric\n{}".format(self.tab_window.main_window.classes.__str__()))


		elif pickedClass == 'druid':
			self.tab_window.main_window.classes=druid.Druid(["Animal Handling","Survival"],['Wooden Shield','Scimitar','Leather Armor','Explorers Pack','Druidic Focus'],['Posion Spray','Frostbite'],["Calm Animal","Charm Animal"])			
			self.label.setText("Druid\n{}".format(self.tab_window.main_window.classes.__str__()))


		elif pickedClass == 'fighter':
			self.tab_window.main_window.classes=fighter.Fighter(['Intimidation','Athletics'],['Chain Mail','Martial Weapon and Shield','Light Crossbow and 20 bolts','Dungeoneers pack'],'Dueling')			
			self.label.setText("Fighter\n{}".format(self.tab_window.main_window.classes.__str__()))


		elif pickedClass == 'monk':
			self.tab_window.main_window.classes=monk.Monk(['Acrobatics','Stealth'],['Shortsword','Dungeoneer pack','10 Darts'],'Guitar')
			self.label.setText("Monk\n{}".format(self.tab_window.main_window.classes.__str__()))

		
		elif pickedClass == 'paladin':
			self.tab_window.main_window.classes=paladin.Paladin(['Medicine','Religion'],['Martial weapon and Shield','5 Javelins','Priest Pack','Chain Mail','Holy Symbol'])
			self.label.setText("Paladin\n{}".format(self.tab_window.main_window.classes.__str__()))



		elif pickedClass == 'ranger':
			self.tab_window.main_window.classes=ranger.Ranger(['Animal Handling','Nature'],['Scale Mail','Two shortswords','Dungeoneer pack','Longbow 20 arrows'])			
			self.label.setText("Ranger\n{}".format(self.tab_window.main_window.classes.__str__()))
			

		elif pickedClass == 'rogue':
			self.tab_window.main_window.classes=rogue.Rogue(['Stealth','Sleight of Hand','Investigation','Athletics'],['Rapier','Shortbow with 20 arrows','Burglars pack','Leather Armor','Two daggers',"Thieve's tools"],'Thieve\'s Tools','Stealth')			
			self.label.setText("Rogue\n{}".format(self.tab_window.main_window.classes.__str__()))
			
		elif pickedClass == 'sorcerer':
			self.tab_window.main_window.classes=sorcerer.Sorcerer(['Arcana','Insight'],['Light crossbow 20 bolts','Component pouch','Dungeoneers pack','Two Daggers'],['Light','Prestidigitation','Ray of frost','Shocking grasp'],['Shield','Magic missile'],'Bloodline')
			self.label.setText("Sorceror\n{}".format(self.tab_window.main_window.classes.__str__()))
			


		elif pickedClass == 'warlock':
			self.tab_window.main_window.classes=warlock.Warlock(["Arcana","Religion"],['Light crossbow 20 bolts','Component pouch','Scholars pack','Leather Armor','Shortsword','Two daggers'],['Eldrich blast','Chill touch'],['Ray of sickness','Witch bolt'],'The Fiend')	
			self.label.setText("Warlock\n{}".format(self.tab_window.main_window.classes.__str__()))
			


		elif pickedClass == 'wizard':
			self.tab_window.main_window.classes=wizard.Wizard(['History','Insight'],['Quarterstaff','Component pouch','Scholar pack','Spellbook'],['Mage hand','Light','Ray of Frost'],['Burning hands','Charm person','Feather fall','Mage armor','Missile','Sleep'])			
			self.label.setText("Wizard\n{}".format(self.tab_window.main_window.classes.__str__()))
		
		self.classSelected = True