Python by Projects › Grand Adventure
Problems: Grand Adventure
Build the year's biggest program: a text adventure with a hero, a world to explore, and progress you can save. Your hero will travel through rooms, collect useful items, and return for another adventure later.
Milestone 1: Meet your hero
Every great adventure begins with a hero. Build one Hero class whose __init__ method sets self.name, self.health, and self.inventory.
Author a take_damage(self, amount) method inside Hero. It must subtract amount from self.health and return the new self.health. After you print the hero's starting stats, call hero.take_damage(3), store its return value in health_after_damage, and print that returned health so you can see that it works.
Run this starter, enter a hero name, and print the hero's starting stats. Then personalize the starting health or welcome message.
How this is checked: You check this one yourself, against the list below.
The site cannot check this one. Run your program, then tick each item below when your work does it.
Milestone 2: Build the world
Give your hero somewhere to explore. The world uses THREE FLAT dictionaries: room descriptions, exits, and room items. Extend the dictionaries with your own rooms, but keep the same shape.
An exit key is ONE composite string in the form "room direction", such as "cave east". There is NO dictionary nested inside another dictionary.
How this is checked: You check this one yourself, against the list below.
The site cannot check this one. Run your program, then tick each item below when your work does it.
Milestone 3: Explore the adventure
Bring the world to life with an exploration loop. Each turn, ask for a direction, join the current room and direction into move_key, move when that key is in exits, and collect an item when the new room is in room_items. Enter q to end the loop.
On your graded playthrough, collect at least one item. Then author one use of list indexing to retrieve an item from hero.inventory and use that item in a printed message. Appending an item does not count as list indexing.
After the basic journey works, you could add a random trap event with random.randint. Keep that idea for later—the scaffold does not implement it for you.
(Reading tip: item not in hero.inventory is just the opposite of in — it is True when the item is NOT already in the list.)
How this is checked: You check this one yourself, against the list below.
The site cannot check this one. Run your program, then tick each item below when your work does it.
Milestone 4: Save and load the journey
Let the adventure continue another day. Save ONE value per line in adventure_save.txt: line 0 is the hero's name, line 1 is health, and lines 2 and beyond are inventory items.
Use one with block to write the file. Then use a separate with block that loops over the file line by line (for saved_line in save_file:) to load it, use .strip() on each saved line, convert health back to an integer, and confirm that the loaded values match the hero you saved.
How this is checked: You check this one yourself, against the list below.
The site cannot check this one. Run your program, then tick each item below when your work does it.
Milestone 5: Assemble the Grand Adventure
Turn the four scaffolds into one coherent program. Run it from the first cell through the last: create one hero only in Milestone 1, never replace that hero with a new Hero object, and use the same hero in the world and exploration loop before saving and loading the progress produced by that playthrough. The graded program must complete a route that collects an item, use your Hero.take_damage method and your inventory list index, reach the quit branch, and finish the save/load round trip without you manually replacing values between milestones.
How this is checked: You check this one yourself, against the list below.
The site cannot check this one. Run your program, then tick each item below when your work does it.
Make it yours
Choose an extension after your five milestones work.
- Add more rooms by extending the same three flat dictionaries.
- Add a healing method to the
Heroclass that changes health. - Add a score that grows when the hero explores or finds an item.
Requirements checklist
Your adventure must have a Hero class with a working method, the world dictionaries, an exploration loop, save/load, and one complete assembled run.
Before your grand adventure begins, check every box.
- [ ] My program has one
Heroclass with a name, health, and inventory. - [ ] I authored and called
take_damage(self, amount), and it returns the hero's new health. - [ ] My world uses the three flat dictionaries and composite
"room direction"exit keys. - [ ] My exploration loop moves between rooms, collects items, and lets the player quit.
- [ ] I used list indexing to retrieve an inventory item and used it in a message.
- [ ] My program saves and loads the hero's name, health, and inventory.
- [ ] My assembled program runs all five milestones as one adventure without manually replacing values.