so i am making a game in sdl, and while it works, i feel like i wrote it horribly. its based off lazy foos tutorial, although a lot of it is my own code. could someone show me the skeleton of a class for generating SDL Windows and minimizing the number of non method functions? i have racked my brain but its really fried right now. thanks in advance
http://pastebin.com/pcDwUYPw
You don't make a class out of a chunk of code. You make a class out of a concept.
A class represents a 'thing'. Its member functions are to manipulate that thing. std::string is a good example.. the class itself represents something very clear and meaningful.
So the question becomes... what are the "things" in your program?
EDIT
misc side notes:
- generally you want classes to be nouns (they're "things") and functions to be verbs (they "do stuff"). "Menu" is not a verb and therefore is a poor name for a function.
- The entire GetOption function could be replaced with a simple lookup table. Also, string literals are constchar*s and not char*s.
- I see you are loading button.jpg multiple times. Having the same image stored in memory more than once is a waste. Rather than have all your different buttons load their own graphic, have them all access the same graphic.
so i actually asked for the "thing" in the first place
Guess so.
So it looks like you'd want to make a Window class or something similar. Give it a draw() function, a move() function, and whatever else you'd want your windows to have.
Remember that the goal is to have the class self-contained so that it takes care of itself. You should make it as hard to "misuse" the class as possible.