"안녕하세요, 병사!"
"안녕하세요, 다람쥐 선장입니다!"
"축하합니다. 오늘은 쉬는 날입니다."
"그리고 우리는 우리가 원하는 것은 무엇이든 할 수 있습니까?"
"네, 아미고. 하루 종일 장난감을 가지고 놀 수 있습니다. 예를 들어 Sokoban. 어린 시절부터 가장 좋아하는 게임입니다. 레벨 435를 넘을 수 없습니다. 도와 드릴까요?"
"물론이지, 내가 도와줄게, 내가 보여줄게, 캡틴."
Captain Squirrels는 주머니에서 오래된 게임 보이를 꺼내 단색 버전의 Sokoban을 시작합니다. 그러나 실망이 있습니다. 배터리가 소진되고 Game Boy가 종료됩니다.
조용히 선장은 게임보이를 보고, 아미고를 보고, 다시 게임보이를 본다. 그는 돌아서서 천천히 사무실로 걸어간다.
"대장님! 우리만의 Sokoban 버전을 작성해 봅시다! 1000개의 추가 레벨을 생각하고 멋진 그래픽 인터페이스를 만들겠습니다."
"Amigo, 당신은 나를 놀라게 하는 것을 멈추지 않습니다. IntelliJ IDEA 요원에게 연락하십시오. 그가 당신을 위한 다른 임무가 없고 그의 휴일에 당신을 돕고 싶어한다면 계속 진행하십시오."
20
과제
Java Collections, 레벨 10, 레슨 15
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.
10
과제
Java Collections, 레벨 10, 레슨 15
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
10
과제
Java Collections, 레벨 10, 레슨 15
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
20
과제
Java Collections, 레벨 10, 레슨 15
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
20
과제
Java Collections, 레벨 10, 레슨 15
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
10
과제
Java Collections, 레벨 10, 레슨 15
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
10
과제
Java Collections, 레벨 10, 레슨 15
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
10
과제
Java Collections, 레벨 10, 레슨 15
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
10
과제
Java Collections, 레벨 10, 레슨 15
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
20
과제
Java Collections, 레벨 10, 레슨 15
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.
20
과제
Java Collections, 레벨 10, 레슨 15
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
20
과제
Java Collections, 레벨 10, 레슨 15
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
20
과제
Java Collections, 레벨 10, 레슨 15
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
20
과제
Java Collections, 레벨 10, 레슨 15
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
40
과제
Java Collections, 레벨 10, 레슨 15
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
20
과제
Java Collections, 레벨 10, 레슨 15
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
10
과제
Java Collections, 레벨 10, 레슨 15
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