I work with many language, and am expanding my experience with JS (not jquery). While this works with many languanges I use, What I thought was going to be an easy program, has me stumped at the Array/Object issue. And I could be attacking it from the wrong direction.
In short this is a simple game(I am learning about objects and arrays in JS, and thought this would be a good challenge). Comprises of 15 mobs, each mob attacks 10x in waves, and each wave has up to 5 different criteria for winning that wave. Once the wave is complete, it moves to the next mob, and repeat.
With other languages and even PHP, you can do something similar to the pseudo code below:
aMob = record {
id: integer,
name: string
hp: integer
etc....
}
mob[15]: aMob
now I have an array of 15 aMobs
so you can use mobCnt = 0 and get mob[mobCnt].name
And I can do this is in JS. Pretty simple array, but this is where it gets complicated (for me)
I watched and read several tutorial and learned about Objects. That seemed to be the right way to go, but I could create the object (boiler plate?) But then I could not create the multidimensional array that each mob would be associated with 10 waves, and each of those waves had 5 items to meet. 3D array?
this snipped below sorta works. But very kludgy coding. And the problem arises when I click the attack button, the mobhp will not decrease, so I put that var as global. But after change the code, it just kept getting bigger. So this has to be junked. this was the only code that I got so at least do something, but I feel the object/array method would be better.
function setBattleRoundNFO(currMobCnt, currWaveCnt ) {
switch(currMobCnt) {
case 0: mobName = "Rodents";
// mob = 100;
switch(currWaveCnt){
case 0: weaponId = 1; armorId = 0; powerMoveId = 3; break; // weapon, armor and powermove skill
case 1: weaponId = 4; armorId = 5; powerMoveId = 6; break;
}
break;
case 1: mobName = "Wolf Pack";
mobHp *= 1.15;
switch(currWaveCnt){
case 0: weaponId = 7; armorId = 8; powerMoveId = 9; break; // weapon, armor and powermove skill
case 1: weaponId = 10; armorId = 11; powerMoveId = 12; break;
}
break;
}
}
Ideally, what I want to happen, is it displays (by tracking variables) show
mob[1].wave[1].hp,armor,weapon,level... etc..
after this battle is won, then move to the next wave
mob[1].wave[2].hp,armor,weapon,level .. etc..
I tried this on pascal, qb64 and php, works fine, but I want it in JS, And the array part is stumping me.
thanks