Skip to content

Instantly share code, notes, and snippets.

@dangerwizzrd
Last active October 18, 2020 18:17
Show Gist options
  • Save dangerwizzrd/1c39fa224d2b3dd2751de0858ec6b425 to your computer and use it in GitHub Desktop.
Save dangerwizzrd/1c39fa224d2b3dd2751de0858ec6b425 to your computer and use it in GitHub Desktop.
dicerollerV3
let myCharOne = {
name: 'Zolda',
class: 'Wizard',
maxHp: 90,
currentHp: 75,
armorClass: 16,
atkBonus: 7,
magicBonus: 10
}
let myCharTwo = {
name: 'Rollo',
class: 'Sorcerer',
maxHp: 100,
currentHp: 85,
armorClass: 15,
atkBonus: 6,
magicBonus: 11
}
// Version 3
function diceRoll(min, max) {
let mathLogic = Math.floor(Math.random() * (max - min + 1)) + min;
return mathLogic
}
function atkRoll(diceResult) {
return diceResult += myCharOne.atkBonus;
}
function makeAtk(minimum, maximum) {
let theRoll = diceRoll(minimum, maximum);
let addingBonus = atkRoll(theRoll);
let printedStatement = `You rolled a ${theRoll} for a total of ${addingBonus}.`;
if (theRoll == 20) {
return `Critical Hit!! ` + printedStatement + ` ${myCharOne.name}'s attack hit ${myCharTwo.name} for 4 damage!!`;
} else if (theRoll == 1) {
return `Critical Miss!! ` + printedStatement + ` Your sword flew right in the trash!!`;
} else if (addingBonus >= myCharTwo.armorClass) {
return printedStatement + ` ${myCharOne.name}'s attack hit ${myCharTwo.name} for 2 damage!`;
} else {
return printedStatement + ` ${myCharOne.name}'s attack missed!`;
}
}
console.log(makeAtk(1, 20))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment