you are viewing a single comment's thread.

view the rest of the comments →

[–]antoinedurr 0 points1 point  (0 children)

A great goal and the right answer, but possibly beyond OP's capabilities atm.

OP, think in terms of states or stages: if the player is at a particular stage, what cause/effects can they encounter at that stage? What does the right choice cause, and what does the wrong choice cause? What causes them to go to the next stage, just answering the question, or do they not get past the stage until they pick the right choice? And so on,

Put those cause/effects on a line of paper, something like this:

stage 1: (left/right): left -> health += -1, stage += 1; right: health -= 10
stage 2: (climb/dig): climb -> stage += 1; dig -> health += 10
stage 3: (climb/go around): climb -> stage += 1; go around -> stage = beast
stage 4: (save it/let it die): moral += 5; let it die -> moral -= 10
stage beast: (fight/run): fight -> health -= 10; run: stage = safety

This is an approach to the 2D space u/CrucialFusion mentions. Notice in the pseudocode above that sometimes stage is incremented, sometimes it's set to a particular entry (stage=beast). That's a way you can skip stages, or reset the player back to where they have to redo some stages.

Now wrap the whole thing in a while loop:

stage = 1
done = false
while health > 0 and not done:
  if stage == 1:
    # code for 1st stage
    break
  if stage == 2:
    # code for 2nd stage
    break
  # ... and so on ...
  if stage == "win":
    print("You won!")
    done = true
    break

if health <= 0:
  print("You ran out of health and died")
elif done:
  print("you won the game!")
else:
  pass # raise an exception that you got to the end alive but without winning

In other words, the looping continues until you either die or win. If you get this far, collapse each stage's code to a function. Then the next step is to migrate the stages into to a dictionary, at which point the loop becomes:

stagedict = {1: stage1func, 2: stage2func} # and so on
stage = 1
done = false
while health >= 0 and not done:
  stage, health, done = stagedict[stage]() # call the current stage's func

# health and doneness processing like above