lundi 17 août 2020

Text adventure game in Python - Creating a random selection of items from a text file with weighted properties

I'm currently creating an inventory system for a text adventure game in Python. I have a list of items in a text file with the rarity of them item after a comma.
e.g.
potion, 1
sword, 2
legendary armour, 7

I have tried a few variants of importing the file and random selection but I can't seem to find a solution by myself.
The basic operation is...

Player completes level (levels go from 1-30).
At the end of the level the game picks 3 random items from the text file.
The player chooses one of the items.

The items need to be weighted based on their rarity vs the current player level, so the higher the player level, the higher chance of a rarer item being offered.
--------------------------
So far I have tried importing the items and weights into different lists, but comparing these to the level is complicated. I have also considered making seperate text files based on each level and having duplicates of each item to measure the weightings but this would make thousands of lines just for the items.
There must be a way I am not considering.




Aucun commentaire:

Enregistrer un commentaire