You will simply initiate the game in main() by creating a Game object. There should also be a Game class to keep a collection of Players and handle the gameplay. For instance, Player can become a class instead of a struct so that it can be kept private. This would look and function better with more classes, especially since it's a game. I would normally recommend C++-style static_cast(object) instead of your C-style (type)object casting, but in your case I think it would just reduce readability even more without giving much benefit.Īnd finally, not directly code related: It's either Pythagoras' theorem, or the Pythagorean theorem. I'm sure you agree player_one_base_offset is much more readable and understandable than 0xDF73C. Players = Player((int**) ((UINT) GetModuleHandleW(0) + player_one_base_offset)) For example: const std::size_t player_one_base_offset = 0xDF73C Use symbolic, rather than literal, constants. You risk forgetting to dereference a pointer if you're lucky you get undefined behavior from violating the strict aliasing rule if you're not. It is error prone, and some of the potential errors can be really hard to find. I'm not sure if all your pointer fiddling is really necessary. Using ( and ) instead compiles, but means something entirely different! (It will default-construct 0x34 = 52 objects.) Int* getClosestPointer(int** basePointer, int offsets, int levels) in the last example. * but it is more prone to undefined behaviour and I am more likely to get away with the first method. * Another more elegant looking method is to use int as if it were int*, int**, etc * I am using int* as if it were the same thing as int**, int***, etc. Do you see any ways I can improve readability, maintainability and performance, and make it more object-oriented? /* I am actually quite new to C++, although I have previously programmed in Java.
0 Comments
Leave a Reply. |