javascript rpg tutorial

Solutions on MaxInterview for javascript rpg tutorial by the best coders in the world

showing results for - "javascript rpg tutorial"
Salim
09 Mar 2019
1  tChar.fight = function(enemy){
2   //assumes enemy is also based on Char
3   hitPerc = (this.hitPerc - enemy.defMod) / 100;
4   if (Math.random() < hitPerc){
5    damage = 0;
6    for (i = 0; i < this.damage; i++){
7     damage += parseInt(Math.random() * 6);
8    } // end for
9    damage -= enemy.armor;
10    enemy.hp -= damage;
11    if (enemy.hp <= 0){
12     alert(enemy.name + " is dead!")
13     document.location.href = ";
14    } // end 'enemy dead' if
15   } // end "hit" if
16  } // end fight