Skip to main content
Engineering LibreTexts

11.3: Enhancements

  • Page ID
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    What will make or break the game are the enhancements. Again, it is recommended that you start with the core described above, perhaps with only two or three weapons, get that working, and then proceed to enhance the program. The first step would be to expand the armory (i.e., the choices of weapons). Other ideas include randomizing the win/lose messages so that a certain weapon does not always generate the same message. One way to do that is as follows for each weapon:

    m = random.randrange(3)
    if m == 0:
         print( “You won!” )
    elif m == 1:
         print( “The rabbit is defeated!” )
         print( “The rabbit was no match for you!” )

    This technique will work but there is a more efficient method utilizing tuples (see the Tuples exercise for a general explanation; the random integer would serve as the index into a tuple of messages thereby removing the need for the if/elif structure for much more compact code).

    Other ideas include awarding an extra life as well as points for a particularly unlikely weapon, removing points as well as a life if the player loses on a “sure thing” weapon (i.e., The Holy Hand Grenade of Antioch) or preventing the player from using a certain weapon too many times (a variable would need to be added to keep track of the number of times the weapon was used). A popular add-on is the “extra life”. At the end of the loop, the score could be compared to a preset value (say, 5000 points) and an extra life added if that level is exceeded. This is somewhat trickier that it appears to be at first. A more interesting variant is the idea of adding lives for every “so many” points, such as a new life every 5000 points. There are a couple of different ways to do this but this also is not as simple as it at first appears.

    For the more adventurous, advanced scores could expand the weapons menu or even introduce a new level, such as battling the Black Knight at the bridge or trying to escape from the Castle Anthrax. Different levels can be thought of as new loops added after the first loop (not within).

    Take your time with the enhancement and try to make something that you and your friends might find enjoyable.

    This page titled 11.3: Enhancements is shared under a not declared license and was authored, remixed, and/or curated by James M. Fiore.

    • Was this article helpful?