DEV Community

Sam Ellis
Sam Ellis

Posted on

Designing a location game that keeps working when the phone has no signal

The default shape of a mobile game is a round trip. The player taps, the app asks a server, the server does the thinking, the app renders the answer. It works, it is easy to build, and it means the game is over the moment the signal is not.

For a location game this is a much bigger problem than it sounds, because the exact moments a player most wants to play are the moments the signal is worst. You are walking down a street, you hold the phone up to find the spot, and you are in a tunnel, a basement cafe, an old town with thick walls, or simply a city centre at 6pm with everyone else on the same two bars of 4G.

We built Ping Hunt with the assumption that the network might be absent, and the design decisions that followed are the most useful part of the project.

The wrong default: ask the server what the player is looking at

The obvious way to check whether a player's photo matches a spot is to upload the photo and let the server compare it. It is simple, it keeps the matching code in one place, and it means the client never needs reference images.

It also means the game dies without signal. And it means every single unlock is a network round trip with an upload, which is slow, expensive, and leaks a stream of geotagged photographs to your own infrastructure - a privacy problem in its own right, and one we would rather not have had.

We moved the match to the device. The server generates the hunt; the phone does the matching.

Ship the hunt, not just the request

The shift is in what the server sends. Instead of the client asking "what is at coordinate X?" and receiving an answer, the client asks for a hunt and receives the whole thing:

  • The ordered list of spots, with coordinates.
  • A small reference image for each spot.
  • The clue text and the hint ladder for each spot.
  • The total distance and estimated duration.

That payload is a few hundred kilobytes. It is not large, it compresses well, and - this is the important part - it does not change during the hunt. Which means the client can hold the entire game in memory and never talk to the server again until the hunt is finished.

This is the whole trick. If the data is static for the duration of the session, offline is not a special mode you build. It is the default, and "online" is just a bonus.

Compress the reference images hard

The reference images are what make the payload big, and they are also the part you can throw away. The matching does not need the full-resolution street-level panorama; it needs enough of the spot to recognise its shape and colour.

We ship aggressively downscaled, heavily compressed references - small enough that a dozen of them cost you almost nothing, and large enough that a recognisable corner is still recognisable. On a good connection the app will opportunistically fetch higher-quality references in the background for the spots you have not reached yet; if it cannot, you play with what you have.

That gives you a graceful ladder instead of a cliff.

Score can be client-side; progress needs to reconcile

Once the client decides "matched" and "not matched", it is also deciding the score. And a client cannot be trusted with a score.

The split we use:

  • The server is authoritative for the recorded result. When the hunt ends and you are online, the client submits what it did, and the server validates it - re-running the match against its own copy of the references, or at least checking the evidence - before it records a score.
  • The client is authoritative for progress within the hunt. Which spots are unlocked, what the current clue is, how many hints have been spent. None of that needs a round trip, and all of it is ephemeral.

The reconciliation problem is real but tractable: the client keeps a local log of what happened and when, and uploads it at the end. If the server rejects something, the player sees a corrected score. In practice the rejections are rare and the alternative - locking the game on every unlock - is much worse.

If your game has stakes worth attacking, treat the client score as a claim rather than a fact, and design the claim format so it can be checked.

What you give up, honestly

Offline play costs something specific, and it is worth writing the list down before you promise it:

  • New hunts cannot be generated without a connection. If the player finishes offline, they finish, but they cannot immediately start another one.
  • Leaderboards and social features cannot update live.
  • Live content - a spot that got closed this morning - cannot be removed from a hunt already downloaded.
  • Cheat detection is weaker, because the client held the whole game.

That last one is the one people get uncomfortable about, and the honest answer is that offline play and airtight anti-cheat are in tension. You cannot have both. Decide which one your product needs, and if you are not sure, look at what the score is actually for: a personal best, a shareable result and a sense of achievement need almost no protection. A prize needs a lot.

Degrade in a defined order

The interesting part is not "works offline" but "what does it look like when it does not". We use a fixed ladder, and each rung is worse in a way the player can feel:

  1. Full - the whole hunt with reference images.
  2. Reduced references - the hunt with lower-quality images, or images only for the next few spots.
  3. Text only - coordinates, clues and hints, with no images. The player walks to the coordinates and looks for the spot themselves.
  4. No help - the app cannot reach the network and has nothing cached for this area. It says so plainly and stops pretending.

Rung three is surprisingly playable and surprisingly useful. It turns the app back into a treasure hunt with written clues, which is a perfectly good game. Being able to fall back to it is what stops the whole thing feeling broken.

And notice what is missing from the ladder: there is no state where the app shows a spinner. If it cannot help, it says so in a sentence and gets out of the way.

Airplane mode should be a test case

If offline is the default, airplane mode is a first-class test condition, not an edge case to check before a release.

Turn it on and walk through: does the hunt still start? Can you still unlock spots? Do the hints still escalate? Does the finished hunt still upload later? Where does the app lie - is there a screen that implies it is fetching something when it is not?

We also test the awkward middle: start the hunt online, lose signal halfway, and finish it. That is where the state machine usually falls apart, because code paths written for "connected" and "not connected" meet for the first time.

Make the server's job smaller

There is a second, quieter benefit to all of this. If the server generates the hunt and ships it, the server is not in the hot path of play. It handles a request to start, a submission at the end, and the occasional opportunistic image refresh.

That means it scales differently. A game where every unlock is a server call has a traffic profile proportional to your player count multiplied by their engagement. A game where the server hands out a plan and then gets out of the way has a traffic profile proportional to your player count. It is also cheaper to run, easier to reason about, and considerably less likely to fall over on the one evening when everyone decides to go for a walk at the same time.

What I would tell someone starting this

  • Decide what the server is for. If it is only generating and validating, the client can do the rest and the game survives a tunnel.
  • Ship the whole session, not just the query. Static-for-the-session data is what makes offline the default rather than a mode.
  • Have a text-only rung. It is a good game on its own and it saves the whole experience.
  • Do not promise live anything you cannot deliver offline. Leaderboards and "new hunt" buttons need a connection, and pretending otherwise is what makes a game feel broken rather than limited.
  • Turn on airplane mode in your test plan.

The general lesson is bigger than games. If your product has a moment where the player most wants to use it and the signal is most likely to be terrible, that moment is the one you should design for - not because offline is a nice feature, but because it is where your users will meet your software at its worst.

If you are building something similar, I am glad to compare notes - Ping Hunt is out, and the awkward parts are mostly written down.

Top comments (0)