Guys, I already made my very primitive chat server and it's working perfectly. The problem is the code, which is quite ugly.
For example, I don't like the way I declare the booleans for the keys.
bool aKey, bKey, cKey, dKey, eKey,
fKey, gKey, hKey, iKey, jKey,
kKey, lKey, mKey, nKey, oKey,
pKey, qKey, rKey, sKey, tKey,
uKey, vKey, wKey, xKey, yKey,
zKey, spaceKey, enterKey, escapeKey, f1Key;
I don't like this too. But I guess there's no other way here.
if( event.key.keysym.sym == SDLK_a )
{
aKey = true;
}
if( event.key.keysym.sym == SDLK_b )
{
bKey = true;
}
if( event.key.keysym.sym == SDLK_c )
{
cKey = true;
}
if( event.key.keysym.sym == SDLK_d )
{
dKey = true;
}
if( event.key.keysym.sym == SDLK_e )
{
eKey = true;
}
if( event.key.keysym.sym == SDLK_f )
{
fKey = true;
}
if( event.key.keysym.sym == SDLK_g )
{
gKey = true;
}
if( event.key.keysym.sym == SDLK_h )
{
hKey = true;
}
if( event.key.keysym.sym == SDLK_i )
{
iKey = true;
}
if( event.key.keysym.sym == SDLK_j )
{
jKey = true;
}
//And so on.
And the biggest problem is this:
void App::resetAllKeys()
{
aKey = bKey = cKey = dKey = eKey =
fKey = gKey = hKey = iKey = jKey =
kKey = lKey = mKey = nKey = oKey =
pKey = qKey = rKey = sKey = tKey =
uKey = vKey = wKey = xKey = yKey =
zKey = spaceKey = enterKey = escapeKey = f1Key = false;
}
Every time I add a new key as a boolean, I need to remember to add it to this function, too, because if I forget to reset it, there are really strange bugs happening. I'm sure there is a way to beautify some of this. Any ideas?