Example

The back-end is responsible for maintaining state and enforcing state mutation rules.

JS scripts define state mutation rules. These scripts run on the server in a sandbox. Check out the following examples for how state is mutated and maintained.

Back-End Game Script Excerpts

Character.js

const state = game.state(entity);
state.type = 'Character';
state.hp = 100;
state.xp = 0;

Attack.js

const attackerEntity = context.entities[0];
const attacker = game.state(attackerEntity);
const defenderEntity = context.entities[1];
const defender = game.state(defenderEntity);
defender.hp -= attacker.strength;
if (isDead(defender)) {
  defender.hp = 0;
  defender.statusMessage = 'Dead';
}

Back-End Script Integration Tests

The platform makes testing these scripts straightforward. The tests are written in C# to match the rest of the stack. This might seem a little strange, but these tests use a generated C# GameStateClient which can also be used in the Game UI itself.

CharacterTest.cs

GameEntityState character = await game.Create.Character();
var characterState = game.State(character);
Assert.Equal("Character", characterState.type);
Assert.Equal(100, characterState.hp);
Assert.Equal(0, characterState.xp);

AttackTest.cs

game.State(attacker).strength = 13;
game.State(defender).hp = 17;

await game.Call.Attack(attacker, defender);

// Enemy's hp should be reduced by the attacker's strength
Assert.Equal(4, game.State(defender).hp);

Front-End Game Client

You can use the C#/.NET compatible game engine of your choice for the front-end.

async Task Attack()
{
    await game.Call.Attack(selectedCharacter.Entity, selectedEnemyCharacter.Entity);
}