[Boston.pm] Rock-paper-scissors-lizard-Spock
email-2Ro/Dj86MvDSUeElwK9/[email protected] Sat, 07 Dec 2024 09:27:33 -0600
| Newsgroups | gmane.comp.lang.perl.perl-mongers.boston |
|---|---|
| Message-ID | <[email protected]> |
Say i have some objects moving around on a map. Rock, paper, scissors. The method to handling collisions() is sort of connected to the classes, but doesnt really belong in any single one of them. How would you code this in perl? Keep in mind that later on, someone wants to add some new classes, lizard and spock. I was thinking making a base class of "things" And have some sort of resolver in there? Multiple collision() functions with signatures for each type of object that is colliding? But can perl even do that? Perl would need a way to resolve which sub to call based On types passed in. I used to do this in ada/vhdl but never seen it in perl. A hash of hashes where the indexes are the types, put that in the "things" base class, and have a "collision()" sub that crawls through the hadh? New object classes populate their types into the hash? I feel like this is probably a CS101 type concept that they didnt teach us electrical engineers...