Roguelike AoC – part 25

In the twenty-fifth lesson of a roguelike game tutorial no actual logic-changes were introduced. Only the cleanup happened – which I’ve done also in my code.

We’re not in Kansas anymore – split of main header file

The author decided to split humongous rogue.h file and make a cleanup among the functions and declarations of data structures. Therefore, I had to do the same 😉 When it came to splitting rogue.h it was not a big deal. There were some reruns needed to actually have all the proper include directives in place, but that was no biggie. How it was done can be seen in the source code – there’s no way I’m describing all the changes here.

What should I return from method?

That was something that was bothering me for some time. I understand the UNIX-like approach to the return values – if there’s zero being returned that means everything went fine. If the value is different – then an error occurred. The convention is obvious and widely used. However, I do not see a reason for many methods that are somehow ‘predefined’ in their behaviour (eg. setup of rooms) should return an integer? It would be a heavy screw-up if this method returned an error. What is more – we do not check this value in any way. So I’ve gone through all the functions that actually return int and changed them to void if that was acceptable. Below is the whole list of functions that were changed.

  • combat
  • moveMonsters
  • killMonster
  • playerDraw
  • placePlayerInTheLevel
  • playerMove
  • drawRoom
  • screenSetup
  • printGameHub
  • pathfindingSeek
  • pathfindingRandom

Uff, that was the hell of refactoring. Of course with heavy usage of CLion it wasn’t that hard but still – a lot of recompilation going on. However, right now the code is cleaner that it was before.


Here is the direct link to the GitHub repo.

You Might Also Like

Leave a Reply

Back to top