For my COMP2511 course, I was given a group assignment to make a dungeon crawler type of game in Java. As an “Object-Oriented design focused” course, the backend was to be made in Java, with a front-end written in JavaFX.
The aim of the game was to complete different goals and challenges to finish the level… Killing the enemies, picking up treasure, activating all switches, reaching the exit - or perhaps a combination of all of them.
While arduously waiting for my group partner to do his part, I decided to sit down and make another frontend for the game - a completely text-based, terminal version of the game which could even be played over telnet or SSH!
Challenges
One challenge in getting this application to work was capturing key presses.
Java reads its lines in buffers / strings of characters rather than single characters one at a time - this meant that I was unable to capture each key press as they were being pressed.
Because there was no GUI / Window, I could not use Java AWT’s KeyEvent
.
There were other libraries like JLine - but were massive libraries for such little needed functionality.
Luckily I found a library called RawConsoleInput.java
which worked wonders (not say without any hitches)!