After a breaking through the difficulties related to my rendering system and Javaswing, Escape has finally come to its completion! Escape from the dungeon! Although it seems complicated, the codes are not ineffable. I had a blueprint inside my head and separated the structure into two main parts, a render system and a sensor.
A render system controls frames of the game animation. Each animation you see on the monitor is nothing more than a set of fast-changing images. And a render system is what determines the arrangement of those images. According to the received data, a render system draws the image on the screen and waits for a command that tells it to draw another one. This action occurs up to 200 times per second (depends on your computer capability). With the high refreshing speed and the proper installment of the render system, the game runs fluently and flawlessly.
A sensor receives keyboard or mouse commands and performs corresponding actions. It is thus often named “Class actionListener” in Java. For instance, the character moves forward in game when the player presses down the “d” key. It is due to the instant reaction of the sensor, which sends the signal to the render system to display the “moving forward” animation. Fortunately, the coding for the sensor is relatively simple because it can be achieved with one class only, instead of seven (for the render system).
Anyways, the game is worth a shot: “D” for moving forward, “A” for moving backward, space bar for jumping. The download hyperlink is provided below (it requires Java 1.8 or higher).