Computer Science Canada Shorter Death Handler For Bomberman! |
Author: | Gooie [ Mon Dec 10, 2007 8:15 pm ] | ||
Post subject: | Shorter Death Handler For Bomberman! | ||
Hey, I'm relatively new to Turing and was wondering if their was any simple way to make this piece of code any shorter it seems extremely long and unnecessary. I also don't want a super long unreadable line of an overly complicated if statement.
|
Author: | Ultrahex [ Mon Dec 10, 2007 11:27 pm ] | ||||||
Post subject: | Re: Shorter Death Handler For Bomberman! | ||||||
Yes, there is a much better way visually of writing this code. start by factoring out your: player_gy = bomb_gy (i), and player_gx = bomb_gx (i) (note that two of your conditions are actually the same! im gonna assume you meant for one to be the corresponding missing one)
And there is also other ways to simplify this even more using absolute function and other methods that actually may look nicer, this is just an example of how to deal with big messy if statements. ![]() Also depending on your context, and what you want it to do, their may even be an easier way to simplify based on the problem you are trying to accomplish by these boolean statements. Side Notes:
For Small Conditions:
|
Author: | Clayton [ Tue Dec 11, 2007 8:24 am ] |
Post subject: | RE:Shorter Death Handler For Bomberman! |
Just a small nitpicky thing, but what if you want b was false even if a was false? (Something's happened in your program to make b false, and you want it to stay that way for example) There might be a point where that could be an issue. Just pointing that out |
Author: | Gooie [ Tue Dec 11, 2007 10:10 pm ] | ||||||
Post subject: | Re: Shorter Death Handler For Bomberman! | ||||||
Ultrahex @ December 10th, 11:27 pm wrote: Yes, there is a much better way visually of writing this code.
start by factoring out your: player_gy = bomb_gy (i), and player_gx = bomb_gx (i) (note that two of your conditions are actually the same! im gonna assume you meant for one to be the corresponding missing one)
And there is also other ways to simplify this even more using absolute function and other methods that actually may look nicer, this is just an example of how to deal with big messy if statements. ![]() Also depending on your context, and what you want it to do, their may even be an easier way to simplify based on the problem you are trying to accomplish by these boolean statements. Side Notes:
For Small Conditions:
Nice! Thanks, it worked! |