HNRS 299, Spring 2017
AssignmentsDue Tuesday, March 28, at the beginning of class.
Background: Text based games.
Before computers were fast enough to show seamless animated graphics, several
text-based games were developed. The most famous of these were "Adventure" (the
first one) and "Zork". You can download a version of Zork to try out at
info.com or play
it directly at
http://textadventures.co.uk/games/view/5zyoqrsugeopel3ffhz_vq/zork.
In these games, the scenes are described in prose, rather than pictures and images,
and the player must tell the computer what to do, e.g. "go west", "light torch",
"hit dragon", etc. The game then describes what happens. Over the course of the
game, according to its own description, "the intrepid explorer delves into the forgotten secrets
of a lost labyrinth deep in the bowels of the earth, searching for
vast treasures long hidden from prying eyes, treasures guarded by
fearsome monsters and diabolical traps!"
Program description:
In this assignment you will write a very small piece of a text based game.
In it, the player finds him- or herself facing a large troll. The player can
choose to attack the troll or run away. If the player attacks, the attack may
damage the troll by varying amounts (chosen at random by the computer),
or it may miss, leaving the troll free to attack the player and end the game.
Part a. (15 points)
There are a few tricky pieces to this program so you will write it in stages.
For this stage, you will write the bulk of the program, including a simplified
version of the while loop.
In this program, which you should name <username>_battle1.py, the loop will only depend on whether the user answers yes or no to the question of whether they want to attack. Only the troll will lose health points. The user will be able to continue attacking the troll as long as he or she wants, even when the troll's health points go below zero.
The following are sample outputs for this program. User input is underlined.
Sample output 1:
You find yourself in a dark cave, facing a large troll. Your health level is 10. The troll's health level is 10. You may attack the troll or run away. If you attack, you might miss, allowing the troll to attack you. If you run away, you stay healthy, but you will not complete the mission. Do you want to attack? yes Your attack succeeded in wounding the troll. Your health level is 10 The troll's health level is 5 Do you want to attack? yes Your attack succeeded in wounding the troll. Your health level is 10 The troll's health level is 0 Do you want to attack? yes Your attack succeeded in wounding the troll. Your health level is 10 The troll's health level is -1 Do you want to attack? yes Your attack succeeded in wounding the troll. Your health level is 10 The troll's health level is -4 Do you want to attack? no You have defeated the troll! You may continue your quest.
Sample output 2:
You find yourself in a dark cave, facing a large troll. Your health level is 10. The troll's health level is 10. You may attack the troll or run away. If you attack, you might miss, allowing the troll to attack you. If you run away, you stay healthy, but you will not complete the mission. Do you want to attack? yes Your attack succeeded in wounding the troll. Your health level is 10 The troll's health level is 9 Do you want to attack? yes Your attack succeeded in wounding the troll. Your health level is 10 The troll's health level is 7 Do you want to attack? no You ran away. You live to fight another day!
Writing the program
To write the program, you will need to write the following pieces, in order.
Save this program as <username>_battle1.py.
Part b. (2 points)
It is rather unsportsmanlike to allow the user to keep attacking the troll even after
he is dead (health points are zero or less). In this part of the assignment you will
modify the program from part a that will exit the loop once the troll's health points
reach zero or less.
To modify your program, do the following:
A sample output is given below.
Sample output 3 (Compare this to Sample output 1 above).
You find yourself in a dark cave, facing a large troll. Your health level is 10. The troll's health level is 10. You may attack the troll or run away. If you attack, you might miss, allowing the troll to attack you. If you run away, you stay healthy, but you will not complete the mission. Do you want to attack? yes Your attack succeeded in wounding the troll. Your health level is 10 The troll's health level is 8 Do you want to attack? yes Your attack succeeded in wounding the troll. Your health level is 10 The troll's health level is 3 Do you want to attack? yes Your attack succeeded in wounding the troll. Your health level is 10 The troll's health level is -2 You have defeated the troll! You may continue your quest.
Save your code for this part in a file named <username>_battle2.py
Part c. (3 points)
This game is really no fun if there is no risk to the player when he or she attacks the troll.
In this part of the program, you will modify the program from part b so that the user
may miss when he or she attacks, which will lead to a devastating attack by the troll,
and an end to the game.
To modify the program, do the following:
Sample outputs of the final version of the program are given below.
Sample output 4:
You find yourself in a dark cave, facing a large troll. Your health level is 10. The troll's health level is 10. You may attack the troll or run away. If you attack, you might miss and lose health. If you run away, you stay healthy, but you will not complete the mission. Do you want to attack? yes Your attack succeeded in wounding the troll. Your health level is 10 The troll's health level is 6 Do you want to attack? yes Your attack succeeded in wounding the troll. Your health level is 10 The troll's health level is 2 Do you want to attack? yes Your attack succeeded in wounding the troll. Your health level is 10 The troll's health level is -3 You have defeated the troll! You may continue your quest.
Sample output 5:
You find yourself in a dark cave, facing a large troll. Your health level is 10. The troll's health level is 10. You may attack the troll or run away. If you attack, you might miss and lose health. If you run away, you stay healthy, but you will not complete the mission. Do you want to attack? yes Your attack succeeded in wounding the troll. Your health level is 10 The troll's health level is 7 Do you want to attack? yes Your attack missed. The troll attacks you. Your health level is 0 The troll's health level is 7 The troll delivered a devastating attack with his battle-axe. Game over!
Sample output 6:
You find yourself in a dark cave, facing a large troll. Your health level is 10. The troll's health level is 10. You may attack the troll or run away. If you attack, you might miss and lose health. If you run away, you stay healthy, but you will not complete the mission. Do you want to attack? yes Your attack succeeded in wounding the troll. Your health level is 10 The troll's health level is 6 Do you want to attack? no You ran away. You live to fight another day!