Пример #1
0
 def phasers(game):
     if game.enterprise.phaser_damage > 0:
         game.display(Quips.jibe_damage("phaser"))
         game.display()
         return
     kships = game.game_map.get_area_klingons()
     if len(kships) == 0:
         game.display(_("There are no Klingon ships in this sector."))
         game.display()
         return
     game.display(_("Phasers locked on target."))
     phaser_energy = game.read_double(
         _("Enter phaser energy (1--{0}): ").format(game.enterprise.energy))
     if not phaser_energy or phaser_energy < 1 or phaser_energy > game.enterprise.energy:
         game.display(_("Invalid energy level."))
         game.display()
         return
     game.display()
     game.display(_("Firing phasers..."))
     destroyed_ships = []
     for ss, ship in enumerate(kships):
         game.enterprise.energy -= int(phaser_energy)
         if game.enterprise.energy < 0:
             game.enterprise.energy = 0
             break
         dist = Calc.distance(game.game_map.xpos, game.game_map.ypos,
                              ship.xpos, ship.ypos)
         delivered_energy = phaser_energy * (1.0 - dist / 11.3)
         ship.shield_level -= int(delivered_energy)
         if ship.shield_level <= 0:
             game.display(
                 _("Enemy ship destroyed at [{xpos},{ypos}].").format(
                     xpos=ship.xpos + 1, ypos=ship.ypos + 1))
             game.display(Quips.jibe_defeat('enemy'))
             destroyed_ships.append(ship)
         else:
             game.display(
                 _("Hit ship at [{xpos},{ypos}].").format(
                     xpos=ship.xpos + 1, ypos=ship.ypos + 1))
             game.display(
                 _("Enemy shield down to {shield_level}.").format(
                     shield_level=ship.shield_level))
     game.game_map.remove_area_items(destroyed_ships)
     if game.game_map.count_area_klingons() > 0:
         game.display()
         ShipKlingon.attack_if_you_can(game)
     game.display()
     game.enterprise.damage(game, Probabilities.PHASERS)
Пример #2
0
    def long_range_scan(self, game):
        if self.long_range_scan_damage > 0:
            game.display(Quips.jibe_damage('long ranged scanner'))
            game.display()
            return

        pw_sector = game.game_map.sector
        if pw_sector < 4:
            pw_sector = 5
        elif pw_sector > 60:
            pw_sector = 60
        lines = []
        for peek in range(pw_sector - 4, pw_sector + 5):
            quad = game.game_map.scan_sector(peek)
            lines.append(f"SEC: {quad.number:>03}")
            lines.append(f"{Glyphs.KLINGON}: {quad.area_klingons:>03}")
            lines.append(f"{Glyphs.STARBASE}: {quad.area_starbases:>03}")
            lines.append(f"{Glyphs.STAR}: {quad.area_stars:>03}")
        dots = '     +' + ('-' * 35) + '+'
        game.display(dots)
        game.display(_('     |          LONG RANGE SCAN          |'))
        game.display(dots)
        for ss in range(0, (len(lines) - 1), 12):
            for offs in range(4):
                line = f'     | {lines[ss+offs]:<9} | {lines[ss+4+offs]:<9} | {lines[ss+8+offs]:<9} |'
                game.display(line)
            game.display(dots)
        game.display()
        if not game.enterprise.repair(game):
            game.enterprise.damage(game, Probabilities.SRS)
Пример #3
0
 def damage(self, game, item):
     '''
     Damage the Enterprise.
     '''
     if not Probabilities.should_damage_enterprise(game, item):
         return
     damage = Probabilities.calc_damage(game, item)
     if item < 0:
         item = random.randint(0, 6)
     if item == 0:
         self.navigation_damage = damage
         game.display(Quips.jibe_damage('warp engine'))
     elif item == 1:
         self.short_range_scan_damage = damage
         game.display(Quips.jibe_damage('short range scanner'))
     elif item == 2:
         self.long_range_scan_damage = damage
         game.display(Quips.jibe_damage('long range scanner'))
     elif item == 3:
         self.shield_control_damage = damage
         game.display(Quips.jibe_damage('shield control'))
     elif item == 4:
         self.computer_damage = damage
         game.display(Quips.jibe_damage('main computer'))
     elif item == 5:
         self.photon_damage = damage
         game.display(Quips.jibe_damage('torpedo controller'))
     elif item == 6:
         self.phaser_damage = damage
         game.display(Quips.jibe_damage('phaser'))
     game.display()
Пример #4
0
 def short_range_scan(self, game):
     if self.short_range_scan_damage > 0:
         game.display(Quips.jibe_damage('short ranged scanner'))
         game.display()
     else:
         quad = game.game_map.get_pw_sector()
         Sector.display_area(game, quad)
     game.display()
     if not game.enterprise.repair(game):
         game.enterprise.damage(game, Probabilities.SRS)
Пример #5
0
    def run(self):
        '''
        The game loop - runs until the game is over.
        '''

        fr = gettext.translation('startrek2020', localedir='locale', languages=['fr'])
        fr.install()

        self.show_strings(TrekStrings.LOGO_TREKER)
        game.star_date = random.randint(2250, 2300)
        game.time_remaining = random.randint(40, 45)
        game.destroyed = False
        stars     = random.randint(500, 700) # 4096 = ALL
        aliens    = random.randint(14, 24)
        starbases = random.randint(6, 8)
        game.game_map.randomize(starbases, stars, aliens)
        dest = WarpDest(64, 0)
        game.move_to(dest)
        game.game_map.get_area(64).name = 'Outer Limits'
        self.print_mission()

        self.show_strings(TrekStrings.HELM_CMDS)
        running = True
        try:
            while self.game_on():
                if not self.command_prompt():
                    break
                if self.is_testing:
                    self.destoryed = False
                    ShipStarbase.dock_enterprise(self.enterprise)
                    ShipStarbase.launch_enterprise(self.enterprise)
                    self.enterprise.shield_level = 1000
                    
        except ErrorEnterpriseCollision as ex:
            if ex.glyph == Glyphs.KLINGON:
                self.display(_("You flew into a KLINGON!"))
            if ex.glyph == Glyphs.STARBASE:
                self.display(_("You flew into a STARBASE?"))
            if ex.glyph == Glyphs.STAR:
                self.display(_("You flew into a STAR?"))
            self.destroyed = True
        game.display()
        Stats.show_exit_status(game)
        game.display()
        if self.destroyed == True:
            self.display(Quips.jibe_fatal_mistake())
        game.display()
        return False
Пример #6
0
 def show_exit_status(game):
     if game.destroyed:
         msg = _("MISSION FAILED: SHIP DESTROYED")
         game.show_banner([msg], '!')
     elif game.enterprise.energy == 0:
         msg = _("MISSION FAILED: OUT OF ENERGY.")
         game.show_banner([msg], '!')
     elif game.game_map.game_klingons == 0:
         msg = _("MISSION ACCOMPLISHED"), _("ENEMIES DESTROYED"), _(
             "WELL DONE!")
         game.show_banner(msg)
     elif game.time_remaining == 0:
         msg = _("MISSION FAILED: OUT OF TIME.")
         game.show_banner([msg], '!')
     else:
         ary = [_("::::::::: MISSION ABORTED :::::::::"), Quips.jibe_quit()]
         game.show_banner(ary, ':')
Пример #7
0
 def computer(game):
     if game.enterprise.computer_damage > 0:
         game.display(Quips.jibe_damage('computer'))
         game.display()
         return
     game.show_strings(TrekStrings.CPU_CMDS)
     command = game.read(_("Enter computer command: ")).strip().lower()
     if command == "rec":
         Stats.show_galactic_status(game)
     elif command == "sta":
         Stats.show_ship_status(game)
     elif command == "tor":
         Calc.show_torp_targets(game)
     elif command == "bas":
         Calc.show_starbase(game)
     else:
         game.display()
         game.display(_("Invalid computer command."))
         game.display()
     game.enterprise.damage(game, Probabilities.COMPUTER)
Пример #8
0
 def torpedos(game):
     if game.enterprise.photon_damage > 0:
         game.display(Quips.jibe_damage('photon launcher'))
         game.display()
         return
     if game.enterprise.photon_torpedoes == 0:
         game.display(_("Photon torpedoes exhausted."))
         game.display()
         return
     if game.game_map.count_area_klingons() == 0:
         game.display(_("There are no Klingon ships in this sector."))
         game.display()
         return
     shot = game.read_xypos()
     if not shot:
         game.display(_("Invalid shot."))
         game.display()
         return
     game.display()
     game.display(_("Photon torpedo fired..."))
     game.enterprise.photon_torpedoes -= 1
     hit = False
     for ship in game.game_map.get_area_objects():
         if game.is_testing:
             print(
                 f'{ship.glyph}({ship.xpos},{ship.ypos}), shot({shot.xpos},{shot.ypos})'
             )
         if ship.xpos == shot.xpos and ship.ypos == shot.ypos:
             if ship.glyph == Glyphs.KLINGON:
                 num = game.game_map.get_game_id(ship)
                 game.display(
                     _("Klingon ship #{num} destroyed.").format(num=num))
                 game.display(Quips.jibe_defeat('enemy'))
                 game.game_map.remove_area_items([ship])
                 hit = True
                 break
             elif ship.glyph == Glyphs.STARBASE:
                 game.game_map.game_starbases -= 1
                 num = game.game_map.get_game_id(ship)
                 game.display(
                     _("Federation Starbase #{num} destroyed!").format(
                         num=num))
                 game.display(Quips.jibe_defeat('commander'))
                 game.game_map.remove_area_items([ship])
                 hit = True
                 break
             elif ship.glyph == Glyphs.STAR:
                 num = game.game_map.get_game_id(ship)
                 game.display(
                     _("Torpedo vaporizes star #{num}!").format(num=num))
                 game.display(Quips.jibe_defeat('academic'))
                 game.game_map.remove_area_items([ship])
                 hit = True
                 break
     if not hit:
         game.display(_("Torpedo missed."))
     if game.game_map.count_area_klingons() > 0:
         game.display()
         ShipKlingon.attack_if_you_can(game)
     game.display()
     game.enterprise.damage(game, Probabilities.PHOTON)