+ 2
Text-based game need help
I want to make a game of life with random events.. Is someone able to push me in the right direction. I successfully made a random event but now the details are missing for example the police can stop me, but now I need random details example -the police stopped me -did the police find anything -if yes what is the penalty my code https://code.sololearn.com/cXcKIqkxNKou
7 odpowiedzi
+ 7
I agree with Maxbro Channel : Basically it's the same logic.
Maybe you could use a dictionary/ dictionaries for the events. The keys are the events, the values the outcomes. Then you can randomly choose the next event and based on the outcome, sample the next event.
event = {"Police": [("Everything okay", "No license"), ("Drive on", "Get arrested")]}
Though I think, that gets easily very complex. Maybe you could have a separate (sub)dictionary for each story line...
+ 5
Hi, you have a lot of code there in the description. Please save your code in a playground script and link it here. This way your code would be easier to read and to test!
+ 2
+ 2
You could imagine this game as a series of events that happen in a sequence. For me it usually helps if I draw this, for example with boxes connected with arrows.
You could store these boxes in a dictionary, with an ID (number) as key, and the description of the event that is printed, in value.
You could implement your story book (the connection between boxes) by a single data structure, that contains other nested structures.
For example, the current "frame" or moment in the story is represented by a dict, with the event ID as key, and a list of possible other event IDs as value.
(this is building on Lisa's suggestion)
Something similar I made a while ago:
https://code.sololearn.com/c47Uq02cP4Fu/?ref=app
+ 1
I think y can use same code like in a random. It would be nice to do this through a separate function that would accept the values of the chances of getting a penalty, the chance of being stopped by the police
0
Lisa thanks for the advice
0
Maxbro Channel can you make a small example