The Making of the Azure Mystery Mansion
Tags: serverless, games, cloud, twine
Published: 2019-10-31 20:26:34

---
title: The Making of the Azure Mystery Mansion
published: false
description: Creating a text-based game to introduce folks to Microsoft Azure
published: true
cover_image: https://media.giphy.com/media/wyC0qsYrpEgMM/giphy.gif
tags: Serverless, Games, Cloud, Twine
---

It was a sunny, hot morning in July when I opened Outlook and took a look at the messages scrolling slowly past. Meeting, meeting, meeting, ... and a request! My colleague, Chris Noring, had cc'ed me on a message about an innovative code-challenge project that had been launched several months ago. It involved a Power Animal Quiz to engage developers and raise awareness of Microsoft Learn, a repository of educational modules that help developers learn about Azure, Microsoft's cloud offering. 

Apparently, the Power Animal Quiz had been a hit, and the hunt was on for a new and cool project to engage developers. "They are building an awesome campaign with compelling content and a fun challenge", Chris wrote. I was curious and immediately thought of puzzles such as those created by Google to [reveal the date of Google I/O](https://nextbiggadgets.com/2018/01/24/google-io-2018-teaser-conference-date-venue/). Could we create an online puzzle for developers? Would they like it? What would it look like?

Over the next few weeks Chris, who has a degree in game development, and I started thinking about the type of project that we could create that would both be fun and innovative to build and that would engage developers in a cool, retro way. A scavenger hunt? A "choose-your-own-adventure" clickable game? We settled on a text-based game that would be entirely clickable to proceed, something like the old-school games we used to play in Middle School like [Raaka-Tu](http://www.figmentfly.com/raakatu/raakatu.html). The premise would be to wander through an old house, picking up objects and solving puzzles along the way. The first prototype used a [library I discovered on GitHub](https://github.com/pistacchio/Dedalus) with art likewise borrowed from the internet. It looked like this:

![AMM V1](https://thepracticaldev.s3.amazonaws.com/i/1fx7kbazmlkm99opkp4r.png)

As the project progressed and Halloween approached, we pivoted slightly both with the folks who were involved in the project and its overall atmosphere. Dubbed the "Azure Mystery Mansion" (a nod to work I have been doing recently on Beatles lyrics), the project started integrating custom art and new puzzles:

![AAM V2](https://thepracticaldev.s3.amazonaws.com/i/6y1izmcp3rf723go8hzh.png)

As Chris turned his attention to other projects, a new team member was added, [Em Lazer-Walker](http://lazerwalker.com), a specialist in text-based games as well as other innovative game experiences. An ideal team-member for this project, Em introduced a new architecture to the project: [Twine](https://twinery.org/), "an open-source tool for telling interactive, nonlinear stories". I'm certain I never would have found this project by myself, but having worked with it, it's a super way to build [this type of game](https://www.nytimes.com/2014/11/23/magazine/twine-the-video-game-technology-for-all.html), which has been used to build other well-known text games such as Zoe Quinn's Depression Quest. You should give it a try!

## Building a Text-Based Game with Twine

If you've never tried Twine, you can [download it for free](https://twinery.org/). Using Twine 2, you are given a graphical interface where you craft your users' pathways. For example, from a front porch, a person can enter a foyer, from which several rooms branch off; the user can wander into a library, a salon, a dining room, or go upstairs to the bedroom. 

![Twine](https://thepracticaldev.s3.amazonaws.com/i/b1qoxt7ar0lqm3qj7msy.png)

You can style your app using basic CSS, and you write your logic in one of several possible game engines that come with markup formats. We used Harlowe, which looks like this:

```
(set: $inventory to (a:))
(set: $chest to (a: 'a shield', 'a suit of armor'))
(set: $chestOpen to false)

:: inventory [header]
You are currently carrying: 
<!-- if the inventory contains nothing, show "nothing" -->\
(if: $inventory's length is 0)[\
    nothing.
](else:)[\
    <!-- we iterate over the array and print each item -->\
    (for: each _item, ...$inventory)[\
        _item (unless: $inventory's last is _item)[, ]\
    ].
]
```

In this sample, the inventory array is initialized and the items in the chest are assigned to it. Then the inventory is printed out.

To progress in the game, you write the narrative and then enhance it with arrays, variables and macros. 

```
You find yourself inside a small room. In the corner, you see a sword, and decide to pick it up.

(set: $inventory to it + (a: 'a sword'))\
[[Continue|hallway]]

:: hallway
You see a chest here in the hallway.  \
(unless: $chestOpen)[\
    Do you want to open it?

    {
    (link: 'Open the chest.')[
        <!-- adding to arrays together can also be done with the + operator -->
        (set: $inventory to it + $chest)
        (set: $chestOpen to true)
        (goto: 'chest')
    ]
    }
](else:)[\
    It's open, and there's nothing inside.
]\

[[Move on.|dart trap]]

```

In the above example, you explore a space, pick up items and perform tasks such as opening a chest to view its contents.

Using Twine, we created a spooky mystery mansion experience where folks can solve problems in each room, like entering codes into an old rotary phone to open hiding places. Twine exports the entire game to a flat html file, which you can then commit to GitHub to be picked up by [Azure Pipelines](https://docs.microsoft.com/azure/devops/pipelines/?view=azure-devops&WT.mc_id=devto-blog-jelooper) to complete the CI/CD process and build out the game's website.

##Game Analytics with PlayFab

You may have written a blockbuster game, but it won't do you any good unless you have analytics behind it to show you your users and their paths. We are lucky to have a Microsoft-owned game platform called [PlayFab](https://docs.microsoft.com/en-us/gaming/playfab?WT.mc_id=devto-blog-jelooper) that serves as a robust and easy to configure and manage game PAAS. PlayFab can provide a scalable backend for large-scale online multiplayer games, handling everything from matchmaking to in-game economy to social features. It provides a backend for the Mystery Mansion, even though it's a much smaller game that's not using any of those features. We're only using it to gauge numbers of visitors and to gather some basic analytics data about how players are doing:

![PlayFab](https://thepracticaldev.s3.amazonaws.com/i/hlsylos7wfv99svlck2u.png)

We're using basic PlayFab login to track how many daily users we have, and where in the world they're coming from. We're also using the real-time [PlayStream events API](https://docs.microsoft.com/en-us/gaming/playfab/features/automation/playstream-events?WT.mc_id=devto-blog-jelooper) to log whenever players do things like solve a puzzle, so we can get a clearer sense of questions like how much time people spend on the game, what percentage of players beat it, and which puzzles are stumping people. Integrating PlayFab into our Twine game only took a few minutes!

##Dare To Play!

Do you want the deeds to the Azure Mystery Mansion? Solve the puzzles, collect 8 keys in the rooms, and climb to the attic for your prize. Then tweet about your experience to spread the word!

[Click here to enter the Mystery Mansion!](https://aka.ms/mysterymansion?WT.mc_id=devto-blog-jelooper)