Lets Play Pontoon – Part 1

In this series of posts we’ll run through how to create the game of Pontoon running in the cloud on the GameSparks platform.

This post will detail the process we followed and the steps required to get the core logic working, the next post will show how we test the logic using the test harness.

1. Create a new game

We’ll start by creating a new Game in the portal. We’ll call it Pontoon, and use the empty game template so we can start from scratch.

Screen Shot 2013-10-24 at 17.06.53

2. Create Events

There are 2 player events that happen in pontoon that we care about, Twist and Stick. We’ll create an event for each. The events do not require any data to be passed, so no attributes need to be created. We’ll use TWIST and STICK as the respective short codes for the events.

Screen Shot 2013-10-24 at 17.09.31

3. Create a Challenge

We need to define how a challenge should behave. Pontoon is a turn based game, where each player takes a number of goes before either sticking or going bust. We’ll create a new Challenge that defines itself as turn based and uses the Stick event to move to the next player. The process of going bust will need to be calculated in our cloud code. There is no leaderboard so we’ll specify the outcome is scripted.

Screen Shot 2013-10-24 at 17.12.50

4. Challenge Setup

When the challenge starts, we need to define a deck of cards and shuffle them, this deck can then be stored against the challenge with the shuffled order maintained for each player as they take their turns. To do this we create some cloud code that binds to the ChallengeStartedMessage. This message is generated by the platform when the challenge begins and runs once per challenge.

The following functions were created in a new module that would allow us to include it into any of our scripts (Credit to BrainJar for saving us from having to write this from scratch)

We create a cloud code module with the sort code of “cards” to store this code.

The complete listing for the cards module:


Once the module is done, we can create a Script and bind it to the ChallengeStartedMessage. It includes the module, creates a stack of cards and creates an empty had for each user. This data is stored against the challenge for further script invocations.

We created a Global Message Script and bound it to the ChallengeStartedMessage event:


5. Taking a turn

When the challenge starts, the platform assigns a random player to be the first. The first player will ask for cards to be twisted until they either stick or go bust. The first thing we need to do is handle the twist event.

We’ll create a module that contains common code for taking a turn, this can be used by both the stick and twist events. We save this with a short code of “turns”:

Now we have the turns module we can use it in a Challenge Event Script bound to the TWIST event:

Next we create it in a Challenge Event Script bound to the STICK event:

And with that, all the code is complete. The game is pretty simple so we’ll add further capabilities in future posts.


Who uses GameSparks?