CodeSOD: Enumerating Your Plants

This post was originally published on this site

The Daily WTF

Usually, we don’t pick on game code, as it’s frequently bad because of the time constraints under which it’s developed and because the concerns are more around “making a fun, performant game,” and not “writing good reusable code”.

But there are some egregious exceptions, like what happened to Patrick. He was handed some C# game code, and told, “Good luck!”

This particular block lived in a file called banana.cs. Does this game have anything to do with bananas? It does not! It has to do with zombies. No, it is not Plants vs. Zombies, though given the botanical flair in this code, perhaps the author was a fan?

One module of the game uses integers as the ID values of enemies. One module uses strings. No one uses enums. So when you want to convert the IDs to the appropriate type, you need to call enemyIdNumToName, which I want to

To read the full article click on the 'post' link at the top.