Question
You are given the class SokobanGUI that implements a simple graphical user interface for the game Sokoban. Click the image below to watch a short
You are given the class SokobanGUI that implements a simple graphical user interface for the game Sokoban. Click the image below to watch a short video of the completed assignment problem:
This problem involves several classes:
- Location: a class that represents a grid location (x,y) where x and y are integer coordinates. The positive x-direction points to the right, and the positive y-direction points down.
- Wall: a class that represents a wall square
- already implemented for you
- Storage: a class that represents a storage location square
- already implemented for you
- Box: a class that represents a box
- already implemented for you
- Player: a class that represents the player
- already implemented for you
- Board: a class that represents a game of Sokoban; it manages all of the wall, storage, box, and player objects
Begin by reviewing the documentation for the class Location. It is very similar to the Point2 class from the course notebooks.
Complete the implementation of the class Location. You should probably add a main method to the class (or create one in a different class) to test your implementation.
Review the implementation of the classes Wall, Storage, Box, and Player. You should pay attention to the methods that the classes provide. Also notice how similar the classes are to one another.
Edit the file Board.java. Begin by deciding what fields you will use to manage the walls, boxes, and storage sites, and add these fields to the class. You need some type of collection for each of the walls, boxes, and storage sites; any collection type can be made to work, but your choice of collection type will affect how other methods in the class are implemented. Arrays, lists, sets, and maps are all workable.
Next, implement the first constructor which creates a simple board. Use the main method and the provided toString method to test your constructor.
Next, implement the second constructor which reads in a board level from a file. The file is a plain-text file where:
- space is an empty square
- # is a wall
- @ is the player
- $ is a box
- . is a storage location
- + is the player on a storage location
- * is a box on a storage location
The level shown in the animated GIF near the beginning of the assignment looks like:
##### ### # #.@$ # ### $.# #.##$ # # # . ## #$ *$$.# # . # ########
There are eight different level files included in the project in the sokoban package directory.
The number of rows in the file is the height of the board. The widest row is the width of the board. The upper-left corner is the location (0,0) and the bottom-right corner is (width1,height1).
To implement the second constructor, initialize your fields in the constructor then call the method readlevel. The first two lines of readLevel opens the level file and read the contents into a list named level. The size of the list is equal to the height of the board. The longest string in the list defines the width of the board.
You need to complete the implementation of readLevel by parsing the strings in the list level to compute the locations of the wall, box, storage, and player objects. Much of the implementation has been done for you; you need to fill the bodies of the if statements.
Use the main method and the provided toString method to test your constructor.
Next, implement the remaining methods in the order that they appear in the class. Depending on what collection type you chose to store the walls, boxes, and storage sites, you may find yourself writing a loop or two for every method.
When your class is complete, run the class SokobanGUI to play a game of Sokoban.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started