It's simple quizz game, where bunch of players answers set of question and one who has the most correct answers wins.
Disclaimer I created it for my girlfriend on her Baby shower party. Time was crucial, and expectations weren't that high. It's far from being ideal but it was a little after hours project. Also one important thing is, that it was designed to be run on local network only and as so it was never designed to be published on the Internet. It's very important from security point of view as this lacks many basic safety mechanism. Current authentication mechanism exist only for game-play reasons, so people can simply signup and stay in game. It's not production ready code!
Game has 4 states:
- new game
- awaiting for players
- started
- finished
In the beginning, the game is not available as long as it is not created by host. After host creates the game, it switch to "new game" state. From now other people may join by entering special link and becoming players after they give their names. Also now host can add questions to the game.
After game has been started by the host, no other person is allowed to join and no more questions can be added.
Questions are asked one by one in the order specified by host. Game moves to next question automatically when all players give theirs answer. Always only one answer can be given. There are no multi answer questions. After all players answer last question, game ends. At the end scores are summed up and the game picks the winner.
There are three main components of the game:
- host panel - to manage the game (actually there is only start button, rest must be done via API)
- player panel - to join and play the game
- game panel - to displaying current game state: screen with join link, current question and score board
To add questions REST API must be used. Rest of the game is based on forms. Admin panel is hidden and to reach it user must be authenticated. Base HTTP Authentication was choosen as simplest solution. Game is based on session, so loosing your sesion will unable you to continue the game. Acctually game is constructed in such a way that if one player looses his/her session game cannot be continued by anyone as it is expecting all players to answet their questions. Although I have very little time, I decided to use DDD way of writing with separation into three layers. It is my default way of thinking about applications, and my default way of creating them. I feel very comfrotable with that separation of responsibilities. Domain is mostly tested where the rest of code is not.
One interesting part of the code is a little state machine I created with the new enums in PHP8, you can check it out at Domain\Game\State.
I used some graphic from the Internet to make this game a little more nice to eye. Here are links: