Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write the code for move player left and right in java You are given the class SokobanGUI that implements a simple graphical user interface for

image text in transcribedimage text in transcribedimage text in transcribedwrite the code for move player left and right in java

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: Assignment 3 Sokoban app 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 o already implemented for you Box : a class that represents a box o 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, classes are to one another. Box , and player . You should pay attention to the methods that the classes provide. Also notice how similar the 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 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: ***** *** # #.$$ *** $. #.#$# ## #$55. + # *** 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 comer is (width - 1, height - 1). 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 reads 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 readilevel 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 1t 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 Sokobangun to play a game of Sokoban. /** * Moves the player to the left adjacent location if possible. If there is a box * in the left adjacent location then the box is pushed to the adjacent location left of the box.

* Returns {@code false} if the player cannot move to the left adjacent location (leaving the player location unchanged). * @return true if the player is moved to the left adjacent location, false otherwise */ public boolean movePlayerLeft() { | } /** * Moves the player to the right adjacent location if possible. If there is a * box in the right adjacent location then the box is pushed to the adjacent * location right of the box. *

Returns {@code false} if the player cannot move to the right adjacent * location (leaving the player location unchanged). * * > @return true if the player is moved to the right adjacent location, false otherwise */ public boolean movePlayerRight() { } 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: Assignment 3 Sokoban app 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 o already implemented for you Box : a class that represents a box o 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, classes are to one another. Box , and player . You should pay attention to the methods that the classes provide. Also notice how similar the 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 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: ***** *** # #.$$ *** $. #.#$# ## #$55. + # *** 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 comer is (width - 1, height - 1). 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 reads 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 readilevel 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 1t 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 Sokobangun to play a game of Sokoban. /** * Moves the player to the left adjacent location if possible. If there is a box * in the left adjacent location then the box is pushed to the adjacent location left of the box.

* Returns {@code false} if the player cannot move to the left adjacent location (leaving the player location unchanged). * @return true if the player is moved to the left adjacent location, false otherwise */ public boolean movePlayerLeft() { | } /** * Moves the player to the right adjacent location if possible. If there is a * box in the right adjacent location then the box is pushed to the adjacent * location right of the box. *

Returns {@code false} if the player cannot move to the right adjacent * location (leaving the player location unchanged). * * > @return true if the player is moved to the right adjacent location, false otherwise */ public boolean movePlayerRight() { }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions