It's time to learn a new language! Python!
Python is a popular, easy-to-use programming language that has significant traction in the field.
Remember the goal is learning to learn, so keep track of what works for you and what doesn't as you go through the process of exploring Python.
-
Try to relate things you already know in another language (e.g. what an array is) to the corresponding things in Python (e.g. a list) and how to use them.
-
Write a bunch of "toy programs" that demonstrate different key features of the language
-
Explore the standard library that's available for the language. Skim it briefly for now--the idea isn't to memorize everything but to file away generally what functionality is available.
-
Write a more substantial toy program that uses a variety of the features.
Again, keep track of what works for you. Try different things to see what works best for learning new languages.
- Installing Python and pipenv
- JavaScript<->Python cheatsheet
- How to read Specs and Code
- Python 3 standard library
- Style Guide for Python Code
-
Make sure you have Python 3 and pipenv installed.
-
Go to the directory with the
Pipfile
and runpipenv install
-
After the install completes, run
pipenv shell
This will get you into the virtual environment. At this point, you should be able to run Python 3 by just running
python
:$ python --version Python 3.6.5
You can exit the virtual environment by typing
exit
.
- Learn the basic syntax and structure of Python
- Implement a number of tiny Python programs that demonstrate Python syntax.
Take a look in the src/
directory.
NOTE: adv/
is for Day 2, so ignore it for today.
Suggested order for implementing the toy programs:
hello
-- Hello worldbignum
-- Print some big numbersdatatypes
-- Experiment with type conversionmodules
-- Learn to import from modulesprintf
-- Formatted print outputlists
-- Python's version of arraystuples
-- Immutable lists typically for heterogenous dataslice
-- Accessing parts of listscomp
-- List comprehensionsdicts
-- Dictionariesfunc
-- Functionsargs
-- Arguments and Keyword Argumentsscope
-- Global, Local, and Non-Local scopefileio
-- Read and write from filescal
-- Experiment with module importsobj
-- Classes and objects
- Solidify the Python basics
- Implement a basic text adventure game
- Add classes for rooms and the player
- Add a simple parser that reads user input and performs actions
This is in src/adv/
. Check it out!
-
Put the Room class in room.py based on what you see in
adv.py
. -
Put the Player class in
player.py
. -
Follow the instructions
adv.py
. -
Figure out what all those
.pyc
files are that appear after you successfully run the program.
- Prepare for more OOP techniques
- Practice classes and lists
- Add items to the game that the user can carry around
- Make rooms able to hold multiple items
- Make the player able to carry multiple items
- Add two-word commands to the parser
- Add the
get
anddrop
commands to the parser
-
Add an
Item
class in a fileitem.py
.-
This will be the base class for specialized item types to be declared later.
-
The item should have
name
anddescription
attributes.- Hint: the name should be one word for ease in parsing later.
-
-
Add capability to add items to rooms.
-
The
Room
class should be extended with alist
that holds theItem
s that are currently in that room. -
Add functionality to the main loop that prints out all the items that are visible to the player when they are in that room.
-
-
Add capability to add
Item
s to the player's inventory. The inventory can also be alist
of items "in" the player, similar to howItem
s can be in aRoom
. -
Add a new type of sentence the parser can understand: two words.
-
Until now, the parser could just understand one sentence form:
verb
such as "n" or "q".
-
But now we want to add the form:
verb
object
such as "take coins" or "drop sword".
-
Split the entered command and see if it has 1 or 2 words in it to determine if it's the first or second form.
-
-
Implement support for the verb
get
followed by anItem
name. This will be used to pick upItem
s.-
If the user enters
get
ortake
followed by anItem
name, look at the contents of the currentRoom
to see if the item is there.-
If it is there, remove it from the
Room
contents, and add it to thePlayer
contents. -
If it's not there, print an error message telling the user so.
-
-
-
Implement support for the verb
drop
followed by anItem
name. This is the opposite ofget
/take
. -
Add the
i
andinventory
commands that both show a list of items currently carried by the player.
- Practice inheritance
- Practice method overriding
- Be able to call superclass methods
- Implement a callback/event structure
- Add scoring
- Subclass items into treasures
- Subclass items into light sources
- Add methods to notify items when they are picked up or dropped
- Add light and darkness to the game
-
Add a
score
to yourPlayer
class. Set it to 0. -
Add a single word command,
score
, that the user can type in to see their current score. -
Add a subclass to
Item
calledTreasure
.- The
Treasure
constructor should accept a name, description, and value.
- The
-
During world creation, add three
Treasure
s to convenientRoom
s. -
Add an
on_take
method toItem
.-
Call this method when the
Item
is picked up by the player. -
The
Item
can use this to run additional code when it is picked up.
-
-
Override
on_take
inTreasure
so that the player gets the value of theTreasure
added to theirscore
attribute but only the first time the treasure is picked up.- If the treasure is dropped and picked up again later, the player should not have the value added to their score again.
-
Add an
on_drop
method toItem
. Implement it similar toon_take
. -
Add a subclass to
Item
calledLightSource
. -
During world creation, add a
lamp
LightSource
to a convenientRoom
. -
Override
on_drop
inLightSource
that tells the player "It's not wise to drop your source of light!" if the player drops it. (But still lets them drop it.) -
Add an attribute to
Room
calledis_light
that isTrue
if theRoom
is naturally illuminated, orFalse
if aLightSource
is required to see what is in the room. -
Modify the main loop to test if there is light in the
Room
(i.e. ifis_light
isTrue
or there is aLightSource
item in theRoom
's contents or if there is aLightSource
item in thePlayer
's contents).-
If there is light in the room, display name, description, and contents as normal.
-
If there isn't, print out "It's pitch black!" instead.
-
Hint:
isinstance
might help you figure out if there's aLightSource
among all the nearbyItem
s.
-
-
Modify the
get
/take
code to print "Good luck finding that in the dark!" if the user tries to pick up anItem
in the dark.
In arbitrary order:
-
Add more rooms.
-
Add more items to the game.
-
Add a way to win.
-
Add more to the parser.
-
Remember the last
Item
mentioned and substitute that if the user types "it" later, e.g.take sword drop it
-
Add
Item
s with adjectives, like "rusty sword" and "silver sword".-
Modify the parser to handle commands like "take rusty sword" as well as "take sword".
- If the user is in a room that contains both the rusty sword and silver sword, and they type "take sword", the parser should say, "I don't know which you mean: rusty sword or silver sword."
-
-
-
Modify the code that calls
on_take
to check the return value. Ifon_take
returnsFalse
, then don't continue picking up the object. (I.e. prevent the user from picking it up.)- This enables you to add logic to
on_take
to code things like "don't allow the user to pick up the dirt unless they're holding the shovel.
- This enables you to add logic to
-
Add monsters.
-
Add the
attack
verb that allows you to specify a monster to attack. -
Add an
on_attack
method to the monster class. -
Similar to the
on_take
return value modification, above, haveon_attack
prevent the attack from succeeding unless the user possesses asword
item. -
Come up with more stretch goals! The sky's the limit!