Post

Avatar
Was testing out some code for a turn based tactical game. Mostly an amalgamation of a bunch of guides I've been reading so far. Hit... well it works for what I need. but it does end up being a bunch of lines just to say 'hey, see if they miss'.
Avatar
You post your code in public, I give an unsolicited review! I don't recognise this language, but I'll do my best.
Avatar
I'm not sure if lines 34-37 execute when you expect them to. In most languages there are separate if, if/else and else statements. If yours doesn't, ignore me, but if it does then check line 32, and consider what this block as a whole should do.
Avatar
Line 46 onwards: what happens if comAccuracy exactly equals hitChance? (again, this depends on your language)
Avatar
Whenever you get the feeling, "wow that's a lot of lines to do one thing," check if you are really doing one thing. Could you split this function into smaller functions? My suggested split: Calculate evasion; calculate accuracy; calculate hit chance;
Avatar
Yes, calculate hit chance would be one line. No that doesn't matter. Imagine a world where you change hit chance to e.g. give the player a pity timer if they haven't hit in a while: that would be much more code, but it's already in its own function so you can add all that code in its own place.
Avatar
Again, not sure about language, but I would expect the vars like comDodge to be parameters to this function. If they are currently global, they'll bite you in the ass one day. If they're fields in an object this is less important, but the code might still read better if they become parameters.