programming question

getKey() is NOT a blocking function. It will NOT wait for a key to be pressed, so you have a value for level. There is a different method that will waitForKey().

    level = (key - 48);

Not obvious.

    level = (key - '0');

Obvious.