Building ‘Star Wars: The Awaken’

Warren Niu
4 min readOct 23, 2020

A command line, decision based game based on the popular ‘Star Wars’ franchise

“A long time ago, in a galaxy far, far away…”

Well, not that far away, but it definitely felt a long time ago when my partner and I presented our project pitch, just three days ago, to our module one instructors at Flatiron School. Where do we even start, we wondered?

I was familiar with the Command Line Interface, or CLI, from running tests and navigating directories. But to build an applications that runs on the CLI? We had our hands full, for sure.

We started with what we knew — domain modeling. Or at least that’s what I thought at the time. It’s one thing to be presented with the models and instructed how the models associate with each other, but to build one from scratch…that’s a whole new challenge and something that I’ve never done before.

With some trial & error (even after we started the project — we had to tinker with our model and set a new join class), we came up with the below:

The model that started it all

A simple 3 model domain, where our Games model was our join class. In addition to using an API (SWAPI https://swapi.dev/documentation), which is what drew our inspiration for creating a Star Wars game, we calmed our nerves upon the realization that we’ve seen this before & can build this out.

Migrations

Using Active Record migrations felt like receiving my first Pokemon card when I was 12 (it was a Diglett, but still). Migrations allow the user to “evolve” their database schema through separate instances, or what we’d like to call migrations.

Let’s say if we had the following schema:

Looks good right? But what if we wanted to add a column to “planets” and call it habitants, or change the datatype of “karma” to an integer? Rather than hard-coding everything manually, we can easily rollback our migrations to the moment we created the planets or games table, update what we need, and re-migrate the database with the handy “rake” command.

Working with APIs

The Star Wars API, or SWAPI, was a wonderful first API to work with. The flexibility of pulling data from a vast database was something that we wanted to learn early, and with a little help from our instructor — we were able to pull the right data & parse it into something useful our project.

RestClient & JSON were two gems we worked with to access our API data

In the above snippet, we use RestClient.get to access the data that we need, and JSON.parse to parse that data and collect only the information that we need. In this case, we only need the planet’s name, population, and terrain. And just like that, we have our planet information!

Building the Game

With our foundation set, we can start with the fun part!

Well, for the most part. Building the game took roughly two full days and a chronic case of headaches, but we have a finished product that we feel proud of given the time & resources we had. So how did we get here?

Star Wars: Awaken main menu. Your adventure starts here!

Ah, the main menu. After setting up our environment (which also came with it’s complications), we created the necessary nested methods for users to create an account and login. Our User class contains our username & password information for our users (as seen in our above schema) and using the combination of the Active Record find_by username and password methods and TTY::Prompt (more on TTY in a second), we’re able to have our users create an account, login and check for any errors and duplicates.

From there, we enter the meat of the program. We utilized the TTY toolkit gem as our main driver in presenting prompts to our users. In addition to our menu options, we utilized TTY in our scenarios for our users to select from, as well as view “The Awakened”, which is our result board. It was such a major tool for us and the flood gates suddenly opened for us in building our program.

Photo by Tommy van Kessel 🤙 on Unsplash

Having played plenty of games in my life, creating Star Wars: The Awaken’ felt like a dream come true. In the grand scheme of things, the program itself is very basic & simple (and definitely won’t win any awards with it’s content and design), but it’s something that my partner and I created, and I’m incredibly proud of what we achieved in such a short period of time.

I encourage you to try out our game, and I hope it inspires you to create something that you’re proud of us as well.

How to play:

Clone the repository(main branch) ‘git@github.com:warrenniu/ruby-project-guidelines.git’ to your local machine and run ‘bundle install’

run ‘Rake db:migrate’

run ‘Rake db:seed’

run ‘ruby bin/main.rb’

--

--

Warren Niu

Uncovering the truths of Software Engineering one story at a time. Former Healthcare Administrator and proud dad of my Pomeranian, Nami. Based in Brooklyn, NY