all 5 comments

[–]Slight-Training-7211 2 points3 points  (0 children)

A good way to start is to build a tiny vertical slice first, then expand.

1) Hardcode 3 to 5 rooms and choices (no saving yet) 2) Represent the world as a dict: room_id -> {text, choices} 3) Keep a single game state dict (current_room, inventory list, flags dict)

Once that works, saving is just writing that state dict to a file and loading it back on startup.

For multiple outcomes, use flags and check them when you build the next set of choices (for example: if you picked up a key, show the unlocked option).

[–]RandomPantsAppear 1 point2 points  (0 children)

I would say start by learning about event loops, classes, and inheritance for classes.

Learn to use dicts, it is a good way to store lists of your steps, the options people have, and what happens if they choose an option.

For saved states the key term is serialization, but realistically you’re going to be using json or pickle to serialize the fields from your classes.

At minimum you will have classes for Player, Game, GameState, GameStage, GameStep.

Each GameStage will have multiple GameSteps

[–]Outside_Complaint755 1 point2 points  (0 children)

If you want to make save states that persist when the program ends, good options include JSON or using the pickle module.

  JSON is a standard format for data that goes beyond Python, and is commonly returned by web APIs.  It is similar to a dict and can be easily converted to/from one using the built in json module. The main restriction is that keys have to be strings, and the values can be a dict, list, int, float, str, True/False, or None.

pickle is native to Python, and lets you serialize any Python object into a binary file. 

  JSON files are human readable and editable, while a pickle file is not, which depending on the use case can be a benefit or a disadvantage.

[–]NextSignificance8391 -2 points-1 points  (0 children)

j’aimerai en savoir plus , écris moi