Skip to main content

Role Playing Game

Role Playing Game Project Preview - Main Page Role Playing Game Project Preview - You enter the store Role Playing Game Project Preview - You enter the cave. You see some monsters Role Playing Game Project Preview - You defeat the dragon, you win the game Role Playing Game Project Preview - Lose game Role Playing Game Project Preview - You find a secret game Role Playing Game Project Preview - You win

The Project

Dragon Repeller RPG developed by integrating JavaScript with HTML and CSS, featuring combat system, inventory management, multiple locations and complete game mechanics. The first project that combines logic, interface and user interaction.

Source Code

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="./styles.css">
<title>RPG - Dragon Repeller</title>
</head>
<body>
<div id="game">
<div id="stats">
<span class="stat">XP: <strong><span id="xpText">0</span></strong></span>
<span class="stat">Health: <strong><span id="healthText">100</span></strong></span>
<span class="stat">Gold: <strong><span id="goldText">50</span></strong></span>
</div>
<div id="controls">
<button id="button1">Go to store</button>
<button id="button2">Go to cave</button>
<button id="button3">Fight dragon</button>
</div>
<div id="monsterStats">
<span class="stat">Monster Name: <strong><span id="monsterName"></span></strong></span>
<span class="stat">Health: <strong><span id="monsterHealth"></span></strong></span>
</div>
<div id="text">
Welcome to Dragon Repeller. You must defeat the dragon that is preventing people from leaving the town. You are in the town square. Where do you want to go? Use the buttons above.
</div>
</div>
<script src="./script.js"></script>
</body>
</html>

The Most Challenging Experience

It was a very long and most tiring project done so far. It was difficult to enter the logic of JavaScript and I still don't feel comfortable.

Halfway through the project I took a complete day off where I only read a few pages of Refactoring UI, I needed it to recharge.

The Moments of Joy

As soon as I started the project I began with great energy writing HTML and CSS, with the same energy also the assignment of HTML elements to JavaScript, like buttons.

I admit that functions and if/else loops also entertained me (even if less than the previously mentioned areas), maybe because by repeating them continuously throughout the project I started to feel confident - and this is exactly what brings me joy in doing it.

The Achilles' Heel

For loops are my Achilles' heel. Better than the last project, but I can't reach the level of abstraction it requires.

An Encouraging Discovery

I researched and discovered that for a designer's mind, it's normal to find for loops more difficult, particularly compared to if/else statements. I'm sure that throughout the course, with all the projects there will be, I will learn to master them completely.

What I Learned

DOM Manipulation:

  • document.querySelector() to select HTML elements

  • onclick events to handle user interactions

  • innerText and innerHTML to dynamically update content

  • style.display to show/hide elements

Game Logic:

  • State management with global variables

  • Object arrays for weapons, monsters, locations

  • Dynamic UI updates based on game state

  • Conditional game flow with multiple locations

Advanced JavaScript:

  • Math.random() for random elements

  • Array methods (push, pop, shift, includes)

  • Complex conditionals for game mechanics

  • Function composition for interconnected systems

HTML/CSS/JS Integration:

  • Responsive button behavior with JavaScript

  • Dynamic content updates maintaining CSS styling

  • Event handling for user interactions

  • Real-time stats display synchronized with game state

Observed Development Patterns

Game Architecture:

  • Locations system - each location has button texts and functions

  • Update pattern - central function that updates entire UI

  • State persistence - global variables to maintain progress

Combat System:

  • Turn-based logic with attack/dodge/run options

  • Damage calculation with mathematical formulas

  • Random elements for gameplay variety

Reflection

I'm happy with the confidence I've developed with functions and if/else loops - it gives me faith that loops will also become natural with practice.


Next Project: Learn Basic Debugging by Building a Random Background Color Changer