Good evening folks! Or morning…or afternoon or whenever you are reading this! So me and my amateur coding friend have been developing a game based on an old tabletop game I had made using 6 sided dice. After what seems like months, my amateur coding pal learned how to program damage numbers that mimic 6 sided dice finally! Seems sad now, but it felt like an accomplishment when it looks like an alien language.
So our code reads something like… if you get variable one you do 2 damage.. variable 2 you do 3 and the rest are zero. The zeros simulate misses, and it works fine functionally, but it does not look very clean when a zero pops up. Now it may seem like a stupid question, but is there a Java-ey way to turn those zeros into actual misses?
Example of our coding.
<damage formula>
value = a.atk
var roll = Math.floor((Math.random() * 6) + 1)
var hit = 0
var dodge = Math.floor((Math.random() * 4) + 1)
a.addState(20)
if (roll === 2){
hit = 4;
}
if (roll === 3){
hit = 3;
}
else if (roll === 4) {
hit = 4;
}
else if (roll === 5){
hit = 5;
}
else {
hit = 0;
}
if(b.isStateAffected(115)){
if(dodge ===1){
value = 0;
}
else{
if (a.isStateAffected(34)){
a.removeState(34)
value = 6 + (a.atk -1) + (b.mdf - 1) - (b.def -1);
}
else if( hit > 0){
value = hit + (a.atk -1) + (b.mdf -1) - (b.def - 1);
}
else
{
value = 0;
}
}
}
else{
if (a.isStateAffected(34)){
a.removeState(34)
value = 6 + (a.atk -1) + (b.mdf - 1) - (b.def -1);
}
else if( hit > 0){
value = hit + (a.atk -1) + (b.mdf -1) - (b.def - 1);
}
else
{
value = 0;
}
}
</damage formula>
So our code reads something like… if you get variable one you do 2 damage.. variable 2 you do 3 and the rest are zero. The zeros simulate misses, and it works fine functionally, but it does not look very clean when a zero pops up. Now it may seem like a stupid question, but is there a Java-ey way to turn those zeros into actual misses?
Example of our coding.
<damage formula>
value = a.atk
var roll = Math.floor((Math.random() * 6) + 1)
var hit = 0
var dodge = Math.floor((Math.random() * 4) + 1)
a.addState(20)
if (roll === 2){
hit = 4;
}
if (roll === 3){
hit = 3;
}
else if (roll === 4) {
hit = 4;
}
else if (roll === 5){
hit = 5;
}
else {
hit = 0;
}
if(b.isStateAffected(115)){
if(dodge ===1){
value = 0;
}
else{
if (a.isStateAffected(34)){
a.removeState(34)
value = 6 + (a.atk -1) + (b.mdf - 1) - (b.def -1);
}
else if( hit > 0){
value = hit + (a.atk -1) + (b.mdf -1) - (b.def - 1);
}
else
{
value = 0;
}
}
}
else{
if (a.isStateAffected(34)){
a.removeState(34)
value = 6 + (a.atk -1) + (b.mdf - 1) - (b.def -1);
}
else if( hit > 0){
value = hit + (a.atk -1) + (b.mdf -1) - (b.def - 1);
}
else
{
value = 0;
}
}
</damage formula>