Exemplo n.º 1
0
def prepare_battle(battle):
    if battle:
        return battle

    dragon = Dragon('Valakas')
    #ten people figth with them!
    brave_people = [Player() for _ in xrange(10)]
    battle = Battle(dragon, brave_people)
    battle.started = True
    return battle
Exemplo n.º 2
0
def main():
    rpgbs_init()
    while 1:
        SimpleIOHandler().println("<b>AVAILABLE TEAMS:</b>")
        for team in sorted(rental_teams.keys()):
            names = []
            for teammate in rental_teams[team]:
                names.append(teammate.name)
            SimpleIOHandler().println(str(team) + ":", ", ".join(names))
        SimpleIOHandler().println("c: Custom team")
        SimpleIOHandler().println("q: Quit")
        team1 = False
        if len(sys.argv) > 1:
            if not os.path.isdir(sys.argv[1]):
                team1 = sys.argv[1]
        while not team1 in rental_teams.keys() and not os.path.exists(str(team1)) and not os.path.isdir(str(team1)):
            team1 = SimpleIOHandler().input("Enter the name of your selection here (Team 1): ")
            if team1.lower() == "q" or team1.lower() == "quit":
                sys.exit()
            elif team1.lower() == "c":
                while not os.path.exists(team1) and not os.path.isdir(str(team1)) and not team1.lower() == "r":
                    team1 = SimpleIOHandler().input("Enter a valid pathname here (r: return): ")
                if not team1.lower() == "r":
                    break
        if os.path.exists(team1) and not os.path.isdir(team1):
            if team1.endswith(".rbst"):
                file_ = open(team1, "rb")
                team1 = pickle.load(file_)
            else:
                file_ = open(team1, "r")
                team1 = team_from_rbs2(json.load(file_))
            file_.close()
        else:
            team1 = copy.deepcopy(rental_teams[team1])
        team2 = False
        if len(sys.argv) > 2:
            if not os.path.isdir(sys.argv[2]):
                team2 = sys.argv[2]
        while not team2 in rental_teams.keys() and not os.path.exists(str(team2)) and not os.path.isdir(str(team2)):
            team2 = SimpleIOHandler().input("Enter the name of your selection here (Team 2): ")
            if team2.lower() == "q" or team2.lower() == "quit":
                sys.exit()
            elif team2.lower() == "c":
                while not os.path.exists(team2) and not os.path.isdir(str(team2)) and not team2.lower() == "r":
                    team2 = SimpleIOHandler().input("Enter a valid pathname here (r: return): ")
                if not team2.lower() == "r":
                    break
        if os.path.exists(team2) and not os.path.isdir(team2):
            if team2.endswith(".rbst"):
                file_ = open(team2, "rb")
                team2 = pickle.load(file_)
            else:
                file_ = open(team2, "r")
                team2 = team_from_rbs2(json.load(file_))
        else:
            team2 = copy.deepcopy(rental_teams[team2])
        for character in team1:
            if not character.is_approved():
                SimpleIOHandler().input("<b>WARNING:</b> At least one of the characters in Team 1 has not been approved for normal play.")
                break
        for character in team2:
            if not character.is_approved():
                SimpleIOHandler().input("<b>WARNING:</b> At least one of the characters in Team 2 has not been approved for normal play.")
                break
        versus = False
        while not versus == "y" and not versus == "n":
            versus = SimpleIOHandler().input("Is this a 2-player match? (y/n): ")
        if versus == "n":
            difficulty = False
            while 1:
                SimpleIOHandler().println()
                SimpleIOHandler().println("<b>AVAILABLE AIS:</b>")
                for a in all_ais.list_ais():
                    SimpleIOHandler().println(a)
                difficulty = SimpleIOHandler().input("Enter your selection here:")
                try: exec("import ai." + difficulty)
                except: pass
                else: break
        else:
            difficulty = 0
        if not "-a" in sys.argv:
            mode = "priority"
        else:
            SimpleIOHandler().println()
            SimpleIOHandler().println("<b>AVAILABLE MODES:</b>")
            for m in modes:
                SimpleIOHandler().println(m)
            mode = False
            while not mode in modes:
                mode = SimpleIOHandler().input("Enter a mode here: ")
        SimpleIOHandler().println()
        SimpleIOHandler().println("<b>AVAILABLE WEATHER:</b>")
        for w in matchups.get_all_weather().keys():
            SimpleIOHandler().println(w)
        weather = False
        while not weather in matchups.get_all_weather():
            weather = SimpleIOHandler().input("Enter a weather here: ")
        SimpleIOHandler().println()
        SimpleIOHandler().println("<b>AVAILABLE TERRAIN:</b>")
        for t in matchups.get_all_terrain().keys():
            SimpleIOHandler().println(t)
        terrain = False
        while not terrain in matchups.get_all_terrain():
            terrain = SimpleIOHandler().input("Enter a terrain here: ")
        try:
            SimpleIOHandler().println()
            battle = Battle(team1, team2, True if versus == "y" else False, difficulty, mode, weather=weather, terrain=terrain, io_handler=DialogIOHandler())
            battle.start()
        except:
            logging.exception("Something awful happened!")
        logging.debug("Finishing battle...")
        SimpleIOHandler().println("")
def main():
    rpgbs_init()
    team = {}
    carlos = Carlos()
    corina = Corina()

    def restore_health():
        for member in team.values():
            member.recalculate_stats()
            member.health = member.stats["HP"]
            member.mana = member.stats["MP"]

    fancy_input("<b>THE CHRONICLES OF RPG-BATTLE-SYSTEM</b>\n" + "An extremely basic RPG coded by <b>Daniel Sim</b>")
    fancy_println()
    fancy_input("<b>TOWN:</b> Irydia")
    fancy_input("(Carlos is lying under a tree, relaxing)")
    carlos.says("Man, I'm so bored...")
    corina.says("Hi, Carlos!")
    carlos.says("Hey, Corina. Listen, I'm really bored right now. " + "Got any ideas for what we should do?")
    corina.says("Let's trick Charles into doing something " + "stupid again!")
    carlos.says("Nah, that's too easy.")
    corina.says("Um... we could walk around town together?")
    carlos.says("Too mundane.")
    corina.says("Oh, I know! Why don't we go on some crazy " + "adventure like they do in role-playing games?")
    carlos.says("Yes! That's it! I can't believe I " + "didn't think of that before! Let's go!")
    team["Carlos"] = carlos
    team["Corina"] = corina
    fancy_input(
        "(And with that, our heroes head off on a random, "
        + "pointless adventure.\n It is not long before they "
        + "encounter their first obstacle...)"
    )
    carlos.says("Dammit! This stupid rock is in our way! " + "Now how are we going to get through?")
    corina.says("This looks like a good time to " + "practice fighting enemies!")
    no = True
    while 1:
        g = fancy_input(
            '<b>Corina:</b> <magenta>"Shall I explain how ' + 'to declare an attack?"</magenta> (y/n): '
        ).lower()
        if g == "y":
            break
        elif g == "n":
            no = False
            break
    if no == True:
        corina.says(
            "To declare an attack, "
            + "all you have to do is enter in the number of the attack, "
            + "followed by the number of the target. "
            + "It's pretty self-explanatory, so let's begin!"
        )
    else:
        corina.says("Then let's begin!")
    fancy_println()
    battle = Battle(team.values(), [Rock().level_to(3)])
    battle.start()
    fancy_println()
    restore_health()
    for member in team.values():
        member.level_to(6)
        fancy_input(member.name + " grew to level 6!")
    fancy_println()
    corina.says('Yay! We won! And I gained a level, too!" ^^')
    carlos.says("That was really annoying, though... " + "Whoever knew rocks could be so tough?")
    corina.says("Anyway! Let's move on to the next town!")
    fancy_input("(And so our heroes move on to the next town...)")
    fancy_println()
    fancy_input("<b>TOWN:</b> Lindenshire")
    carlos.says("Well, that was fast...")
    corina.says('(pointing) "Carlos! ' + "It looks like a fight's going on over there!")
    carlos.says('(turns to look) "Huh?')
    fancy_input("(Sure enough, two people are facing off.)")
    mook = Mook().rename("Guy With A Gun")
    mook.says("Hand over your goodies!")
    blade = Blade().rename("Guy With A Big Sword").level_to(9001).remove_attack("Kamikaze").remove_attack("Regenerate")
    blade.says("Sorry, don't feel like it.")
    mook.says("Then I challenge you to a fight!")
    carlos.says("What's with this ridiculous scene...?")
    fancy_println()
    fancy_input("(Perspective of Guy With A Gun)")
    fancy_println()
    battle = Battle([mook], [blade])
    battle.start()
    fancy_println()
    fancy_input("(Guy With A Gun slumps to the ground, unconscious.)")
    blade.says("<sigh>")
    carlos.says("Whoa. That was totally insane.")
    corina.says("Talk about a curb-stomp battle!")
    fancy_input("(Guy With A Big Sword walks over to Carlos and Corina.)")
    corina.says("Ack! He's coming this way!")
    blade.says(
        "The two of you... look like you have potential. " + "My name is Blade; I have the feeling we'll meet again..."
    )
    fancy_input("(With that, Blade walks off again.)")
    carlos.says("Well, that was... interesting.")
    corina.says("Anyway! We should rest here for the night!")
    carlos.says("Good idea. Let's do that.")
    fancy_input("(Our heroes find an inn.)")
    fancy_input('<b>Innkeeper:</b> "Welcome. How may I help you?"')
    corina.says("Cheapest room for two, please!")
    fancy_input(
        "<b>Innkeeper:</b> (hands her a pair of keys) \"Room J1702. It's "
        + 'on the 17th floor; the elevators are over there."'
    )
    corina.says("Thank you!")
    fancy_input(
        "(Carlos and Corina head up to the 17th floor. As they head "
        + "out of the elevator, Carlos walks straight into a maid.)"
    )
    carlos.says("Ow!")
    shelly = Shelly().level_to(6).rename("Maid")
    shelly.says("Uwaah! I'm sorry!")
    carlos.says("Nah, it's not a big deal. See ya later!")
    fancy_input("(Carlos and Corina head to their room)")
    if not rpy:
        corina.says("Sorry, that's as far as the story gets for now!")
        fancy_input("<b>THE END</b>")