I'm currently making a small game for my C++ programming class and the professor requires us to have a timer for the game. We haven't talked at all about how to use timers and any std timer libraries so we're on our own. I found the std library and have tried to implement a simple timer for the game and have managed to do so but I can't seem to figure out how to format the time from it to a more user friendly version like HH:MM:SS.Millisecons. All I have is the raw time since I started the steady_clock till I ended it and I can display that in seconds, milliseconds, minutes, whatever, but that doesn't look as good as I'd like to. I found some solutioms but they are way too hard for me to even deconstruct and try to apply. Any simple way to do what I want? Part of my code where I implement the timer:
// Initialize game timer using <chrono>
chrono::steady_clock::time_point start = chrono::steady_clock::now();
// While game is running (player alive and enemy robot lefts) update map
while (!GameEnd){
show_maze(maze_map);
cout << endl;
playerMove(x, y, GameEnd, died, maze_map);
}
// Terminate game timer and calculate time elapsed
chrono::steady_clock::time_point end = chrono::steady_clock::now();
chrono::steady_clock::duration time_elapsed = end - start;
// Show last map state before either player died or no more robots left
show_maze(maze_map);
// Boo / congratulate player for his performance on the game
cout << "Game Over! You " << (died ? "died by hitting a fence/robot :(" : "won because all the robots died. Congratulations!") << endl;
cout << "Your game lasted for " << chrono::duration_cast<chrono::milliseconds>(time_elapsed).count() << " milliseconds.\n\n";