This problem involves understanding and modifying an object-oriented program. It will give you an opportunity to apply what you've learned about object-oriented programming by creating a working game. You are welcome and encouraged to work with a partner on this single programming problem. One of you should turn it in (using the submit script); be sure to indicate both names.
pyProcessing is a Python library we'll use for graphics in Python. The pyProcessing tutorial and quick reference may be helpful, as will the O-O examples we developed in class. pyProcessing emulates the functionality of Processing, a programing language (of a sort) designed to make it easy to program for the visual arts. For the most part, we can use any of the functions that are available in Processing. So, you may want to see the Processing reference guide and tutorials for extra background.
In this homework problem you will implement the game of Sokoban. The game itself is fairly simple: each level is a simple maze with a couple of objects scattered about it (in our case, we will call them boxes). The goal of the game is to push the boxes to specially designated ‘goal’ locations in the maze. When all goal tiles are covered with boxes, you advance to the next level. The challenge of the game is that the boxes are really heavy, and you can only move them by pushing. In fact they are so heavy that you can only push one at a time. If you push one box into another one, it will no longer move. So you have to be a little canny about how you move the boxes around. You can play the game at sokoban.info, which has the classic levels that we are using for our version (there are many other implementations out there).
Implementing this from scratch would be a bit daunting, so we'll provide you with a substantial amount of the code, leaving it to you to fill in some of the details. Here is what you need to do (work in the order specified below and test frequently):
Read through the code and try to understand it. The code includes a large number of comments to help guide you through this process. Pay particular attention to how things get drawn and the mechanics of moving pieces around on the board.
Create the visual look of the game by adding code
to the draw()
functions for the tiles, boxes and the
player. Make sure that you can easily distinguish between open
tiles, walls, boxes, and the player.
Implement the isFree()
and getNeighbor()
functions of the Tile class.
Write the movePiece()
method on the Board class.
Edit the code so the player object can be controlled by the
arrow keys. This involves editing the move()
function
of the player and the keyPressed()
method of the
board.
Change the player’s move()
function so that
it shoves any obstructions out of the way if possible.
Implement the levelComplete()
function and edit
the keyPressed()
function so that it calls
levelComplete()
and advances to the next level if all
boxes are on goals.
Implement at least one cool thing (see below) of your choice.
To begin, download cs101_hw10_sokoban.zip. In it, you will find the starter code you will be working with as well as a folder called levels. This contains all of the various levels in text file format. You will need to keep this folder in the same folder as your Python file so that the loader can find the level files. Rename the Python file to username_hw10_sokoban.py.
"Cool things" are elements that you add to the program that go above and beyond what is asked for in the assignment. Here's a short list of some, but do not feel obligated to be limited by these. You also do not need to follow the below cool things to the exact letter; if you like an idea, but want to do it a little differently from how it is described, that is fine.
IMPORTANT: The one requirement is that you include in a comment at the top of your Python file a list of the cool things that you added to the assignment.
ADVICE: Make copies of the file as you make changes. In particular, before you start adding in cool things, save a clean copy of your working game somewhere safe so you can always go back to that.
Here are some potential cool things:
For this portion of the assignment, turn in one file called username_hw10_sokoban.py. You do not need to turn in your levels folder.
Update all comments and add your own. Any new functions should have appropriate comments. If you change one of the given functions, update the comments to reflect the changes (this includes adding your name at the top of the file). Also, do not forget to list the cool thing(s) in the header comment.