"Hello, soldier!"

"Hello, Captain Squirrels, sir!"

"Congratulations. Today we have a day off."

"And we can do whatever we want?"

"Yes, Amigo. You can play with your toys all day long. For example, Sokoban. My favorite game since childhood. I can't get past level 435. Can you help?"

"Of course, I'll will help, I'll show you, Captain."

Captain Squirrels pulls an old Game Boy out of his pocket and starts up the monochrome version of Sokoban. But then there's disappointment. The battery runs out, and the Game Boy shuts down.

Silently, the captain looks at the Game Boy, then at Amigo, then again at the Game Boy. He turns around and slowly walks to his office.

"Captain! Let's write our own version of Sokoban! We'll think up 1000 additional levels and make a cool graphical interface."

"Amigo, you never cease to amaze me. Contact Agent IntelliJ IDEA. If he has no other assignments for you and wants to help you on his day off, then proceed."

Big task: Write Sokoban - 1
undefined
20
Task
Java Collections, level 10, lesson 15
Locked
Sokoban (part 1)
Today we're going to write our own implementation of the game Sokoban. This is a logical puzzle game. You can read more about it on Wikipedia. The game will consist of 3 main components (as you may have guessed, you'll need the MVC pattern). The graphical interface will be implemented using Swing.
undefined
10
Task
Java Collections, level 10, lesson 15
Locked
Sokoban (part 2)
The foundation is laid, so now let's start building. You can think of the gameplay as the interaction of GameObject objects. We'll have several types of them: Box, StorageLocation (the place where you need to put the box), Wall, and Player. 2.1. Add an abstract GameObject class to the model package
undefined
10
Task
Java Collections, level 10, lesson 15
Locked
Sokoban (part 3)
Soon we'll be creating various game objects. It would be handy to be able to draw them somewhere right away and see how they look. Objects will be drawn on the game board represented by a Board object. You've received modified code for the View class that creates a Board object and sets up the view
undefined
20
Task
Java Collections, level 10, lesson 15
Locked
Sokoban (part 4)
We already have a shared GameObject class. It's time to create classes for specific types of game objects. 4.1. Some game objects can move (player and boxes) and some can't (walls and storage locations). 4.1.1. Add the Movable interface to the model package. 4.1.2. The Movable interface must have a
undefined
20
Task
Java Collections, level 10, lesson 15
Locked
Sokoban (part 5)
Box and Player game objects can not only collide with other objects, but also move around the board. 5.1. Create a Player class and a Box class in the model package. Make each of them inherit the most appropriate class. 5.2. The created classes must support the interface responsible for object move
undefined
10
Task
Java Collections, level 10, lesson 15
Locked
Sokoban (part 6)
It's time to create the StorageLocation class. This class will be responsible for the game board cells that all the boxes must be moved to. Objects of this type must not move across the board or collide with other game objects. 6.1. Add a StorageLocation class to the model package. 6.2. The class m
undefined
10
Task
Java Collections, level 10, lesson 15
Locked
Sokoban (part 7)
Let's make the Wall class. A wall can collide with other objects, but it can't move. 7.1. Add a Wall class to the model package. 7.2. Make the class inherit the appropriate parent class. 7.3. Implement a constructor with int x and int y parameters. 7.4. Implement the method for drawing. Hint: you c
undefined
10
Task
Java Collections, level 10, lesson 15
Locked
Sokoban (part 8)
You've created the complete collection of game objects. Let's create a class to store these objects. 8.1. Create a GameObjects class in the model package. 8.2. Add the following: 8.2.1. Set walls, Set boxes, Set storageLocations, and Player player fields. 8.2.2. Getters
undefined
10
Task
Java Collections, level 10, lesson 15
Locked
Sokoban (part 9)
Various events will occur during the game. Let's create an EventListener interface. Every class that wants to handle events must implement it. And classes that generate events will call this interface's methods. 9.1. Add the EventListener interface to the controller package. 9.2. Add these void met
undefined
20
Task
Java Collections, level 10, lesson 15
Locked
Sokoban (part 10)
The game will have several levels, and all of them will be stored in a text file. Now we'll write a LevelLoader test stub. Why a test stub? We don't need the full functionality yet. It's pretty complicated, so we'll leave it for later. For now: 10.1. Create a LevelLoader class in the model package.
undefined
20
Task
Java Collections, level 10, lesson 15
Locked
Sokoban (part 11)
Let's begin fleshing out the Model class' functionality. Add the following: 11.1. A GameObjects gameObjects field. It will store our game objects. 11.2. An int currentLevel field that stores the current level. Initialize it to 1. 11.3. A LevelLoader levelLoader field that stores the level loader. I
undefined
20
Task
Java Collections, level 10, lesson 15
Locked
Sokoban (part 12)
Let's try organizing the interaction between the view and model. 12.1. Add an update() method to the View class. It must call the repaint() method on the board field. In other words, the update() method will update the view (redraw the board). 12.2. Add the GameObjects getGameObjects() method to th
undefined
20
Task
Java Collections, level 10, lesson 15
Locked
Sokoban (part 13)
Let's fill out the controller's functionality. 13.1. In addition to what the Controller class constructor already has, add event listeners on the model and view. The controller must itself be a listener. 13.2. Implement the controller's methods: 13.2.1. move(Direction direction) - should call the m
undefined
20
Task
Java Collections, level 10, lesson 15
Locked
Sokoban (part 14)
Let's make our game more interactive (using a keyboard to move the player). We'll start by handling keystrokes. 14.1. Add to the Board class a nested KeyHandler class that inherits KeyAdapter. 14.2. Overload its keyPressed() method. If the key with code VK_LEFT is pressed, then send an event with a
undefined
40
Task
Java Collections, level 10, lesson 15
Locked
Sokoban (part 15)
The time has come to implement the model's move() method, which is responsible for movement. But first, let's implement some helper methods. Add the following methods to the Model class: 15.1. boolean checkWallCollision(CollisionObject gameObject, Direction direction). This method checks for collis
undefined
20
Task
Java Collections, level 10, lesson 15
Locked
Sokoban (part 16)
All that remains is to finish implementing the level loader. 16.1. Open the levels.txt file and carefully study the file structure. The character 'X' represents a wall, ‘*’ represents a box, ‘.’ represents a storage location, ‘&’ represents a box in a storage location, and ‘@’ represents the player
undefined
10
Task
Java Collections, level 10, lesson 15
Locked
Sokoban (part 17)
You're a superstar! You've made a great game. Now you can relax a bit and play it. If you ever get tired of it, which is practically impossible, you could make the following improvements: 17.1. Use images to represent the objects. 17.2. Make a level editor. 17.3. Add rankings. You could even post t