Hi,
Sorry - I’m green as grass, and have fallen at the first hurdle. I’m on the portfolio project stage of the Computer Science pathway, and have decided to make a text-based RPG set in a supermarket.
Essentially, the functionality I’m trying to create is to give the player a choice of startup ‘pathways’ (trying not to use the word ‘classes’ in a gamer sense!) that gives them different beginning characteristics.
Based on their input choice, this index value is used to read from a nested list of attributes, and then a createPlayer method is called with these charactersitics.
This is what I have so far:
# Supermarket: the RPG
# start-up message
start_up_message = "###########################################\n\nWelcome to Supermarket: the RPG \n \n Choose a player class\n1: Mum with kids\n2: Sharp-elbowed Granny"
player_choice_of_class = 0
# Player class, influenced by which type of shopper they initially choose
startup_stats = [["Mum with kids", 0.8, 120, 120, 70, 70, 100], ["Sharp-elbowed Granny", 1.1, 70, 70, 100, 100, 80]]
class Player:
def __init__(self, player_class, time_factor, stamina, max_stamina, patience, max_patience, money):
self.player_class = player_class
self.time_factor = time_factor
self.stamina = stamina
self.max_stamina = max_stamina
self.patience = patience
self.max_patience = max_patience
self.money = money
def __repr__(self, player_class, time_factor, stamina, max_stamina, patience, max_patience, money):
pass
def create_player(player_choice_of_class):
index_choice = int(player_choice_of_class) - 1
init_player_class = startup_stats[index_choice][0]
init_time_factor = startup_stats[index_choice][1]
init_stamina = startup_stats[index_choice][2]
init_max_stamina = startup_stats[index_choice][3]
init_patience = startup_stats[index_choice][4]
init_max_patience = startup_stats[index_choice][5]
init_money = startup_stats[index_choice][6]
# Create player as "new_player" with start-up data as drawn from startup stats list
new_player = Player(init_player_class, init_time_factor, init_stamina, init_max_stamina, init_patience, init_max_patience, init_money)
return new_player
# block of code to call that shows character's current stats as a running item
def display_stats():
stats = "Time Factor: " + str(self.time_factor) + "\n" + "Stamina: " + str(self.stamina) + "/" + str(self.max_stamina) + "\n" + "Patience: " + str(self.patience) + "/" + str(self.max_patience) + "\n" + "Money: £" + str(self.money)
return stats
# ################################# GAME LOOP ########################
# Ask player which player_class they want to play with
player_choice_of_class = input(start_up_message)
#print(player_choice_of_class)
create_player(player_choice_of_class)
#test_player = Player("Mum with kids", 0.8, 120, 120, 70, 70, 100)
print(display_stats())
This throws an error - fundamentally, I’m struggling to refer to the ‘new_player’ object I’ve just created in order to display their stats (or do anything else with them going forwards.
Any help gratefully received!