$30
File Input/Output and Functions
In this assignment, you will write a small game called traveller.py. The purpose of this game is to travel along a path.
a. The player starts at position 1 and needs to move to position 10. The current position on the path must be stored as csv data in a file called road. Think of each position on the path as being between the commas of the csv file. The player will be represented in this file as an X.
b. The player starts with 100 health, which must be stored in a file called health.
c. [IS 615 only] The player starts with a potion, which must be stored in a file called inventory.
Your program will need to take dynamic user input using the input() function. Each time a user provides an input, this is considered a single turn. The user can provide one of three valid inputs: r for roll the dice, p for consume potion, and q to quit.
When the dice is rolled, 1 of 6 outcomes will occur:
1. Take 10 damage
2. Take a step backwards
3. Pray for salvation and roll a d10 to be saved. If the roll is equal to 7, send the player to the end of the path. Otherwise do nothing.
4. Take 40 damage
5. [IS 615 only] Double your next movement (forward or back). [IS 415] Do nothing.
6. Take a step forward
[IS 615 only] When the potion is selected, restore up to 70 health (100 is full health), and the potion is now empty and cannot be reused.
You must not maintain any information in any variables between turns. Everything that you need to remember must be stored in the files: road, health and inventory.
You will need to write many functions to create this game. Each action should be stored in a function. For example, getting the current position on the road should be performed by a function that returns a list that contains the information stored in the road file.
The current health and current position on the road should be shown to the user on every turn.
The player cannot move beyond the edges of the road, positions 1 and 10. Being at position 10 is the win condition.
The outcome of each dice roll should be shown to the user. Below is an example game:
>python traveller.py
Your current health is: 100 X| | | | | | | | |
Your journey begins. You are What will you do, traveller?
only at the first position. r
You rolled a 1
You took 10 damage
Your current health is: 70
What will you do, traveller? |X| | | | | | | |
r
You rolled a 1 You took 10 damage
Your current health is: 90 What will you do, traveller?
X| | | | | | | | | r
You rolled a 5
Double your next movement
Your current health is: 70
What will you do, traveller? |XX| | | | | | | |
r
You rolled a 1 You took 10 damage
Your current health is: 80 What will you do, traveller?
X| | | | | | | | | r
You rolled a 1
You took 10 damage
Your current health is: 60
What will you do, traveller? |XX| | | | | | | |
r
You rolled a 5 Double your next movement
Your current health is: 80 What will you do, traveller?
XX| | | | | | | | | r
You rolled a 4
You took 40 damage
Your current health is: 20
What will you do, traveller? |XX| | | | | | | |
r
You rolled a 6 You moved forward
Your current health is: 80 What will you do, traveller?
| |X| | | | | | | p
You consumed your potion
Your current health is: 90
|XX| | | | | | | |
What will you do, traveller? r You rolled a 3
Nobody heard your prayers What will you do, traveller?
Your current health is: 80 r
| |X| | | | | | | You rolled a 6
You moved forward
Your current health is: 90
| | |X| | | | | |
What will you do, traveller? r You rolled a 2
You moved back What will you do, traveller?
Your current health is: 80 r
|X| | | | | | | | You rolled a 6
You moved forward
Your current health is: 90
| | | |X| | | | |
What will you do, traveller? r You rolled a 5
Double your next movement
Your current health is: 90
| | | |XX| | | | |
What will you do, traveller? r You rolled a 5
Double your next movement
Your current health is: 90
| | | |XXXX| | | | |
What will you do, traveller? r You rolled a 3
Nobody heard your prayers
Your current health is: 90
| | | |XXXX| | | | |
What will you do, traveller? r You rolled a 6
You moved forward
Your current health is: 90
| | | | | | | |X|
What will you do, traveller? r You rolled a 1
You took 10 damage
Your current health is: 80
| | | | | | | |X|
What will you do, traveller? r You rolled a 6
You moved forward You made it to the end of the road. Well done. You win!
If the player inputs something other than an r, p or q, print out the possible inputs and wait for another user input.
If the player rolls a 3 and then subsequently rolls a 7, they are moved to position 10 and win:
The potion can only be consumed once:
If the player runs out of health, they die and the game is over: