TripleX - Randomization of Text

Currently, my code is simply what we made in the lessons (except mine is about escaping a multi-level dungeon, upwards, towards the exit).

However, I would like to have the text parts randomized, so that it would say that occasionally the staircase to the upper level smells gross, occasionally the staircase is cold, occasionally wet, etc, you get the point. As I’m very new to C++, I have no idea as to how to go about Googling this. I have gone through various codes others have posted on here, trying to patch together a rudimentary understanding, but so far, it hasn’t clicked for me.

Also, when you get the code right, you get a message saying, “You can move on!” and when you get the fifth level right, you get “You’re free!” – but you get both, “You can move on! You’re free!” I would like to omit the “You can move on!” from the last bit and only print “You’re free!” to the terminal. I’m sure there’s a way to do that, I just cannot figure it out.

(fingers crossed I haven’t posted this to the wrong section somehow)

  1. You can use what you’ve already been taught. Have a function which a generate a random number is generated within the range of the number of messages you have, use that random number to decide which message should be printed.
  2. If you move the messages out of PlayGame this is much easier.
    main:
      setup.
      loop:
        PlayGame
        If won and not the last level, print message
        else if lost, print message
        (handle other cases here too)
    determine whether player won and print message
    
    Doing it this way also makes adding lives super easy to do.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms