โ˜• My First Java Game ยท Episode 7 of 7 ยท See All Episodes
๐Ÿ‘‘ 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
โญ
0 XP
Level 1
๐Ÿ”ฅ0
Your Progress 0 / 6 steps
1
๐Ÿ’ฌ
The Village Elder (NPC)
A talkable character with multi-line dialogue
Active
๐ŸŽฏ
Goal for this step

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!";
    }
โŒจ๏ธ
Code Challenge
+20 XP
Trigger the enrage exactly once, at half health:
GamePanel.java
if (foe.name.equals("Dragon") && !
        && foe.hp <= foe.maxHp / ) {
    enraged = ;
    foe.attack += 4;
}
๐Ÿ’ก 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.
GamePanel.java (paintComponent)
    if (state.equals("VICTORY")) {
        g.setColor(new Color(15, 10, 25));
        g.fillRect(0, 0, 700, 560);
        g.setColor(new Color(255, 209, 102));
        g.setFont(new Font("Arial", Font.BOLD, 40));
        g.drawString("THE REALM IS SAVED!", 110, 200);
        g.setColor(Color.WHITE);
        g.setFont(new Font("Arial", Font.PLAIN, 20));
        g.drawString(hero.getName() + ", Level " + hero.getLevel(), 110, 260);
        g.drawString("Goblins slain: " + goblinsSlain + " ยท Dragon: DEFEATED", 110, 290);
        g.drawString("A game by YOU", 110, 350);
        return;
    }
โœ๏ธ
Fill in the Blanks
+15 XP
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. ๐Ÿ†
0
Total XP
1
Level
0
Best Streak
0%
Accuracy
โญ View My Progress & Certificates

This workshop was free and took many hours to build. If it helped you learn something new, consider supporting the project.

☕ Support on Ko-fi