コード例 #1
0
ファイル: game.py プロジェクト: Aesthemic/text-rpg
def game_help(a):
    common.clear_screen()
    print("Help Menu")
    print("Which topic would you like help with?")
    print("1. How to Play")
    print("2. Menus")
    print("3. Attributes")
    print("4. Combat")
    print("5. Bug Report")
    print("Press return to return to previous menu.")
    selection = input("> ")
    if selection == "1":
        game_help_general(a)
    elif selection == "2":
        game_help_menues(a)
    elif selection == "3":
        game_help_attributes(a)
    elif selection == "4":
        game_help_combat(a)
    elif selection == "5":
        game_help_bug(a)
    else:
        if a == "game":
            game_menu()
        elif a == "combat":
            combat_menu()
        elif a == "start":
            main_menu()
        else:
            main_menu()
コード例 #2
0
ファイル: game.py プロジェクト: Aesthemic/text-rpg
def game_help_attributes(a):
    common.clear_screen()
    print(
        "Health: This is how much damage you can take before your character dies."
    )
    print(
        "Magic: This is how much magic you can use. Spells in the game take magic to cast."
    )
    print(
        "Strength: This influences how much damage you deal with physical attacks. The higher the strength, the more damage you deal."
    )
    print(
        "Dexterity: This determines your chance to hit an enemy. The higher the dexterity, the better the chance to hit."
    )
    print(
        "Endurance: This determines how much physical damage you can absorb. The higher the endurance, the less damage you take from physical attacks."
    )
    print(
        "Agility: This determines your chance to dodge an incoming attack. The higher the agility, the better the chance that a physical attack will miss you."
    )
    print(
        "Intelligence: This determines how powerful your attack spells are. The higher the intelligence, the more potent your attack spells are."
    )
    print(
        "Spirit: This determines how much magic you receive when you level up. Increase this to improve your health."
    )
    print(
        "Vitality: This determines how much health you receive when you level up. Increase this to improve your magic."
    )
    print(
        "Luck: This determines your chance for lucky things to happen. Don't think too much about it. :)"
    )
    print("Press return to continue.")
    input("?")
    game_help(a)
コード例 #3
0
ファイル: game.py プロジェクト: Aesthemic/text-rpg
def main_menu():
    common.clear_screen()
    print(" _____         _    ____________ _____ ")
    print("|_   _|       | |   | ___ \\ ___ \\  __ \\")
    print("  | | _____  _| |_  | |_/ / |_/ / |  \\/")
    print("  | |/ _ \\ \\/ / __| |    /|  __/| | __ ")
    print("  | |  __/>  <| |_  | |\\ \\| |   | |_\\ \\")
    print("  \\_/\\___/_/\\_\\\\__| \\_| \\_\\_|    \\____/\n\n")
    print("1. New Game")
    print("2. Load Game")
    print("3. Credits")
    print("4. Help")
    print("5. Exit Game")
    selection = input("> ")
    # As it turns out, Python lacks a switch-case system. Odd. If / elif / else it is then.
    if selection == "1":
        start_game()
    elif selection == "2":
        load_game()
    elif selection == "3":
        credits()
    elif selection == "4":
        game_help("start")
    elif selection == "5":
        common.clear_screen()
        sys.exit(0)
    elif selection == "318":
        secret_menu()
    else:
        print("Incorrect selection. Please choose one of the options.")
        print("Press any key to continue.")
        input("?")
        main_menu()
コード例 #4
0
ファイル: game.py プロジェクト: Aesthemic/text-rpg
def game_help_combat(a):
    common.clear_screen()
    print(
        "This menu is under construction since the combat system is under construction."
    )
    print("Press return to continue.")
    input("?")
    game_help(a)
コード例 #5
0
ファイル: game.py プロジェクト: Aesthemic/text-rpg
def secret_menu():
    common.clear_screen()
    print(
        "Welcome to the secret menu! This doesn't do anything right now, but feel free to make yourself at home."
    )
    print("Press return to go back to the main menu.")
    input("?")
    main_menu()
コード例 #6
0
ファイル: game.py プロジェクト: Aesthemic/text-rpg
def game_help_bug(a):
    common.clear_screen()
    print(
        "If you've run into a bug, please send an email to [email protected]."
    )
    print("Thank you for helping with testing the game.")
    print("Press return to continue.")
    input("?")
    game_help(a)
コード例 #7
0
ファイル: game.py プロジェクト: Aesthemic/text-rpg
def game_help_general(a):
    common.clear_screen()
    print(
        "The main objective of the game is to explore the world and defeat the four major bosses."
    )
    print(
        "Over the course of the game you'll recruit new characters to help you, find new gear, and complete quests to unlock new abilities."
    )
    print("Press return to continue.")
    input("?")
    game_help(a)
コード例 #8
0
ファイル: game.py プロジェクト: Aesthemic/text-rpg
def credits():
    common.clear_screen()
    print("This game engine was developed by Aesthemic.")
    print("Github: https://github.com/Aesthemic/text-rpg")
    print("Twitter: https://www.twitter.com/aesthemic")
    print("Discord: Aesthemic#0573")
    print("IRC: Aesthemic in #lounge on irc.digibase.ca")
    print("Email: [email protected]")
    print("Press any key to continue.")
    input("?")
    main_menu()
コード例 #9
0
def display_team_stat(team_name):
    common.clear_screen()
    common.print_title("Displaying Team Statistics for: {}".format(team_name))
    print("Number of Players: {}".format(get_player_count(team_name)))
    print("\nPlayers: {}".format(get_player_names(team_name)))
    print("\nNumber of Newbies: {}".format(
        get_other_counts(team_name, "experience", False)))
    print("\nNumber of Pros: {}".format(
        get_other_counts(team_name, "experience", True)))
    print("\nAverage Height: {}".format(get_avg_height(team_name)))
    print("\nGuardians: {}".format(get_guardians(team_name)))
コード例 #10
0
ファイル: game.py プロジェクト: Aesthemic/text-rpg
def save_game():
    common.clear_screen()
    print(character_data["character_name"])
    character_name = character_data["character_name"]
    savename = "save/" + character_name + ".json"
    with open(savename, 'w') as f:
        json.dump(character_data, f)
        f.close()
    print("You successfully saved the game.")
    print("Press return to continue.")
    input("?")
    game_menu()
コード例 #11
0
ファイル: game.py プロジェクト: Aesthemic/text-rpg
def explore():
    common.clear_screen()
    curr_loc_id = character_data["travel"]
    if location_data[curr_loc_id]["explore"] == 0:
        print(
            "You explore the area, yet find nothing. It seems there isn't much to see here. Try traveling somewhere else."
        )
        print("Press return to continue.")
        input("?")
        game_menu()
    else:
        print("This part of the game is currently under construction.")
        print("Press return to continue.")
        input("?")
        game_menu()
コード例 #12
0
ファイル: game.py プロジェクト: Aesthemic/text-rpg
def go_shop(id):
    common.clear_screen()
    with open("data/shops.json", 'r') as f:
        shops_data = json.load(f)
        f.close()
    print(shops_data[id]["text-name"])
    print(shops_data[id]["text"])
    print("What would you like to do?")
    print("1. Buy Item")
    print("2. Sell Item")
    print("3. Return to Town")
    selection = input("> ")
    if selection == "1":
        buy_item(id)
    elif selection == "2":
        sell_item(id)
    elif selection == "3":
        game_menu()
コード例 #13
0
ファイル: game.py プロジェクト: Aesthemic/text-rpg
def buy_item(id):
    common.clear_screen()
    with open("data/shops.json", 'r') as f:
        shops_data = json.load(f)
        f.close()
    with open("data/items.json", 'r') as f:
        items_data = json.load(f)
        f.close()
    print("Which item would you like to buy?")
    item_list = shops_data[id]["inventory"]
    item_number = 1
    for key in item_list:
        print(
            str(item_number) + ". " + items_data[key]["text-name"] + ": " +
            str(shops_data[id]["inventory"][key]))
    selection = input("> ")
    # Will continue working on this later to see if the player has the gold to buy the item or not and whether they selected a valid item to purchase.
    game_menu()
コード例 #14
0
ファイル: client.py プロジェクト: ktht/battleship
def authenticate():
    ''' After player has joined a server, asks for player credentials

    Checks the database for other players with the same username and if entered password is correct.
    When client connects for the first, his entered credentials will be saved to a database.

    :return: username, player id
    '''
    boolean = False
    print('Connected to {game_server_name}'.format(
        game_server_name=GAME_SERVER_NAME))
    while not boolean:
        try:
            u_name = raw_input("Enter your username: "******"Enter your password: "******"Enter your password: "******"Bye bye")
            sys.exit(1)
        player_id = int(
            rpc_client.call_mum(common.CTRL_REQ_ID, u_name, pwd)[0])
        if player_id == common.CTRL_ERR_DB:
            print(
                'This username is taken or you entered a wrong password, please try again.'
            )
        elif player_id == common.CTRL_ERR_MAX_PL:
            print('Sorry, maximum number of players has been exceeded.')
        elif player_id == common.CTRL_ERR_LOGGED_IN:
            print('Sorry but this user is already logged in.')
        else:
            boolean = True
            common.clear_screen()

    global client_id
    client_id = player_id

    keepalive_thread = threading.Thread(target=send_keepalive,
                                        name='Client_keepalive')
    keepalive_thread.setDaemon(True)
    keepalive_thread.start()

    return u_name, player_id
コード例 #15
0
ファイル: game.py プロジェクト: Aesthemic/text-rpg
def game_menu():
    common.clear_screen()
    print("Game Menu")
    with open("data/locations.json", 'r') as f:
        location_data = json.load(f)
        f.close()
    curr_loc_id = character_data["travel"]
    curr_loc_nm = location_data[curr_loc_id]["text-name"]
    print("You're currently in " + str(curr_loc_nm) + ".")
    print("Select an Option")
    print("1. Travel")
    print("2. Explore")
    print("3. Shopping")
    print("4. Stats")
    print("5. Inventory")
    print("6. Help")
    print("7. Save Game")
    print("8. Exit Game")
    selection = input("> ")
    if selection == "1":
        travel_menu()
    elif selection == "2":
        explore()
    elif selection == "3":
        shop_menu()
    elif selection == "4":
        view_stats("player", character_data["character_name"])
    elif selection == "5":
        print("This game is still under construction.")
        print("Press any key to continue.")
        selection = input("> ")
        game_menu()
    elif selection == "6":
        game_help("game")
    elif selection == "7":
        save_game()
    elif selection == "8":
        main_menu()
    else:
        print("Incorrect selection. Please choose from one of the options.")
        print("Press any key to continue.")
        selection = input("> ")
        game_menu()
コード例 #16
0
ファイル: game.py プロジェクト: Aesthemic/text-rpg
def view_stats(a, b):
    if a == "player":
        common.clear_screen()
        character_filename = "save/" + b + ".json"
        with open(character_filename, 'r') as f:
            character_data = json.load(f)
            f.close()
        print("Character stats for: " + character_data["character_name"])
        print("Basic Information:")
        print("Level: " + str(get.level("player", b)))
        print("Health: " + str(get.health("player", b)) + " \\ " +
              str(get.atr("player", b, "health")))
        print("Magic: " + str(get.magic("player", b)) + " \\ " +
              str(get.atr("player", b, "magic")))
        print("Experience: " + str(get.exp(a, b)) + " \\ " +
              str(get.toexp(a, b)))
        print("Strength: " + str(get.atr("player", b, "strength")))
        print("Dexterity: " + str(get.atr("player", b, "dexterity")))
        print("Endurance: " + str(get.atr("player", b, "endurance")))
        print("Agility: " + str(get.atr("player", b, "agility")))
        print("Intelligence: " + str(get.atr("player", b, "intelligence")))
        print("Spirit: " + str(get.atr("player", b, "spirit")))
        print("Vitality: " + str(get.atr("player", b, "vitality")))
        print("Luck: " + str(get.atr("player", b, "luck")))
        print("Press enter to continue.")
        input("?")
        game_menu()
    else:
        common.clear_screen()
        npc_filename = "save/" + b + ".json"
        with open(npc_filename, 'r') as f:
            npc_data = json.load(f)
            f.close()
        print("Character stats for: " + npc_data["character_name"])
        print("Basic Information:")
        print("Experience: " + str(get.exp(a, b)) + " \\ " +
              str(get.toexp(a, b)))
        print("Press enter to continue.")
        input("?")
        game_menu()
コード例 #17
0
ファイル: game.py プロジェクト: Aesthemic/text-rpg
def travel_menu():
    common.clear_screen()
    curr_loc_id = character_data["travel"]
    curr_loc_nm = location_data[curr_loc_id]["text-name"]
    travel_to = location_data[curr_loc_id]["travel"]
    print("You're currently in " + curr_loc_nm + ".")
    print("Where would you like to go?")
    for key in travel_to:
        print(location_data[key]["text-name"] + " - Level: " +
              str(location_data[key]["area-level"]))
    print("Type the name of the area you would like to go.")
    print("If you change your mind, simply type nothing and hit return.")
    selection = input("> ")
    selection = selection.lower()
    selection = selection.replace(" ", "-")
    if selection in location_data[curr_loc_id]["travel"]:
        character_data["travel"] = selection
        common.clear_screen()
        print("You have successfully traveled to " +
              location_data[selection]["text-name"] + ".")
        print("Press return to continue.")
        input("?")
        game_menu()
    else:
        common.clear_screen()
        print("Invalid selection.")
        print("Press return to continue.")
        input("?")
        game_menu()
コード例 #18
0
ファイル: client.py プロジェクト: ktht/battleship
def choose_server():
    ''' After available server list has been created, asks player which server to join
    Also checks if player entered server name correctly.
    '''
    global available_servers, GAME_SERVER_NAME
    boolean = True
    while boolean:
        try:
            server_name = raw_input(
                'Enter the name of the server you want to connect to: ')
        except KeyboardInterrupt:
            print("Bye bye")
            sys.exit(1)
        if server_name in available_servers:
            boolean = False
            del available_servers[:]
            break
        else:
            print("Incorrect server name")

    GAME_SERVER_NAME = server_name
    common.clear_screen()
コード例 #19
0
ファイル: game.py プロジェクト: Aesthemic/text-rpg
def load_game():
    common.clear_screen()
    print("Please type the name of the save file you would like to load.")
    print("Save files:")
    global character_data
    for files in os.walk('save'):
        for filename in files:
            if ".json" in str(filename):
                print(str(filename)[2:-7])
    character_name = input("> ")
    character_filename = "save/" + character_name + ".json"
    with open(character_filename, 'r') as f:
        character_data = json.load(f)
        f.close()
    if character_data is None:
        print("Invalid character name. Please choose one from the list.")
        print("Press return to continue.")
        input("?")
        load_game()
    print("Save loaded.")
    print("Press return to continue.")
    input("?")
    game_menu()
コード例 #20
0
ファイル: client.py プロジェクト: ktht/battleship
def public_announc_callback(ch, method, properties, body):
    ''' Callback for server announcements, creates a list of available servers
    :param ch:
    :param method:
    :param properties:
    :param body: Server announcement message
    '''
    t_set.add(body)

    global start_t
    global server_list_timeout
    global initialization_phase
    global available_servers

    if time.time() - start_t > server_list_timeout:
        start_t = time.time()
        if initialization_phase:
            common.clear_screen()
            print('Available servers and number of clients connected:')
        for t in t_set:
            if initialization_phase:
                print("{server_name}: {nof_clients} client(s)".format(
                    server_name=t[0], nof_clients=t[1]))
            available_servers.append(t[0])
        if initialization_phase:
            if common.query_yes_no("Would you like to update the list?",
                                   default="no"):
                print('Updating...')
                return
            elif len(available_servers) > 0:
                initialization_phase = False
                cv_init.acquire()
                cv_init.notify_all()
                cv_init.release()

                # we must close the connection, see https://github.com/pika/pika/issues/698
                server_list_con.close()
コード例 #21
0
def start_app():
    logging.info("{}: Application Started".format(datetime.today()))
    common.clear_screen()
    while True:
        common.print_title("Welcome to {}".format(APP_NAME))
        option_selected = common.display_menu(
            """Please select from available menu options e.g. 1:

1) Display Team Statistics
2) Quit
""")
        try:
            option_selected = int(option_selected)
            if option_selected == 1:
                common.clear_screen()
                sub_menu = True
                while sub_menu:
                    display_team_list(teams)
                    option_selected = common.display_menu("")
                    try:
                        option_selected = int(option_selected)
                        if option_selected < 0 or option_selected > len(teams):
                            raise ValueError
                        elif option_selected == 0:
                            common.clear_screen()
                            sub_menu = False
                        else:
                            team = teams[option_selected - 1]
                            display_team_stat(team)
                            input("\nPress ENTER to continue ... ")
                            common.clear_screen()
                    except ValueError:
                        common.invalid_entry(option_selected)
                        continue
            elif option_selected == 2:
                print()
                common.print_title("Thank you for using {}!".format(APP_NAME))
                logging.info("{}: Application Closed".format(datetime.today()))
                break
            else:
                raise ValueError
        except ValueError:
            common.invalid_entry(option_selected)
            continue
コード例 #22
0
ファイル: game.py プロジェクト: Aesthemic/text-rpg
def shop_menu():
    common.clear_screen()
    curr_loc_id = character_data["travel"]
    with open("data/shops.json", 'r') as f:
        shops_data = json.load(f)
        f.close()
    with open("data/locations.json", 'r') as f:
        location_data = json.load(f)
        f.close()
    if not location_data[curr_loc_id]["shops"]:
        print("There are no shops here to find.")
        print("Try visiting a town or village.")
        print("Press return to continue.")
        input("?")
        game_menu()
    else:
        print("Please choose from the following shops by number.")
        shop_number = 1
        for shops in location_data[curr_loc_id]["shops"]:
            print(str(shop_number) + ". " + shops_data[shops]["text-name"])
            shop_number = shop_number + 1
        selection = input("> ")
        if selection.isdigit() == False:
            common.clear_screen()
            print("Your selection should be a number.")
            print("Example: 1")
            print("Press return to continue.")
            input("?")
            shop_menu()
        selection = int(selection)
        all_shops = location_data[curr_loc_id]["shops"]
        shop_names = all_shops.keys()
        shop_number = len(all_shops.keys())
        if selection < 1:
            print("You've selected an invalid shop.")
            print("Press return to continue.")
            input("?")
            shop_menu()
        elif selection <= shop_number:
            selection = selection - 1
            selection = list(shop_names)[selection]
            go_shop(selection)
        else:
            common.clear_screen()
            print("You've selected an invalid shop.")
            print("Press return to continue.")
            input("?")
            shop_menu()
コード例 #23
0
ファイル: client.py プロジェクト: ktht/battleship
def server_bcasts_callback(ch, method, properties, body):
    ''' Callback after receiving updates/commands from the game server. If needed, responds to the server
    by making a rpc call.

    :param ch:
    :param method:
    :param properties:
    :param body: Message received from the server
    '''
    msg = common.unmarshal(body)
    CTRL_CODE = int(msg[0])
    if CTRL_CODE == common.CTRL_BRDCAST_MSG:
        print(msg[1])
    elif CTRL_CODE == common.CTRL_START_GAME:
        board = rpc_client.call_mum(common.CTRL_REQ_BOARD)
        global player_ships_board, player_hits_board
        player_ships_board = process_board(board[0], int(board[1]),
                                           int(board[2]))
        player_hits_board = np.full((int(board[1]), int(board[2])),
                                    '-',
                                    dtype=str)
        common.print_board(player_ships_board, player_hits_board)
    elif CTRL_CODE == common.CTRL_SIGNAL_PL_TURN:  # After server signals this players turn, he gets
        if int(
                msg[1]
        ) == player_id:  # a prompt asking for coordinates to bomb, with a 25 sec timeout
            x, y = get_coords()
            # In case of timeout not worth doing RPC
            if x != common.CTRL_HIT_TIMEOUT and y != common.CTRL_HIT_TIMEOUT:
                hit = int(
                    rpc_client.call_mum(common.CTRL_HIT_SHIP, player_id, x,
                                        y)[0])
                if int(hit) == common.CTRL_ERR_HIT:
                    print('Entered coordinates were invalid.')
                else:
                    if int(hit) == 0:
                        player_hits_board[x][y] = 'O'
                    else:
                        player_hits_board[x][y] = 'X'
            common.clear_screen()
            common.print_board(player_ships_board, player_hits_board)
    elif CTRL_CODE == common.CTRL_NOTIFY_HIT:
        if int(msg[1]) == player_id:  # If this player got hit
            player_ships_board[int(msg[2])][int(msg[3])] = '*'
            common.clear_screen()
            common.print_board(player_ships_board, player_hits_board)
            print('Oh noes, you\'ve been hit by {bomber}!'.format(
                bomber=str(msg[4])))
    elif CTRL_CODE == common.CTRL_SHIP_SUNKEN:
        if int(msg[3]) != player_id:  # If this clients ship did not sink
            player_hits_board[int(msg[1])][int(msg[2])] = 'S'
            common.clear_screen()
            common.print_board(player_ships_board, player_hits_board)
    elif CTRL_CODE == common.CTRL_GAME_FINISHED:
        common.clear_screen()
        common.print_board(player_ships_board, player_hits_board)
        if player_id == int(msg[1]):  # If players id matches the winners id
            print('Good job, you have won!')
        else:
            print('You have lost, sorry. Winner is {winner}!').format(
                winner=msg[2])
コード例 #24
0
ファイル: game.py プロジェクト: Aesthemic/text-rpg
def sell_item(id):
    common.clear_screen()
    with open("data/items.json", 'r') as f:
        items_data = json.load(f)
        f.close()
    game_menu()
コード例 #25
0
ファイル: game.py プロジェクト: Aesthemic/text-rpg
def start_game():
    common.clear_screen()
    print("Welcome to this strange world.")
    print("May I ask your name?")
    character_name = input("> ")
    print(f"Hello, {character_name}, it is a pleasure to meet you.")
    character_filename = "save/" + character_name + ".json"
    character_file = Path(character_filename)
    if len(character_name) > 20:
        common.clear_screen()
        print(
            "Your name needs to be less than 20 characters. Please choose another name."
        )
        print("Press any key to continue.")
        input("?")
        start_game()
    elif character_file.is_file():
        common.clear_screen()
        print(
            "There is already a character with that name. You'll have to choose another one."
        )
        print("Press enter to continue.")
        input("?")
        start_game()
    else:
        global character_data
        character_data = {
            "character_name": character_name,
            "level": 1,
            "current_health": 100,
            "current_magic": 100,
            "attributes": {
                "health": 100,
                "magic": 100,
                "strength": 10,
                "dexterity": 10,
                "endurance": 10,
                "agility": 10,
                "intelligence": 10,
                "spirit": 10,
                "vitality": 10,
                "luck": 0
            },
            "temp_attributes": {
                "health": 0,
                "magic": 0,
                "strength": 0,
                "dexterity": 0,
                "endurance": 0,
                "agility": 0,
                "intelligence": 0,
                "spirit": 0,
                "vitality": 0,
                "luck": 0
            },
            "item_attributes": {
                "health": 0,
                "magic": 0,
                "strength": 0,
                "dexterity": 0,
                "endurance": 0,
                "agility": 0,
                "intelligence": 0,
                "spirit": 0,
                "vitality": 0,
                "luck": 0
            },
            "progress": {
                "experience": 0,
                "experience_to_level": 100
            },
            "currencies": {
                "gold": 0,
                "honor": 0
            },
            "items": {},
            "bank": {},
            "quests": {},
            "travel": "starting-village"
        }
        character_filename = "save/" + character_name + ".json"
        with open(character_filename, 'x') as f:
            json.dump(character_data, f)
        game_menu()
コード例 #26
0
ファイル: game.py プロジェクト: Aesthemic/text-rpg
def game_help_menus(a):
    common.clear_screen()
    print("This help menu is coming soon.")
    print("Press return to continue.")
    input("?")
    game_help(a)