Home » Topics
Struggling with the game state management in my JavaScript Blackjack project
javascriptblackjackgame-devjs-logicstate-management
Registration:
09.11.2021
Messages: 1057
09.11.2021
Messages: 1057
Dev_Ops Topic author
01.01.2025 16:04
I've finally got the basic card drawing and hit functionality working for my JavaScript Blackjack game, but I'm running into trouble managing the overall game state. Specifically, when the dealer busts or when a player gets blackjack, the UI needs to update dramatically, and I'm struggling to keep the logic clean. Should I use a class structure to encapsulate the game state, or would a simple object and global functions be sufficient for a project of this size? Any advice on best practices for handling turn-based game logic in vanilla JS would be greatly appreciated. I want to avoid spaghetti code at all costs.
18 Answers
03.12.2022
Posts: 695
Posts: 695
26.04.2022
Posts: 242
Posts: 242
18.04.2024
Posts: 558
Posts: 558
17.10.2021
Posts: 463
Posts: 463
The key isn't just the structure, but the separation of concerns. Separate your Game Logic (the rules) from your View/UI updates. When the state changes (e.g., dealer busts), the logic should just update the state object, and a separate function should handle rendering that state to the DOM.
15.03.2024
Posts: 862
Posts: 862
12.11.2021
Posts: 975
Posts: 975
08.02.2023
Posts: 1094
Posts: 1094
03.07.2022
Posts: 950
Posts: 950
13.02.2022
Posts: 1187
Posts: 1187
02.04.2025
Posts: 529
Posts: 529
24.10.2022
Posts: 82
Posts: 82
13.08.2023
Posts: 63
Posts: 63
07.12.2021
Posts: 1192
Posts: 1192
04.11.2024
Posts: 1348
Posts: 1348
17.01.2024
Posts: 942
Posts: 942
16.06.2024
Posts: 688
Posts: 688
16.07.2022
Posts: 509
Posts: 509
Want to join the discussion?
To leave a comment, you must log in to the forum.