Damn NaturalViolence. And here I thought you were analyzing and writing up a detailed analysis of yours of what he did wrong and how he could do it better.
This piece of code for example, makes no sense.
Code:
unsigned short playing = 1; //removed other variables for readability
bool game_playing(int playing)
{
if (playing)
return true;
else if (!playing)
return false;
return true;
}
First, you have declared playing as an unsigned short. Better practice is it to make it a bool.
Then you have the function from above which accepts an integer as a parameter which you then check locally if it's true or false.
If you do it this way, you could render the playing variable above useless, as you might as well pass a 0 or 1 to it.
Don't forget about the different datatypes. You are currently passing a short to the function.
You're also checking your parameter redundantly. If you're making checks, you only have to check if a variable is true, otherwise return false.
For better practice, which you'll definitely want when you're working with objects and classes, is to have getters and setters.
Getters to receive the value of the variable and setters to set a value to it.
So something like this:
Code:
bool isPlaying = true;
bool isPlaying() {
if (isPlaying) //if isPlaying = true
return true; //return true and exit function
return false; //this statement only gets reached when isPlaying is false
}
//note that the piece below is for classes
void setPlaying(bool isPlaying) {
this->isPlaying = isPlaying;
}
Also, if you declare variables, you should declare them individually and name the properly. It makes it easier to follow.
Now master this and enter the beauty of Object Oriented Programming.