Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Visit https://www.youtube.com/user/thegrowers420 to see the tutorials maybe even subscribe! :D
- # Sorry for the last part, I made the account when I was 15 and forgot about that. If I get 100 subs, I can change it.
- import character # Import character to access character types
- import time
- import world
- # Assign character objects to the name (a string)
- char_types = {
- "mage": character.mage,
- "thief": character.thief
- }
- def char_select():
- """
- Allows the player to choose the type of character they would like to be
- """
- #Pull in the list 'char_types'
- global char_types
- print("Please choose a character type\n")
- #Loop through the dictionary 'char_types' to list the character types and stats assigned to them
- for char in char_types:
- print(char.title()) #print the name of the character type in title case (Which capitalizes the first letter of each word in a line)
- # Just to make it look better, print a line of dashes
- print("------------------------------------------------------")
- # loop through the character type stats for printing
- for stat in char_types[char].stats.keys():
- #list the stats assigned to the character type
- print(stat, ":", char_types[char].stats[stat])
- # Seperate character types and their stats with an empty line
- print("\n")
- # Prompt the player to chose a character by entering its name
- choice = input("Please choose a character by typing its name\n")
- # Loop through char_types to check which character the player chose
- for char in char_types.keys():
- # If their choice is equal to the current key (Iteration 1 is "mage") then assign that character object to 'player'
- if choice.lower() == char:
- # Assign the character object to the variable 'player'
- player = char_types[char]
- # Allow them to give their character a name
- name = input("Please give your character a name\n")
- # Confirm that they entered their desired name correctly
- conf = input(f"You entered {name}, is this correct? y/n \n")
- # If they are satisfied with the name they entered the first time, assign the name and return the player object
- if conf.lower() == 'y':
- player.name = name
- print(f"You are now {name} the {char}")
- return player
- # If they did not enter the name correctly, use a while loop to ask until they are satisfied with their entry
- while conf.lower() == 'n':
- name = input("Please give your character a name\n")
- conf = input(f"You entered {name}, is this correct? y/n \n")
- #If they are satisfied with the name they gave, assign the name to the attribute 'name' of the character object (which is assigned to 'player' on line 40)
- if conf.lower() == 'y':
- player.name = name
- print(f"You are now {name} the {char}")
- # Return the complete player object
- return player
- # Assign the return of char_select() to the player variable
- # Note: When assigning a function call to a variable, we are actually assigning the return of the function to the variable
- player = character.mage # For faster testing, assign a character type to player
- player.name = "Something"
- # If there is no return from char_select() the player variable is set to None.
- # So we use a while loop to keep prompting them to select a character until char_select() has a return value
- while player == None:
- # Tell them that they didn't enter a listed character type or they had a typo
- print("!!!You did not enter a listed character name or had a typo, please try again!!!")
- # Give them 2 seconds to read the warning
- time.sleep(2)
- # Assign the return of char_select() to the player variable (which will call the function)
- player = char_select()
- ######################################################
- ##############New function############################
- ######################################################
- def play_game(player):
- # Load the tiles (map)
- world.load_tiles()
- #Start the player at the spawn location assigned to starting_position located in world.py
- player.location_x, player.location_y = world.starting_position
- # Get the tile at the players location
- tile = world.tile_exists(player.location_x, player.location_y)
- # Tell the player they can check commands and may also quit
- print("You may enter 'commands' at any time to see available commands; You may also enter 'q' to quit")
- # Start the game loop...Check if the player is alive and has not won yet
- while player.is_alive() and not player.victory:
- # Once again get the tile at the player location
- # Note: We do this first in the loop so if the player moves, we get the tile before anything else
- tile = world.tile_exists(player.location_x, player.location_y)
- # Attempt to modify the player (using the modify_player function assigned to the tile they're on)
- try:
- tile.modify_player(player)
- # Catch an error. There more than likely won't be one, but just in case there is, catch it
- except Exception as e:
- print("Error!" e)
- # Check if the player is still alive and has not won (This can change depending on what the tiles modify_player function does to the player)
- if player.is_alive() and not player.victory:
- # If the player is in a village, tell the 'available_actions' function to get specific actions (will be coded later)
- if tile.name == "Village":
- available_actions = tile.available_actions(in_town=True)
- # Otherwise just get the default actions(such as movement)
- else:
- available_actions = tile.available_actions()
- # Loop through the available actions and print out the keywords that will let the player use the action
- for action in available_actions:
- print(action.keyword)
- # Allow the player to enter a listed action keyword
- action_input = input("Action: ")
- # If the player entered 'q' thank them for playing and quit the game
- if action_input.lower() == 'q':
- print("Thanks for playing")
- quit()
- # Call the play_game() function to start the game
- play_game(player)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement