RPG Quiz Game: A 724-Line RPG Where Correct Answers Deal Damage
Learning Java from a textbook is boring. I wanted a way to practice that felt like playing a game instead of studying for a test.
The RPG Quiz Game is a text-based Java RPG where the combat mechanic is answering programming questions. Correct answers deal damage to the enemy. Wrong answers let the enemy hit you. You explore a 20x20 grid, find shops, level up, and fight a final boss. The whole thing is one Java file.
The Map
The map is a 20x20 grid of characters. The player is P. Empty spaces are dots. Enemies are E. Shops are S. The boss is B. You move with WASD. Step onto an enemy tile and combat starts. Step onto a shop tile and you can buy health or weapon upgrades.
Enemies and shops are placed randomly at startup. 50 enemies and 10 shops fill the map. The placement uses do-while loops that keep picking random coordinates until they find an empty spot. Simple. It works.
Combat As Quiz
When combat starts, a question appears with four shuffled options from the question bank. Pick the right answer and you deal weapon damage to the enemy. Pick the wrong one and the enemy hits you for five health.
The questions live in three 2D arrays for easy, medium, and hard difficulty. Each is a 20x5 structure where the first column is the question text and the remaining four are answers. The correct answer is prefixed with y. The wrong ones are prefixed with x. The prefixes get stripped when displayed and the game checks the prefix to score the response.
You can choose which difficulty pools to use and how many questions to answer before the game ends. Enter -1 for infinite questions.
What I Would Change
The whole thing is one file. 724 lines in a single class. It works, but it is hard to maintain. The question bank, map logic, combat system, and shop all live in the same scope. Splitting them into separate classes would make the project easier to extend.
The boss battle does not use questions. You just choose Attack or Run. Run always fails. It breaks the core mechanic at the most important moment. I would make the boss ask the hardest questions from the pool.
There is no save system. Dying means starting over. The map generation can place enemies on top of each other in rare cases. Input validation is minimal. These are the gaps I notice now that I did not notice when I was focused on making it work.
A terminal with moving characters and a health bar feels like a real game when you are the one who wrote it. It still does.