DEV Community

Christian Howard
Christian Howard

Posted on

[Entry] Mafia: A Game About Deduction

What I built

Mafia is an online version of the popular icebreaker/party game with the same name. It is also known as Werewolf to some. In this game, players are divided into two groups, the Mafia and the Villagers. Within the Villagers, there are two special roles, the Doctor and the Detective. The game is played in two phases: Day and Night.

During the Day phase, the players tries to deduce which players belong to which group and anyone can put a specific player up for public elimination. If a majority vote succeeds, the player is eliminated. During the Night phase, the Mafia can chat to determine which player they want to eliminate while the Doctor can choose one player to save and the Detective can investigate one player to see which group they belong to.

The game ends when either the Mafia eliminate all the Villagers or the Villagers eliminate the Mafia.

Demo Link

https://app-mafia-game.herokuapp.com

Link to Code

https://github.com/christianhoward/mafia

How I built it

Stack
React.js
Node.js/Express.js
Pusher

When I originally thought of this idea, I thought Pusher would only be used for the chat portion and everything else would be pretty straight forward. That was not the case what-so-ever. I should have realized that Pusher would be needed for just about every part of the app and not just the chat. Manually testing a project of this size was also tough to handle. Knowing what I know now, I would probably opt for something less complex for my first go-around with a technology that is new to me (Pusher).

Additional Resources/Info

Unfortunately, I encountered a road block in the form of a last minute coding challenge that needed to take priority, so this is no where near being as polished as I would like.

This game is hard coded for 7 players, so if you are interested in trying it out, I would recommend having 7 total players (including yourself). I also had to hard code the roles for the game, so the role distribution is never randomized. If I had more time, I would have figured out a way to properly randomize the roles. It can be a little finicky at times, but I'm not sure if this is because of my testing locally or if it's the code itself.

Additionally, there are a few UI bugs in the Mafia Chat that I would have liked to clean up but ran out of time. Styling also fell by the wayside to some extent. Generally, my approach is functionality then styling, so with the time crunch, some styling wasn't completed.

With more time, I would also figure out some way to encrypt the React state, so that tech savvy players couldn't go into the DevTools and spoil the game haha.

Other Posts

Initial Thoughts
Feature Building and CSS Distractions

Latest comments (0)