DEV Community 👩‍💻👨‍💻

Cover image for Lets Save The World!
Maarten Engels
Maarten Engels

Posted on

Lets Save The World!

Will you join me to - dare I say it - Save the World?

Overview of My Submission

In this web based game/simulation you play as a country. You are able to enact, revoke and upgrade policies that influence your country in various ways and by consequence, also the Earth as a whole.

There is no win/lose condition per se, but perhaps trying to keep global warming under 1.5 degrees above pre-industrial temperature is a nice goal?

It's multiplayer, so the more people play, the bigger the impact we can all make!

Play example

History

November 14 I registered a domain name, more or less on a whim: letssavetheworld.club. It was around the time of the Climate Conference in Glasgow and I remember how disappointed I was about the results. Was it really that difficult to actually start doing something? So I decided I'd create a game/simulation to get a sense of the complexity involved. I researched climate change models and the effects of global warming for humanity.

Then, this hackathon came along, offering the perfect reason to actually create the game and publish it.

Submission Category:

Choose Your Own Adventure

Link to Code

GitHub logo maartene / STW

MongoDB+Dev hackathon entry: a game where we - dare I say it - Save The World!

STW

MongoDB+Dev hackathon entry: a game where we - dare I say it - Save The World!

You can play a live build at https://www.letssavetheworld.club

Project setup

The application consists of two parts:

  • API backend: written in Swift using the Vapor framework;
  • Web frontend: written in JavaScript using the Vue framework.

Running the API backend

Pre-requisites

  • You need the Swift toolchain. If you are on macOS, just make sure you have the latest version of Xcode installed. On Linux, you can download Swift from swift.org.
  • You need a MongoDB, either local or on a cloud service like Mongo Atlas. Mongo Atlas has a free tier that works quite well for (testing) this project.
  • Setting the environment variable STW_BACKEND_DB_URL to your MongoDB connection string.
  • By default, the API backend listens on port 8000. If you want to change this, you can do so by setting the environment variable: STW_BACKEND_PORT.

Linux:

…

Additional Resources / Info

About the climate change model

Climate change is a pretty complex concept. The model used in this game is very, VERY basic. It only covers average global temperature and warming based on carbon concentration in the atmosphere. It is not aware of regional differences. The model in itself is flexible though and could be expanded to take more metrics into account.
(exact links to the various data sources for the model can be found in the source code)

About the tech

Lets Save The World is based on two big technologies:

  • backend uses the Vapor framework: a Server Side Swift framework. I like using Swift and feel that in particular for backend work. Its an opinionated language that somehow seems to help me write better code. That Vapor supports MongoDB out of the box also helps;
  • front-end uses the Vue.js framework (with Vuex). I'm no Javascript expert, but find it very easy to use Vue to create a usable front-end.

The runtime version of the game is deployed on the DigitalOcean App platform. The front-end as a Static Website (using a free plan), the backend as a Docker image (using the cheapest paid plan. The app platform takes care of all the complex stuff, such as creating TLS/SSL certificates for the website, deployments and the networking/domain stuff.

About the usage of MongoDB

MongoDB tends to be my database backend of choice for Vapor projects. I like the flexibility its schemaless setup offers. And I like that it uses JSON for most interactions, making bridging to data in the Vapor (Swift) world very easy, because Swift has very simple solutions for briding between JSON and actual Swift data structures.

I also like using MongoDB Atlas as a database provider. Off course, I could run my own MongoDB instance, but having the admin website in Atlas makes it much easier during development to experiment and quickly change stuff. Need to change a value in a document somewhere? The web interface makes this very easy. Need an extra database or drop a table? Just a few clicks. Finally, the larger (paid) Atlas plans provide stuff like backups out of the box. Something that's always a lot of work when you roll your own.

These two aspects help developer productivity a lot.

Feedback/improvements

If you have feedback, please let me know in the comments below. Also, if you have ideas from a game design point of view to make it more engaging, please reach out to me. I'm more of a programmer than a game designer, so can always use help to improve the fun and engagement of a game!

Top comments (0)

Build Anything...


Use any Linode offering to create something for the DEV x Linode Hackathon 2022. A variety of prizes are up for grabs, inculding $1,000 USD. 👀

→ Join the Hackathon <-