mirror of
https://github.com/MrEidam/bigredbutton.git
synced 2026-04-17 15:43:31 +00:00
Updated RPG
This commit is contained in:
@@ -19,7 +19,6 @@ body{
|
|||||||
|
|
||||||
#controls{
|
#controls{
|
||||||
user-select: none;
|
user-select: none;
|
||||||
cursor: pointer;
|
|
||||||
border: 1px #000 solid;
|
border: 1px #000 solid;
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
}
|
}
|
||||||
@@ -40,4 +39,8 @@ body{
|
|||||||
|
|
||||||
.stat{
|
.stat{
|
||||||
padding-right: 10px;
|
padding-right: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
button{
|
||||||
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
57
js/rpg.js
57
js/rpg.js
@@ -24,49 +24,40 @@ const monsterStats = document.querySelector('#monsterStats');
|
|||||||
const monsterName = document.querySelector('#monsterName');
|
const monsterName = document.querySelector('#monsterName');
|
||||||
const monsterHpText = document.querySelector('#monsterHp');
|
const monsterHpText = document.querySelector('#monsterHp');
|
||||||
|
|
||||||
const monsters = [
|
const monsters = [{
|
||||||
{
|
|
||||||
name: 'Slime',
|
name: 'Slime',
|
||||||
level: 2,
|
level: 2,
|
||||||
hp: 15,
|
hp: 15,
|
||||||
},
|
},{
|
||||||
{
|
|
||||||
name: 'Unicorn',
|
name: 'Unicorn',
|
||||||
level: 8,
|
level: 8,
|
||||||
hp: 70,
|
hp: 70,
|
||||||
},
|
},{
|
||||||
{
|
|
||||||
name: 'Dragon',
|
name: 'Dragon',
|
||||||
level: 25,
|
level: 25,
|
||||||
hp: 500,
|
hp: 500,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const weapons = [
|
const weapons = [{
|
||||||
{
|
|
||||||
name: 'Boxing gloves',
|
name: 'Boxing gloves',
|
||||||
power: 1,
|
power: 1,
|
||||||
},
|
},{
|
||||||
{
|
|
||||||
name: 'Oak Stick',
|
name: 'Oak Stick',
|
||||||
power: 5,
|
power: 5,
|
||||||
},
|
},{
|
||||||
{
|
|
||||||
name: 'Iron Dagger',
|
name: 'Iron Dagger',
|
||||||
power: 25,
|
power: 25,
|
||||||
},
|
},{
|
||||||
{
|
|
||||||
name: 'Nordic Hammer',
|
name: 'Nordic Hammer',
|
||||||
power: 50,
|
power: 50,
|
||||||
},
|
},{
|
||||||
{
|
|
||||||
name: 'Royal Broadsword',
|
name: 'Royal Broadsword',
|
||||||
power: 100,
|
power: 100,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const locations = [
|
const locations = [{
|
||||||
{
|
|
||||||
name: 'Town Square',
|
name: 'Town Square',
|
||||||
'btn text': [
|
'btn text': [
|
||||||
`Go to Store`,
|
`Go to Store`,
|
||||||
@@ -91,7 +82,7 @@ const locations = [
|
|||||||
buyWeapon,
|
buyWeapon,
|
||||||
goTown,
|
goTown,
|
||||||
],
|
],
|
||||||
text: `You've entered the store. You can buy something from Jonathan or go back to Town square. Note that your current weapon is ${weapons[currentWeapon].name}.`,
|
text: `You've entered the store. You can buy something from Jonathan or go back to Town square.`,
|
||||||
},{
|
},{
|
||||||
name: 'Cave',
|
name: 'Cave',
|
||||||
'btn text': [
|
'btn text': [
|
||||||
@@ -130,7 +121,7 @@ const locations = [
|
|||||||
goTown,
|
goTown,
|
||||||
egg,
|
egg,
|
||||||
],
|
],
|
||||||
text: `Exiting the nearby cavern, one ${monsters[fighting].name} lies defeated. Its final cry fades as you gain experience. Among the remnants, you find gold—a reward for your bravery.`,
|
text: `Exiting the nearby cavern, one monster lies defeated. Its final cry fades as you gain experience. Among the remnants, you find gold—a reward for your bravery.`,
|
||||||
},{
|
},{
|
||||||
name: 'Lose',
|
name: 'Lose',
|
||||||
'btn text': [
|
'btn text': [
|
||||||
@@ -143,7 +134,7 @@ const locations = [
|
|||||||
restart,
|
restart,
|
||||||
restart,
|
restart,
|
||||||
],
|
],
|
||||||
text: `Your resolve falters as weariness sets in, and the ground trembles with the arrival of another ${monsters[fighting].name} from the shadows. Despite your valiant efforts in battle, the relentless onslaught proves too much, and you find yourself overpowered. As darkness descends upon your vision, the echoing roar of the ${monsters[fighting].name} serves as a grim reminder of your valiant but ultimately unsuccessful struggle.`,
|
text: `Your resolve falters as weariness sets in, and the ground trembles with the arrival of another monster from the shadows. Despite your valiant efforts in battle, the relentless onslaught proves too much, and you find yourself overpowered. As darkness descends upon your vision, the echoing roar of the that monster serves as a grim reminder of your valiant but ultimately unsuccessful struggle.`,
|
||||||
},{
|
},{
|
||||||
name: 'Win',
|
name: 'Win',
|
||||||
'btn text': [
|
'btn text': [
|
||||||
@@ -199,6 +190,7 @@ function goTown(){
|
|||||||
|
|
||||||
function goStore(){
|
function goStore(){
|
||||||
update(locations[1]);
|
update(locations[1]);
|
||||||
|
text.innerText += ` Remember that your weapon is ${weapons[currentWeapon].name}.`
|
||||||
}
|
}
|
||||||
|
|
||||||
function goCave(){
|
function goCave(){
|
||||||
@@ -211,11 +203,12 @@ function buyHp(){
|
|||||||
gold -= 10;
|
gold -= 10;
|
||||||
hp += 10;
|
hp += 10;
|
||||||
textUp();
|
textUp();
|
||||||
|
text.innerText = `You bought 10 more Health Points.`
|
||||||
}else{
|
}else{
|
||||||
text.innerText = `You need ${10-gold} more Gold to buy more HP.`
|
text.innerText = `You need ${10-gold} more Gold to buy more HP.`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function buyWeapon(){//TODO current weapon in shop entry
|
function buyWeapon(){
|
||||||
if(currentWeapon < weapons.length-1){
|
if(currentWeapon < weapons.length-1){
|
||||||
if(gold>=30){
|
if(gold>=30){
|
||||||
gold -= 30;
|
gold -= 30;
|
||||||
@@ -273,7 +266,7 @@ function attack(){
|
|||||||
if(isMonsterHit()){
|
if(isMonsterHit()){
|
||||||
hp -= getMonsterAttackValue(monsters[fighting].level);
|
hp -= getMonsterAttackValue(monsters[fighting].level);
|
||||||
}else{
|
}else{
|
||||||
text.innerText += ` You missed.`
|
text.innerText += ` ${monsters[fighting].name} missed.`
|
||||||
}
|
}
|
||||||
monsterHp -= weapons[currentWeapon].power + Math.floor(Math.random()*xp) + 1;
|
monsterHp -= weapons[currentWeapon].power + Math.floor(Math.random()*xp) + 1;
|
||||||
textUp();
|
textUp();
|
||||||
@@ -281,7 +274,7 @@ function attack(){
|
|||||||
else if(monsterHp<=0){
|
else if(monsterHp<=0){
|
||||||
fighting === 2 ? winGame() : defeatMonster();
|
fighting === 2 ? winGame() : defeatMonster();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Math.random() <= .1 && inventory.length !== 1){
|
if(Math.random() <= .1 && inventory.length !== 1){
|
||||||
text.innerText += `Your ${inventory.pop()} breaks.`;
|
text.innerText += `Your ${inventory.pop()} breaks.`;
|
||||||
currentWeapon--;
|
currentWeapon--;
|
||||||
@@ -289,15 +282,22 @@ function attack(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getMonsterAttackValue(level){
|
function getMonsterAttackValue(level){
|
||||||
return (level*5) - (Math.floor(Math.random()*xp));
|
return Math.max(1, (level*5) - (Math.floor(Math.random()*xp)));
|
||||||
}
|
}
|
||||||
|
|
||||||
function isMonsterHit(){
|
function isMonsterHit(){
|
||||||
return Math.random()>.2 || hp<20;
|
return Math.random()>.2 || hp<20;
|
||||||
}
|
}
|
||||||
|
|
||||||
function dodge(){ //TODO round up when monster hits (lichá) % sudá misses
|
function dodge(){
|
||||||
text.innerText = `You dodge the attack from the ${monsters[fighting].name}.`
|
if(Math.floor(Math.random()*10)%2){
|
||||||
|
text.innerText = `You dodge the attack from the ${monsters[fighting].name}.`;
|
||||||
|
}else{
|
||||||
|
text.innerText = `You didn't dodge the attack from the ${monsters[fighting].name}.`;
|
||||||
|
hp -= getMonsterAttackValue(monsters[fighting].level);
|
||||||
|
textUp();
|
||||||
|
if(hp<=0) lose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function defeatMonster(){
|
function defeatMonster(){
|
||||||
@@ -368,5 +368,4 @@ function textUp(){
|
|||||||
hpText.innerText = hp;
|
hpText.innerText = hp;
|
||||||
goldText.innerText = gold;
|
goldText.innerText = gold;
|
||||||
monsterHpText.innerText = monsterHp;
|
monsterHpText.innerText = monsterHp;
|
||||||
}
|
}
|
||||||
//TODO 1:12:00 https://www.youtube.com/watch?v=SYx885hX0OY
|
|
||||||
Reference in New Issue
Block a user