HW 10 (Lunar Lander Part 2)
Assignment overview
You'll implement a graphical user interface to play the Lunar Lander game that you build in HW9.
If you did not get a working solution to HW9, please reach out to Anna early in the week. I want to help you get your code to a place where you'll be able to complete this assignment, independent of how HW9 went.
Goals
Practice using the graphics.py library (specifically, this will give you practice working with
classes and OOP).
Logistics
This is a partner assignment, which means you should complete all pieces of this assignment with your assigned partner. In particular, any coding must be completed side-by-side in a pair programming style. You are welcome to discuss the assignment with other classmates, course staff or Anna. Make sure to cite any help you receive in the "acknowlegdements" portion of the assignment.
You're working with the same partner as for HW9.
This assignment is due at 10PM on Friday, May 22.
Setup
Mount the COURSES drive and create a folder called hw10 in your STUWORK folder.
Open the new folder in VSCode.
If you need a refresher on how to complete these steps, refer back to the in-class
lab from the first day of class.
Copy the files from HW9 (graphics.py, interfaces.py, and lunarLander.py) into your HW10 folder.
You'll use the GraphicalLanderInterface in interfaces.py. Take some time to read through this class
carefully, and note the parts that seem incomplete (these should be noted in the method docstrings).
Using GraphicalLanderInterface
Change the constructor of your LanderGame class in lunarLander.py so that it uses the GraphicalLanderInterface
class. Once you've done this, you should be able to run your code as previously (python3 lunarLander.py).
Just click on the screen and watch the moon lander descend. (Why does this work? You used the methods from
the interface to interact with the user, and GraphicalLanderInterface has those same method names. If you didn't
use the methods from TextLanderInterface in HW9, you'll need to modify your code to use the methods before continuing.)
Depending on the difficulty levels you included in the HW9 game, the window may or may not be big enough to accomodate the
starting height. If you want, you can modify the size of the window (see the constructor of GraphicalLanderInterface).
Fixing the graphical interface
There are a few problems with the graphical interface, as written. First, there's no way to use thrust (currently, any mouse click just inputs 0 for the thrust amount). Second, there is no display of the current game state (properties of the lunar lander like altitude, velocity, and fuel level). Finally, when the lunar lander reaches the moon, the graphical window just closes and then a message is printed to the terminal, instead of displaying a message in the window itself.
You'll fix each of these problems. Specifically, you should modify GraphicalLanderInterface in the following ways:
- In the
getThrustmethod, make two buttons appear when the user is asked for a thrust amount. One button should be labeled "thrust" and the other "no thrust". Depending on which button is clicked, have the interface return 0 or 1. (Hints: like in the in-class lab, use a rectangle to create a button, and then add some text to it. You'll want to remove (undraw) the buttons once the user has clicked one of them.) - Edit the
showInfomethod so that it also displays the lunar lander's current status to the screen. Show enough information to be able to play the game (like theTextLanderInterface'sshowInfomethod does). This information should update each time thatshowInfois called, and it should remain on the screen even aftershowInfois complete. - Change the end-game methods so that they move the lander shape to be on hte moon's surface, and then display a short message in the graphical window. You should also wait for a user mouse click before continuing (i.e., before the program terminates and the window closes).
You have the skills necessary to complete each of these steps, but you'll likely have to look back at code from class
(particularly the graphics lab) and at the documentation
for graphics.py (or at the code for graphics.py, located in your current directory).
When you're doing coding projects in the future – beyond this class – you'll often need to use a library
that no one has taught you about. Learning to use libraries that others have written requires reading parts of the documentation
and doing some hands-on experimentation to see what works. This assignment is a chance to try that, while knowing you have
resources (Anna, the prefect, the lab assistants) to help you if you get stuck.
Improvements to the game
For the final 5 points on this assignment, you should implement at least 3 of these enhancements:
- A more complete control system (e.g., buttons for the user to select thrust 2, thrust 3, etc.)
- A lunar lander that looks more like a spaceship instead of a blue trapezoid
- A more celebratory result for a successful landing
- A more illustrative result of crashing onto the moon's surface
- A moon surface that is more detailed than just a gray rectangle
- Background (eg sun, earth, stars, an astronaut - use your imagination!)
- A scoring system that gives a score based on fuel remaining and speed at impact (i.e., the player should get a higher score if they are going at a slower speed when they land, and if they have extra fuel remaining at the end).
- An intro screen that allows the user to graphically choose a difficulty level.
Wrap up
When you're finished, make sure to complete the usual documentation steps. This includes adding comments, writing function docstrings, and adding a top-level comment, acknowledgements, and a reflection to the header.
You should also think about coding style. Have you written everything in a consistent way that is easy to read? Does your code have any unnecessary print statements? (Remove them.) Is there any repetitive code that could be rewritten to use loops or helper functions? Review the style document on Moodle for the expectations for this assignment.
Assignment submission and misc. notes
Handing in the assignment
You need to hand in lunarLander.py and interface.py on Gradescope. Only one partner should submit the
assignment to Gradescope (but make sure to add your partner to your group after submitting).
Grading
This assignment is worth 30 points, broken up as follows:
- 10 points - add "thrust" and "no thrust" buttons
- 5 points - display the lander status to the screen
- 5 points - modify the end of the game
- 5 points Improvements
- 5 points style (reflections, acknowledgments, comments, coding style)
Start early, ask lots of questions, and have fun!
Anna's acknowledgements
This assignment was adapted from Layla Oesper's teaching materials. Thanks for sharing!