Exemplo n.º 1
0
def create_map(number_of_rooms, soldier, scripted_levels={}):
    # the first room is empty, since the player starts there
    options = ['Sectoid', 'Thinman', 'Floater', 'Muton']
    pods = [[]]
    for i in range(1, number_of_rooms):
        if i in scripted_levels:
            pods.append(scripted_levels[i])
        else:
            pod = []
            # more aliens per room the further along you are
            for j in range(3 + random.randrange(-2, 2 + round(i / 10))):
                # determine alien species
                species = options[0]
                nrank = 0
                if 3 < i and i < 10:
                    species = random.choice(options[:2])
                elif 10 <= i and i < 20:
                    species = random.choice(options)
                else:
                    species = random.choice(options[2:])
                # determine rank
                # if species == 'Sectoid':
                maxrank = 4
                if species == 'Thinman':
                    maxrank = 5
                elif species == 'Floater':
                    maxrank = 6
                elif species == 'Muton':
                    maxrank = 8
                nrank = random.randrange(round(i / (number_of_rooms /
                                                    (maxrank - 1))), maxrank)
                alien = create_alien(j, i, species, nrank=nrank)
                pod.append(alien)
            pods.append(pod)
    return Map(pods, soldier)
Exemplo n.º 2
0
def main():
    textcom.globals_hack_init()

    print("Bradford: Welcome Commander. We've discovered an Alien Base, and "
          "it's your job to send someone out to deal with it.")
    print('Bradford: Choose a soldier from the 3 below to go on the mission.')

    barracks = []
    #generates soldiers
    for i in range(3):
        x = create_soldier(i)
        barracks.append(x)

    #displays a list of the soldiers
    for i in range(len(barracks)):
        print(str(i + 1) + ': ')
        barracks[i].print_summary()
        print()

    #forces you to pick only one soldier
    soldier = barracks[get_int_input('# ', 1, 3) - 1]

    if soldier.lastname == "Bradford":
        soldier.say("What? There must have been a mistake on the sheet, "
                    "Commander! You can't send --")
    elif soldier.lastname == "Van Doorn":
        soldier.say("I'm the Ops team?")
    else:
        soldier.say('Ready for duty, Commander!')

    scripted_levels = {
        1:  [create_alien(1, 1, 'Sectoid', nrank=0)],
        2:  [
                create_alien(1, 2, 'Sectoid', nrank=0),
                create_alien(1, 2, 'Sectoid', nrank=0)
            ],
        3:  [
                create_alien(1, 3, 'Sectoid', nrank=0),
                create_alien(1, 3, 'Sectoid', nrank=1)
            ],
        5:  ["Drop Zone"],
        10: ["Drop Zone"],
        15: ["Drop Zone"],
        20: ["Drop Zone"],
        30: [create_alien(1, 1, 'Muton', nrank=8, hp=50)]
    }

    game_map = create_map(NUMBER_OF_ROOMS, soldier, scripted_levels)
    # dump_map(game_map)

    # Yeah, I feel pretty bad about this, but currently I have no idea how to
    # make the current room index available for the death handler score
    # .calculation.  Maybe everything works out fine if components are
    # introduced.  I hope so.
    soldier.game_map = game_map

    #game loop, runs until your soldier is killed
    while soldier.alive == True:
        try:
            old_room = game_map.get_current_room()
            playerTurn(game_map)
            status(str(soldier) + ' is out of AP!')

            current_room = game_map.get_current_room()
            # Aliens are not allowed to act after the room was changed,
            # because they already scattered when the player entered the new
            # room.  Also, there is no need for an alien turn if there are
            # no more aliens in the room.
            if soldier.alive == True and old_room == current_room             \
               and len(current_room) > 0:
                print()
                print("--------------Alien Activity!--------------")
                print()
                time.sleep(1)
                alienTurn(game_map)
                print()
                print("--------------XCOM Turn--------------")
                print()
        except ( ValueError or IndexError ):
            pass
        if game_map.current_room == len(game_map.rooms):
            print("You have won the game!")
            break
Exemplo n.º 3
0
def test_create_alien():
    # this function could be regarded trivial, but the **kwargs stuff is not
    # that intuitive, so test coverage is good

    # test all accepted species
    alien_species = ['Sectoid', 'Thinman', 'Floater', 'Muton']
    for species in alien_species:
        a = create_alien(0, 0, species)
        assert a.species == species
    # test invalid species detection
    exception = None
    try:
        a = create_alien(0, 0, 'Ayy')
    except Exception as e:
        exception = e
    assert exception is not None
    assert str(exception) == 'Unknown alien species'

    # test correct rank handling
    # the value 10 is used because it's not a real rank, that could be
    # generated by the function
    species = 'Sectoid'
    rank = 10
    a = create_alien(0, 0, species, nrank=rank)
    assert a.nrank == rank
    assert a.hp == rank + ALIEN_SPECIES[species][SPECIES_HP_BASE]
    assert rank + ALIEN_SPECIES[species][SPECIES_AIM_RANGE][0] <= a.aim
    assert a.aim < rank + ALIEN_SPECIES[species][SPECIES_AIM_RANGE][1]
    assert rank + ALIEN_SPECIES[species][SPECIES_MOBILITY_RANGE][0]           \
           <= a.mobility
    assert a.mobility                                                         \
           < rank + ALIEN_SPECIES[species][SPECIES_MOBILITY_RANGE][1]
    assert a.firstname in sectoidfName
    assert a.lastname in sectoidlName
    assert a.armour == 'BDY'
    assert type(a.weapon) == ALIEN_SPECIES[species][SPECIES_WEAPON_CLASS]
    assert len(a.items) == 1
    assert a.items[0] in ALIEN_DEFAULT_ITEMS
    assert len(a.mods) == 0

    # test correct overrides
    hp_value = 2
    aim_value = 2
    mobility_value = 2
    firstname_value = 'Ayy'
    lastname_value = 'Lmao'
    armour_value = 'LOLarmour'
    weapon_value = 'LOLweapon'
    items_value = [1,2]
    mods_value = [1, 2]
    a = create_alien(0, 0, species, nrank=rank, hp=hp_value, aim=aim_value,
                     mobility=mobility_value, firstname=firstname_value,
                     lastname=lastname_value, armour=armour_value,
                     weapon=weapon_value, items=items_value, mods=mods_value)
    assert a.aim == aim_value
    assert a.hp == hp_value
    assert a.mobility == mobility_value
    assert a.firstname == firstname_value
    assert a.lastname == lastname_value
    assert a.armour == armour_value
    assert a.weapon == weapon_value
    assert a.items == items_value
    assert a.mods == mods_value