Lummox Labs

Mobile app maker since 2015

Game History with Actions in Forbidden Desert

Haven't played Forbidden Desert yet? Grab it here!

In the mood for a puzzle game instead? Try out Noodles!


This post is one in a series about the Action pattern used in Forbidden Desert on iPad.

So in the previous post we looked at what an Action is, and what it looks like in Swift. Now let's talk about one of the great benefits the game gets from the Action pattern.

The actions have these two methods:

final func doAction(game:Game) -> ()
final func undoAction(game:Game) -> ()

Which are super-easy to use for any Action.

let action = ExcavateAction(tileId: "equip0")
action.doAction(game)
...
action.undoAction(game)

So how can we use this to make an easy game history? Well, let's add a list of everything that's changed the game.

class Game {
  var actionHistory: [GameAction] = [] 
  ...
}

And now every time you perform an action, add it to the history.

let action = ExcavateAction(tileId: "equip0")
action.doAction(game)
game.actionHistory.append(action)

Now you've got enough information to rewind the entire game right to the beginning, action by action. Just keep pulling the last action in the list, and calling undoAction(game). 

You could add a slider to your game that lets a user slide back and forth in history, or easily get a count of how many moves there ever were. There's lots of power hidden in that list of actions.

But the biggest win is just giving the user the ability to Undo to the beginning of their turn, with confidence that the game state won't get messed up with so much change flying around. As long as each action is internally consistent (that undoActionInternal perfectly reverses doActionInternal) then the game will stay consistent too.

We'll take a look in future blog posts at some of the other benefits to the Action pattern.