In this article, I would like to share the development experience of my latest project, Mafia: The Game.
Mafia is a social mystery party game played by a group of people. It's also known as Werewolf, but if you are not familiar with it, check out this Wikipedia page.
Most of my experience in software engineering before this point had been in iOS app development. For this reason, I started this project with an iOS app built with Swift and SwiftUI. Naively, I believed just a CloudKit database would be enough to power the multiplayer capabilities of the game.
After many hours of programming, I eventually did get the app working with only a database but the results were mixed:
Pros:
Cons:
Although I was proud of my work so far, I decided that it would be worthwhile to learn server-side as well.
Before this, I had never developed a REST API so I really didn't have a clue what languages or technologies I should be using. I began with a google search ("How to make a REST API") which led me to a tutorial for using Express.js.
I had used JS when building simple HTML-CSS-JS websites years ago so I was quite drawn to working with it. Perhaps the biggest pull to Express, however, was the fact I got up a simple API up and running within 20 minutes.
Excited by my new-found ability to make REST APIs, I rushed to develop the full feature set for making games, joining games, and actually playing them. I thoroughly enjoyed this change of scene from iOS development but I do have several comments:
After I had the server developed, I was quite intent on using an AWS EC2 instance to deploy it because I had read about AWS in the past. However, I stumbled across Heroku in my research and decided to use that instead. This was for three main reasons:
With my server up and running, it was time to go ahead and use it in the app.
Now the REST API was working, I decided to implement the client-side networking layer as a Swift Package to properly modularise my code. Although I was hesitant about using this within an Xcode project, to my surprise it went really well. I even used a hierarchy of Swift Packages to manage all the way from the API to the model to the UI. Key takeaway: Swift Package manager is awesome! 🎉
Other improvements I made were widgets to view stats from the home screen. Although this was only a short exercise, it was highly enjoyable to explore the new WidgetKit API.
I realised that to properly make this multiplayer game, I needed a way that everyone (whether they have an iPhone or not) would be able to play it. I briefly considered learning more about Kotlin and Android development but that didn't solve the problem of access from desktop computers.
In the end, I decided to give front-end development a try using React. To do this, I first used the Learn React course on Codecademy to get to grips with the basics.
I decided to use Chakra UI for styling. I really loved the experience of working with it as it avoided CSS files. I am not a designer but the website I produced was at least acceptable!
Another technology I used, was this counting API. It provided an easy way to keep track of page views without relying too heavily on third-parties such as Google and Facebook. I would recommend it to anyone as a simple way to achieve this.
I was surprised at how quickly I made the entire website, especially given that this was my first project using React. In the end, I think it was down to great data-flow between components. I tried as much as possible to keep this uni-directional and it certainly paid off. The single source of truth is the game file which is provided to all the child components in their
props
.After I had produced all the pages, I started to look at deployment methods. My first thought was GitHub Pages. However, the requirement to use a `HashRouter` rather than a `BrowserRouter` for navigation put me off. Eventually, I settled on trying out Netlify. This was great because they ran the correct commands to generate the build directory for me, so I just had to focus on pushing the code to the production branch. Like Heroku, this was an extremely easy experience.
Now the website was done, I returned to my Xcode project and decided to use my current codebase to add more Apple platforms to the game.
Firstly, I enabled Mac Catalyst. This allowed me to quickly make a Mac app without adding any extra code. One issue I did encounter, however, was to do with resizable windows; it resulted in a buggy UI that looked weird at extreme aspect ratios. To fix this issue, I decided to set a fixed-window size.
I also built a simple tvOS version of the app. This allowed players to host games from their living room so everyone can see who's dead/alive and keep up to date on the latest in-game alerts. Using SwiftUI and Swift Packages required minimal code as well.
With that, my site was on the internet and my suite of apps was ready for the App Store!
There are so many gameplay features I would love to implement such as new player roles and a more interactive UI. Moving to a persistent database rather than the local filesystem on the Heroku server is another challenge that I am looking at undertaking.
My key findings:
I absolutely loved working on this project and I have learned so much - Node.js, Express and React. If you have time, I would love it if you could check out my website or iOS app - it's free! I'd also really appreciate any feedback on ProductHunt.
Thank you and happy coding!