Tiny Little Elevator Simulator (Qt)
aminbandali.com
aminbandali.com
You know, it never occurred to me to do that, but I think there may be times when that would be a clearer idiom than an if statement (as long as you put "default:" immediately after "case true:"). I always feel like the order of clauses in an if-else gives a sense of privilege to whichever case is handled first, but there's less of that sense with a switch statement.
In particular, I think it might be a good alternative to conditionals on non-boolean arguments. For example, instead of:
if(countDown) {
countDown--;
} else {
blastOff();
}
You could use: switch (countDown) {
case 0:
blastOff();
break;
default:
countDown--;
}This isn't a dig at the poster; it just sparked some memories.
This is what I made in about 5 hours (java)
https://gist.github.com/brambram/6261967
(it was made in 2 sessions, in the 2nd session we had to expand the elevator code so it supported 2D movement)