๐ Episode 7 ยท Big Project ยท RPG Part 3 of 3 ยท Series Finale
RPG Quest Part 3: The Dragon
The finale. Add a talking NPC with a real quest, a locked dragon gate, a multi-phase boss battle, and the victory ending your hero deserves. Everything from all seven episodes comes together here.
๐ถ Ages 11+โฑ๏ธ ~2 Hoursโ Javaโ Free
๐ฌ NPC dialogue๐ Quest tracking๐๏ธ Locked gates๐ Boss phases๐ Endings๐ง Bringing it together
Add an NPC on the map you can talk to, with dialogue that advances.
1New tile type 4 = NPC. Place the Elder near the start and draw them purple.
2Talking: pressing E while standing NEXT to (not on) the NPC sets state = "DIALOGUE".
3"Next to" means the row differs by 1 OR the column differs by 1: Math.abs(heroRow-npcRow) + Math.abs(heroCol-npcCol) == 1, that sum is called Manhattan distance.
4Dialogue is a String[] lines plus an index; E advances a line; after the last line, back to EXPLORE.
5Draw a text box along the bottom with the current line, classic RPG style.
GamePanel.java
int npcRow = 2, npcCol = 3;
String[] dialogue = {
"Elder: Ah, " + "Aria" + "... the Dragon stirs again.",
"Elder: Its gate only opens to the DRAGON KEY.",
"Elder: Three goblins guard its pieces. Slay them.",
"Elder: Return victorious, and the realm is saved!"
};
int dialogueLine = 0;
boolean nextToNpc() {
return Math.abs(heroRow - npcRow)
+ Math.abs(heroCol - npcCol) == 1;
}
// in keyPressed (EXPLORE):
if (e.getKeyChar() == 'e' && nextToNpc()) {
state = "DIALOGUE";
dialogueLine = 0;
}
// in keyPressed (DIALOGUE):
if (e.getKeyChar() == 'e') {
dialogueLine++;
if (dialogueLine >= dialogue.length) state = "EXPLORE";
}
โ๏ธ
Fill in the Blanks
+15 XP
The distance check |ฮrow| + |ฮcol| == 1 is called distance. Dialogue advances with the key until the line index reaches dialogue..
๐ง
Knowledge Check
+15 XP
Why talk to an NPC you are NEXT TO rather than standing on?
AStanding on people is rude (and looks broken), the NPC tile stays solid like a wall
BJava cannot detect same-tile overlap
CIt saves a tile type
2
๐
The Quest System
Track goblin kills; the Elder reacts to your progress
Locked
๐ฏ
Goal for this step
Turn the Elderโs words into a real, trackable quest with a HUD counter.
1Quest state is small: boolean questActive; int goblinsSlain;, big systems, small variables.
2Finishing the Elderโs dialogue the first time sets questActive = true.
3In battleAction, when a defeated foeโs name equals "Goblin" and the quest is active: goblinsSlain++.
4HUD shows ๐ก Goblins: 2/3 while the quest runs.
5Make the Elderโs dialogue CHANGE with progress, quest given, quest in progress, quest done. Three small String arrays and a pick.
GamePanel.java
boolean questActive = false;
int goblinsSlain = 0;
// when a monster dies in battleAction:
if (!foe.isAlive()) {
hero.gainXp(foe.xpReward);
hero.addGold(foe.goldReward);
if (questActive && foe.name.equals("Goblin"))
goblinsSlain++;
state = "EXPLORE";
}
// choosing what the Elder says:
String[] currentDialogue() {
if (!questActive) return dialogue; // gives quest
if (goblinsSlain < 3) return new String[]{
"Elder: " + goblinsSlain + " of 3 goblins slain. Fight on!" };
return new String[]{
"Elder: Incredible! Take the DRAGON KEY.",
"Elder: The gate in the north-east awaits. Good luck, hero." };
}
โจ๏ธ
Code Challenge
+20 XP
Count quest kills only when they should count:
GamePanel.java
if ( && foe.name.equals())
goblinsSlain;
๐ก Hint: Two conditions: the quest must be running, and the dead monster must be the right species. Then add one.
๐ง
Knowledge Check
+15 XP
The Elderโs dialogue changes based on quest progress. Why does that matter?
AIt uses less memory than one long speech
BThe world reacts to the playerโs actions, that reactivity is what makes RPGs feel alive
CNPCs must have exactly three speeches
3
๐๏ธ
The Dragon Key & Gate
A locked tile that consumes the key item to open
Locked
๐ฏ
Goal for this step
Gate the boss behind the quest reward, classic lock-and-key design.
1When the Elderโs "quest done" dialogue finishes, grant the key once: hero.pickUp(new Item("Dragon Key","key",0)), guard it with a boolean so it cannot be granted twice!
2New tile type 5 = the Gate. Place it walling off a boss chamber in the north-east.
3In walkable(): tile 5 is walkable ONLY if the hero carries the key. Give Hero a hasItem(String) helper.
4Stepping through consumes the key and swings the gate: set the tile to 0 and log "The gate grinds openโฆ".
5Lock-and-key is the oldest design pattern in games, you have now built it from scratch.
Hero.java + GamePanel.java
// Hero:
public boolean hasItem(String itemName) {
for (Item it : inventory)
if (it.name.equals(itemName)) return true;
return false;
}
// GamePanel.walkable():
if (map[r][c] == 5)
return hero.hasItem("Dragon Key");
// after moving onto the gate tile:
if (map[heroRow][heroCol] == 5) {
hero.useItem("Dragon Key"); // consumed!
map[heroRow][heroCol] = 0;
}
โ๏ธ
Fill in the Blanks
+15 XP
Tile type is the gate. It is only walkable when hero.("Dragon Key") returns true, and stepping through s the key so it is consumed.
๐ง
Knowledge Check
+15 XP
What stops the player reaching the Dragon at level 1 and getting flattened?
AThe Dragon is friendly at first
BThe gate needs the key, the key needs 3 goblin kills, the quest chain forces you to level up first
CThe map is too big
4
๐
The Dragon: A Boss With Phases
A two-phase boss that changes tactics at half health
Locked
๐ฏ
Goal for this step
Build a boss fight that feels different from every normal battle.
1The Dragon is a Monster with big numbers: 80 HP, 9 attack, 100 XP, 150 gold.
2New tile type 6 inside the chamber triggers the fight directly (no random roll), bosses are placed, not random.
3Phase 2 at half health: attack +4 and the log roars "The Dragon is ENRAGED!", draw its HP bar orange.
4Enrage exactly once: flip a boolean when hp โค maxHp/2 the first time.
5Losing to the Dragon respawns you OUTSIDE the chamber with the gate closed but quest complete, retry without redoing everything.
GamePanel.java
boolean enraged = false;
// stepping on tile 6:
if (map[heroRow][heroCol] == 6) {
foe = new Monster("Dragon", 80, 9, 100, 150);
enraged = false;
state = "BATTLE";
}
// in battleAction, after damaging the boss:
if (foe.name.equals("Dragon") && !enraged
&& foe.hp <= foe.maxHp / 2) {
enraged = true;
foe.attack += 4;
battleLog = "The Dragon is ENRAGED!";
}
๐ก Hint: The boolean guard stops it re-triggering every frame; half health is maxHp divided by two; then latch the flag.
๐ง
Knowledge Check
+15 XP
Why do bosses change behaviour mid-fight?
ATo fix bugs in phase one
BA long fight with one pattern gets boring, phases force the player to adapt and create a story arc
CJava switches require it
5
๐
The Ending
Victory state, credits and the heroโs final stats
Locked
๐ฏ
Goal for this step
Defeating the Dragon triggers a proper ending screen worthy of the journey.
1When the defeated foe is the Dragon: state = "VICTORY" instead of EXPLORE.
2The VICTORY screen is your credits: golden "THE REALM IS SAVED!", the heroโs final level, gold, goblins slain, andโฆ your name as the developer. You earned that line.
3Let the ending breathe: accept R only after a 2-second delay (a small frame counter).
4Add a play-again path that resets the world, or leave the hero basking forever. Your call, developer.
Beating the Dragon sets state to rather than EXPLORE. The ending screen shows the heroโs final and, most importantly, credits as the developer.
๐ง
Knowledge Check
+15 XP
Why delay the restart key on the ending screen?
AJava needs time to garbage-collect
BSo players cannot accidentally skip the ending they spent seven episodes earning
CTimers cannot stop instantly
6
๐ง
Series Wrap: What You Actually Learned
Review the architecture and where to go next
Locked
๐ฏ
Goal for this step
Step back and see the professional patterns hiding inside your seven games.
1Look at what you used: game loop (every episode), state machines (Pong, RPG), encapsulation (Hero), factories (Monster.create), tile maps (RPG), ArrayLists + iterators (Space Shooter), lock-and-key design (the gate).
2Those are not "beginner tricks", they are the same patterns inside Minecraft (Java!), Stardew Valley and Undertale.
3Stretch goals if you want more: save/load with a file, sound effects with javax.sound, sprites with ImageIO instead of rectangles, or a second dungeon map.
4Or go bigger: this series used pure Java so you learned the real thing, engines like libGDX will now feel easy.
5Finish the quiz below to complete the entire Java series. GG, developer. ๐
๐ก
The best next project is one you invent. Pick a small idea you love, and you now have every tool to build it.
โ๏ธ
Fill in the Blanks
+15 XP
The Monster.create method is an example of the pattern, the Heroโs private fields demonstrate , and MENU/PLAYING/GAME_OVER is a state .
๐ง
Knowledge Check
+15 XP
Seven games later, what is the single most important habit you practised in every episode?
ATyping fast
BBuild one small piece, run it, test it, THEN add the next piece
CUsing as many classes as possible
๐๐๐ฎโจ๐
Workshop Complete!
Seven episodes. One complete RPG with dialogue, quests and a dragon. You are not learning Java any more, you are a Java game developer. Take a bow. ๐