How to Build an Emoji Game Using AngularJS

Tony Spiro
HackerNoon.com
10 min readJul 10, 2017

--

In this tutorial I’m going to show you how to create a “Emoji” game using a little bit of Node, and Cosmic JS. For the sake of understanding how to consume Restful API’s, this tutorial will show how to make simple AJAX requests to the Cosmic JS API in order to retrieve, update, and delete data in our Cosmic JS Buckets. Let’s get started.

TL;DR

Download the GitHub repo.
Check out the demo.

Getting Started:

First, let’s make a new directory to build our project in and lets also make a package.json file.

Now, in your package.json, copy and paste the code below:

Second, let’s make a bower.json file.

Now, in your bower.json, copy and paste the code below:

Config app server:

What we’re installing and why:

  1. We’re going to use the AngularJS framework to build Single-page application
  2. We’re installing angular-ui-router for create multi views.
  3. We are going to use gulp for build all js and css files into one file.

Building our app:

Now we’re going to build out our file structure a bit more so that we can organize our angular modules and js files. This is what our emoji-app directory should look like:

Now we we will set up our index.html. Copy and paste the following code into your index.html file:

Here, we are going to target our “root” view to place our angular modules in later. The main.js file located in our dist directory is what our gulpfile.js file will spit out after bundling all of our angular modules Now, set up our gulpfile.js file to bundle all of our js files and export that bundle file to our dist directory. Copy the following code into your gulpfile.js file:

After that we can create main module. Copy and paste the following code into your main.mdl.js file:

Now we we will set up our Auth Controller. Copy and paste the following code into your auth.ctrl.js file:

Create Auth Service, copy and paste the code below:

What’s going on here:

  1. We are using the ui-router for config routes.
  2. We created Auth Service for our asynchronous calls to our Cosmic JS API.
  3. We created Auth Controller for checking credentials.

Create User Service for get and update User, copy and paste the code below:

Create Emoji Service for get emoji from words, copy and paste the code below:

Create Emoji Controller for get quotes and checking results, copy and paste the code below:

Create Emoji Module, copy and paste the code below:

What’s going on here:

  1. We created Emoji Service for get emoji from words.
  2. We created Emoji Controller for drag and drop emoji, get quotes and checking results.
  3. We created Emoji Module.

Create Author Controller for getting information of author, copy and paste the code below:

Create Author Module, copy and paste the code below:

What’s going on here:

  1. We can see information about authors.

Conclusion:

We were able to consume the Cosmic JS API with our actions and dispatcher functions. I hope you enjoyed this tutorial as much as I did, if you have any questions reach out to us on Twitter and join our community on Slack.

--

--