I want to create a state machine for menu in my SDL game. So this is my code without the SDL I just want to ask if this is a good way to create it. here is a code:
#include <stdio.h> #include <windows.h> enum states { Menu, Game, Game_over, Exit }; int main() { int game_is_running = 1; enum states state = Menu; while(game_is_running == 1) { switch(state) { case Menu: state = Game; printf("menu screen with play and exit button.\n"); //need to add if //exit or play is pressed // if exit then exit program if play than you know... break; case Game: state = Game_over; printf("after play button is pressed game screen will show up.\n"); //after this i will come back to menu. break; case Game_over: state = Exit; printf("screen after game.\n"); break; case Exit: printf("turn game off.\n"); //this will be in the if function with a game. game_is_running = 0; break; } Sleep(1000); // sleep for a second just for test } return 0; }