Write a program using an object
Start to create your object-oriented text-based adventure game
Extend other people’s classes
Create an enemy in the room
Recap Week 3
Extending your knowledge of OOP
Finish your game
End of the course
Congratulations! You have now created your own adventure game in object-oriented style!
One of the benefits of writing your code in this programming style is that you can share the reusable classes you have written, so that other people can use them to make their own games. If you are an educator, you might want to share them with your students, allowing them to create their own games. Alternatively, you might simply want to share your code with the world!
Sharing your code with other people need not be limited to people you know. It is very easy to share your code online so that anyone, anywhere can use it.
This probably sounds scary — after all, this is your first object-oriented program. However, you might be surprised and pleased by other people’s reaction to your code – you might get offers of help, or you might make someone’s day by saving them a lot of time!
You can use a website such as GitHub to share your code so that other people can use it, and maybe even suggest changes. Follow this GitHub guide for beginners to get your code online.
If you are sharing your code, it is useful to provide some documentation so that people know what classes and methods are available, and how to use them. Python has a built-in feature for automatically creating basic documentation.
You will only be able to use this feature if you are using Python installed on your computer, rather than using Trinket or Repl.it.
You will need to add docstrings to your code, which will form the basis of the documentation. This is very easy — simply add a line of explanation at the start of each method and enclose it in triple quotation marks, like this:
def get_description(self):
"""
Returns a string containing the description of the room
"""
return self.description
This project on Documenting your code will show you how to turn docstrings into HTML documentation and create your own project website. The shapes documentation you used in week one was created using this method.
You have probably already used Python packages by adding an import statement at the top of your script, like this:
import random
Including your RPG code into a package means that anyone can install it and then import it into their programs.
The packaging your code project will take you through: - Turning your code into a package by adding an __init__.py file - Creating a set-up program - Building a distribution that can be downloaded
What useful code would you like to see shared, documented, and packaged? Leave your thoughts in the comments section.