best way to make a class out of this?

closed account (Dy7SLyTq)
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 const char*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.

- SDL 1.x? ewwwww
Last edited on
closed account (Dy7SLyTq)
as i said its written horribly. my concept is a window that has the ability to load an image, write text to the window, and make windows inside of it

edit: and can you point me to a current release tutorial then?
Last edited on
my concept is a window that has the ability to load an image, write text to the window, and make windows inside of it


So then it sounds like a Window would be a decent "thing", and therefore a class.

and can you point me to a current release tutorial then?


http://lazyfoo.net/tutorials/SDL/index.php

I haven't actually read them... but given how lazyfoo seems to be so popular...
closed account (Dy7SLyTq)
its based off lazy foos tutorial
- SDL 1.x? ewwwww
\

by that logic lazy foo teaches 1.0.

and
generating SDL Windows and minimizing the number of non method functions?
so i actually asked for the "thing" in the first place
by that logic lazy foo teaches 1.0.


? lazy foo also teaches 2.0. I just linked to it.

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.
closed account (Dy7SLyTq)
? lazy foo also teaches 2.0. I just linked to it.

sorry i thought it was this link: http://lazyfoo.net/SDL_tutorials/

and k. i think i have it figured out
Topic archived. No new replies allowed.