PlayFab Samples

Nahuel Beni
Oct 13 · 3 min read

At SOUTHWORKS we’re not just Azure devs, we’re also gamers. While doing some “work” we realized that it might be useful to investigate how to bridge the gaps between these powerful Microsoft platforms (and convince our bosses we’re working, not playing). So, in the interest of bringing communities together, SOUTHWORKS has created an open source repository where we (and all you other developers reading this) will post ways to address common scenarios and challenges that call for integrating these two platforms.

Our first contribution to the project is now live and our friends at Microsoft already found it interesting. It is a sample to showcase how to use PlayFab’s Matchmaking service with a simple turn-based multiplayer game (like TicTacToe) as a quick player matching solution. We’ve included a custom implementation of Match Lobbies along with some custom Azure functions and a Cosmos DB to add support for listing, searching and joining a specific match.

Turn-based multiplayer

For this sample we took the Tic-Tac-Toe PlayFab sample and extended it to support two players. To do this we migrated the use of Player Custom Data to use Shared Group Data and tweaked the main loop to support waiting for the second player to move. Additionally, we implemented matchmaking using PlayFab’s Matchmaking service.

Image for post
Image for post

Match Lobbies

Finally, we wanted to allow players to join their friends by searching for a specific match lobby. This is a feature not supported out-of-the-box by PlayFab so we had to implement an external solution for storing and searching matches, we used CosmosDB and implemented a flow that looks like this.

Image for post
Image for post

The following diagram briefly describes the flow for creating a new match lobby.

Image for post
Image for post

The following diagram briefly describes the flow of searching a match lobby, as you can see it’s as simple as searching for the available matches in the CosmosDB

Image for post
Image for post

The following diagram briefly describes the flow for joining a match lobby and kicking off the game.

Image for post
Image for post

We hope you enjoy and welcome your questions and feedback.

SOUTHWORKS

SOUTHWORKS is the remote dev firm people turn to for their…

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store