8000 new adv · pythonminna/Intro-Python@82ed3fe · GitHub
[go: up one dir, main page]

Skip to content

Commit 82ed3fe

Browse files
author
Beej Jorgensen
committed
new adv
1 parent a551651 commit 82ed3fe

File tree

6 files changed

+69
-77
lines changed

6 files changed

+69
-77
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
.vscode/
1+
.vscode
2+
*.pyc
3+
__pycache__

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Learn the basics of Python with a pile of toy programs.
6363

6464
Take a look in the `src/` directory.
6565

66-
NOTE: `adv.py` is for Day 2, so ignore it for today.
66+
NOTE: `adv/` is for Day 2, so ignore it for today.
6767

6868
Suggested order for implementing the toy programs:
6969

@@ -85,7 +85,16 @@ Suggested order for implementing the toy programs:
8585

8686
Put it together into a bigger toy program: a simple text adventure!
8787

88-
This is in `src/adv.py`. Check it out!
88+
This is in `src/adv/`. Check it out!
89+
90+
* Put the Room class in room.py based on what you see in `adv.py`.
91+
92+
* Put the Player class in `player.py`.
93+
94+
* Follow the instructions `adv.py`.
95+
96+
* Figure out what all those `.pyc` files are that appear after you successfully
97+
run the program.
8998

9099
Stretch goals:
91100

src/adv.py

Lines changed: 0 additions & 74 deletions
This file was deleted.

src/adv/adv.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from room import Room
2+
3+
# Declare all the rooms
4+
5+
room = {
6+
'outside': Room("Outside Cave Entrance",
7+
"North of you, the cave mount beckons"),
8+
9+
'foyer': Room("Foyer", """Dim light filters in from the south. Dusty
10+
passages run north and east."""),
11+
12+
'overlook': Room("Grand Overlook", """A steep cliff appears before you, falling
13+
into the darkness. Ahead to the north, a light flickers in
14+
the distance, but there is no way across the chasm."""),
15+
16+
'narrow': Room("Narrow Passage", """The narrow passage bends here from west
17+
to north. The smell of gold permeates the air."""),
18+
19+
'treasure': Room("Treasure Chamber", """You've found the long-lost treasure
20+
chamber! Sadly, it has already been completely emptied by
21+
earlier adventurers. The only exit is to the south."""),
22+
}
23+
24+
25+
# Link rooms together
26+
27+
room['outside'].n_to = room['foyer']
28+
room['foyer'].s_to = room['outside']
29+
room['foyer'].n_to = room['overlook']
30+
room['foyer'].e_to = room['narrow']
31+
room['overlook'].s_to = room['foyer']
32+
room['narrow'].w_to = room['foyer']
33+
room['narrow'].n_to = room['treasure']
34+
room['treasure'].s_to = room['narrow']
35+
36+
#
37+
# Main
38+
#
39+
40+
# Make a new player object that is currently in the 'outside' room.
41+
42+
# Write a loop that:
43+
#
44+
# * Prints the current room name
45+
# * Prints the current description (the textwrap module might be useful here).
46+
# * Waits for user input and decides what to do.
47+
#
48+
# If the user enters a cardinal direction, attempt to move to the room there.
49+
# Print an error message if the movement isn't allowed.
50+
#
51+
# If the user enters "q", quit the game.

src/adv/player.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Write a class to hold player information, e.g. what room they are in
2+
# currently.

src/adv/room.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Implement a class to hold room information. This should have name and
2+
# description attributes.

0 commit comments

Comments
 (0)
0