Python代写:CS1591 The Camel Game

用基本的Python语法,完成一个简单的小型文字游戏。

Tutorial

In this tutorial you will use the basic python programming techniques that you have learned in 159171 and that we have revised during the first week of classes, in particular conditional statements and loops, and random number generation.
The idea for Camel originally came from the Heath Users Group and was published in More BASIC Computer Games in 1979. This version comes from Paul Craven’s online text “Program Arcade Games with Python and Pygame”.
The idea is to ride your camel across the desert while being chased. You need to manage your thirst, how tired the camel is, and how far ahead of the natives you are. It is easy to add sandstorms and other random events to the game to make it more interesting.

Sample Run of Camel

Here is a sample run of the game:

Welcome to Camel!
You have stolen a camel to make your way across the great Mobi desert.
The natives want their camel back and are chasing you down! Survive 
your desert trek and outrun the natives.

A. Drink from your canteen.
B. Ahead moderate speed.
C. Ahead full speed.
D. Stop and rest.
E. Status check.
Q. Quit.
Your choice? C

You traveled 12 miles.

A. Drink from your canteen.
B. Ahead moderate speed.
C. Ahead full speed.
D. Stop and rest.
E. Status check.
Q. Quit.
Your choice? C

You traveled 17 miles.

A. Drink from your canteen.
B. Ahead moderate speed.
C. Ahead full speed.
D. Stop and rest.
E. Status check.
Q. Quit.
Your choice? eYour choice? e

Miles traveled:  29
Drinks in canteen:  3
The natives are 31 miles behind you.

A. Drink from your canteen.
B. Ahead moderate speed.
C. Ahead full speed.
D. Stop and rest.
E. Status check.
Q. Quit.
Your choice? b

You traveled 6 miles.
...and so on until...

A. Drink from your canteen.
B. Ahead moderate speed.
C. Ahead full speed.
D. Stop and rest.
E. Status check.
Q. Quit.
Your choice? C

You traveled 12 miles.
The natives are getting close!

A. Drink from your canteen.
B. Ahead moderate speed.
C. Ahead full speed.
D. Stop and rest.
E. Status check.
Q. Quit.
Your choice? C

You traveled 11 miles.
The natives are getting close!
You made it across the desert! You won!

Programming Guide

Here are the steps to complete this tutorial task. Feel free to modify and add to the program. Try the game with your classmates, or friends and family.

  1. Create a new program camel.py and add code to print the instructions to the screen. Do this with multiple print statements. Don t use one print statement and multiple \n characters to jam everything on one line.
  2. Create a boolean variable called done and set to False.
  3. Create a while loop that will keep looping while done is False.
  4. Inside the loop, print out the following.
  5. Ask the user for their choice. Make sure to add a space before the quote so the user input doesn’t run into your text.
  6. If the user’s choice is Q, then set done to True. By doing something like user_choice.upper() instead of just user_choice in your if statement you can make it case insensitive.
  7. Test and make sure that you can quit out of the game.
  8. Before your main program loop, create variables for miles traveled, thirst, camel tiredness. Set these to zero.
  9. Create a variable for the distance the natives have traveled and set it to -20. (Twenty miles back.)
  10. Create and set an inital number of drinks in the canteen.
  11. Add an elif in your main program loop and see if the user is asking for status. If so, print out something.
  12. Add an elif in your main program loop and handle if the user wants to stop for the night. If the user does, reset the camel’s tiredness to zero. Print that the camel is happy, and move the natives up a random amount from 7 to 14 or so.
  13. Add an elif in your main program loop and handle if the user wants to go ahead full speed. If the user does, go forward a random amount between 10 and 20 inclusive. Print how many miles the user traveled. Add 1 to thirst. Add a random 1 to 3 to camel tiredness. Move the natives up 7 to 14 miles.
  14. Add an elif in your main program loop and handle if the user wants to go ahead moderate speed. If the user does, go forward a random amount between 5 and 12 inclusive. Print how many miles the user traveled. Add 1 to thirst. Add a random 1 to camel tiredness. Move the natives up 7 to 14 miles.
  15. Add an elif in your main program loop and handle if the user wants to go ahead drink from the canteen. If the user does, make sure there are drinks in the canteen. If there are, subtract one drink and set the player’s thirst to zero. Otherwise print an error.
  16. In the loop, print “You are thirsty” if the user’s thirst is above 4.
  17. Print “You died of thirst” if the user’s thirst is above 6. Set done to true.
  18. Print “Your camel is getting tired.” if the camel’s tiredness is above 5.
  19. Print “Your camel is dead.” if the camel’s tiredness is above 8.
  20. If the natives have caught up, print that they caught the player and end the game.
  21. Else if the natives are less than 15 miles behind, print “The natives are getting close!”
  22. If the user has traveled 200 miles across the desert, print that they won and end the game.
  23. Add a one-in-twenty chance of finding an oasis. Print that the user found it, refill the canteen, reset player thirst, and rest the camel.
  24. Play the game and tune the numbers so it is challenging but not impossible. Fix any bugs you find.

Hints

  • Remember that it is good idea to put blank lines between logical groupings of code in your program. For example, but a blank line after the instructions, and between each user command.
  • It is considered better style to use while not done: instead of while done == False:
  • To prevent bad message combinations, such as printing “You died of thirst.” and “You found an oasis!” on the same turn, use the and operator. Such as, if not done and thirst > 4:

Submit a copy of your camel.py file, with your completed code, via Stream. Internal students: please note that you must attend a workshop session and show evidence of making progress on this tutorial during the session in order to gain marks for your work.