Skip to content

Solution with Timer - #780

Closed
cparkes1 wants to merge 3 commits into
the-csharp-academy:mainfrom
cparkes1:main
Closed

cparkes1 wants to merge 3 commits into
the-csharp-academy:mainfrom
cparkes1:main

Conversation

@cparkes1

Copy link
Copy Markdown

No description provided.

Import System.Diagnostics and add Stopwatch timing around the question loop. Capture start timestamp before the do/while loop and compute elapsed time after, formatted as mm:ss.fff and shown in console output. Replace scoreTracker int with score and update increments/usages. Change scoreList from List<int> to List<string> and store combined "score + formatted elapsed" entries. Update console messages to display points alongside elapsed time.
Replace the old string-based score list with a typed GameResult model and update program logic to store, sort, and display GameResult instances.

- Add GameResult class (Score:int, Time:TimeSpan) with ctor and ToString() that formats time as mm:ss.fff.
- Add using System.Collections.Generic and System.Linq to Program.cs.
- Replace List<string> scoreList with List<GameResult> scoreHistory.
- Build sortedLeaderboard with LINQ: OrderByDescending(r => r.Score).ThenBy(r => r.Time) and print entries via GameResult.ToString().
- On game end compute elapsedTime (TimeSpan) and add new GameResult(score, elapsedTime) instead of a preformatted string.
@github-actions

Copy link
Copy Markdown

🚀 Project Submitted!

Thanks for submitting your project! I will review it soon.

📋 Please check the dashboard to make sure the project is marked as Pending.

⚠️ If it's not marked as pending, submit it manually using the URL for this PR.

@TheCSharpAcademy

Copy link
Copy Markdown
Collaborator

@cparkes1 Project approved! 😄✅ ✅ Well done for completing the timer challenge. It's a shame you didn't complete the other ones this time. 😟 It's always a good use of your time. But nothing stops you from revisiting the project later. 👩‍🎤

🥋And congratulations! You got your green belt!! 🟩🟩

Feedback
🔍️ I found an important bug while testing. When I enter an incorrect input in the main menu it still takes me to the game. For example if I input "lala":

image

🔍️It would be much easier and more readable to handle all menu options with a switch case instead of a massive if-else. You can use the default case to handle all invalid inputs.

🔍Adding the date and time a game was played would make the history feature more informative.

🗺️I noticed that you haven't completed any of our courses yet. I suggest you try our Intro to Object Oriented Programming course next. This will close gaps in your knowledge and give you more confidence about OOP

☕If you like our roadmap, please consider buying us a coffee. We appreciate your help 🙂

Overall good work!✋🏻Looking forward to seeing your next projects!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants