Skip to content

Commit

Permalink
Added all the visuals to the functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Dorstener committed May 1, 2024
1 parent 504ac14 commit 79892ad
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 5 deletions.
Binary file added images/Dragon Repeller.webp
Binary file not shown.
Binary file added images/cave.webp
Binary file not shown.
Binary file added images/fight.webp
Binary file not shown.
Binary file added images/lose.webp
Binary file not shown.
Binary file added images/monster.webp
Binary file not shown.
Binary file added images/square.webp
Binary file not shown.
Binary file added images/store.webp
Binary file not shown.
Binary file added images/win.webp
Binary file not shown.
Binary file added images/witch.webp
Binary file not shown.
4 changes: 4 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
</head>

<body>
<div class="imageTwo">
<img src="/images/Dragon Repeller.webp" alt="cover picture of Dragon Repeller" class="image">
</div>
<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>
Expand Down
25 changes: 21 additions & 4 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,43 +62,51 @@ const locations = [
"button text": ["Go to store", "Go to cave", "Fight dragon"],
"button functions": [goStore, goCave, fightDragon],
text: "You are in the town square. You see a sign that says \"Store\".",
imagePath: "/images/square.webp",
},
{
name: "store",
"button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"],
"button functions": [buyHealth, buyWeapon, goTown],
text: "You enter the store.",
imagePath: "/images/store.webp",
},
{
name: "cave",
"button text": ["Fight slime", "Fight fanged beast", "Go to town square"],
"button functions": [fightSlime, fightBeast, goTown],
text: "You enter the cave. You see some monsters.",
imagePath: "/images/cave.webp",
}, {
name: "fight",
"button text": ["Attack", "Dodge", "Run"],
"button functions": [attack, dodge, goTown],
text: "You are fighting a monster.",
imagePath: "/images/fight.webp",
}, {
name: "kill monster",
"button text": ["Go to town square", "Go to town square", "Go to town square"],
"button functions": [goTown, goTown, easterEgg],
text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.',
imagePath: "/images/monster.webp",
}, {
name: "lose",
"button text": ["REPLAY?", "REPLAY?", "REPLAY?"],
"button functions": [restart, restart, restart],
text: "You die. &#x2620;",
imagePath: "/images/lose.webp",
}, {
name: "win",
"button text": ["REPLAY?", "REPLAY?", "REPLAY?"],
"button functions": [restart, restart, restart],
text: "You defeat the dragon! YOU WIN THE GAME! &#x1F389;",
imagePath: "/images/win.webp",
}, {
name: "easter egg",
"button text": ["2", "8", "Go to town square?"],
"button functions": [pickTwo, pickEight, goTown],
text: "You find a secret game. Pick a number above. Two numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!",
imagePath: "/images/witch.webp",
}
];

Expand Down Expand Up @@ -128,8 +136,17 @@ function update(location) {
button2.onclick = location["button functions"][1];
button3.onclick = location["button functions"][2];
text.innerHTML = location.text;

const imageElement = document.querySelector('.image');
if (imageElement) {
imageElement.src = location.imagePath;
} else {
console.error("Image not found");
}
}



function goTown() {
update(locations[0]);
}
Expand Down Expand Up @@ -243,7 +260,7 @@ function attack() {
} else {
text.innerText += " You miss.";
};

healthText.innerText = actualHealth;
monsterHealthText.innerText = monsterHealth;
if (actualHealth <= 0) {
Expand All @@ -262,8 +279,8 @@ function attack() {
actualWeapon--;
}

localStorage.setItem ("Current Weapon", actualWeapon);
localStorage.setItem ("Health", actualHealth.toString());
localStorage.setItem("Current Weapon", actualWeapon);
localStorage.setItem("Health", actualHealth.toString());
localStorage.setItem("Inventory", JSON.stringify(actualInventory));
}

Expand All @@ -284,7 +301,7 @@ function dodge() {
function defeatMonster() {
let actualGold = parseInt(localStorage.getItem("Gold"));
actualGold += Math.floor(monsters[fighting].level * 6.7);
let actualXp = parseInt(localStorage.getItem ("XP"));
let actualXp = parseInt(localStorage.getItem("XP"));
actualXp += monsters[fighting].level;
goldText.innerText = actualGold;
xpText.innerText = actualXp;
Expand Down
16 changes: 15 additions & 1 deletion styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ body {
max-height: 400px;
background-color: #ffffff ;
color:#ffffff;
margin-top: 30px;
/*margin-top: 30px;*/
margin-bottom: 0px;
margin-left: auto;
margin-right: auto;
Expand Down Expand Up @@ -44,4 +44,18 @@ button {
background-color: #feac32 ;
background-image: linear-gradient(#fecc4c, #ffac33);
border: 3px solid #feac32;
}

.image {
width: 520px;
height: 400px;
margin-top: 30px;
margin-bottom: 0px;
}

.imageTwo {
max-width: 520px;
max-height: 434px;
margin-left: auto;
margin-right: auto;
}

0 comments on commit 79892ad

Please sign in to comment.