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.
const state = game.state(entity);
state.type = 'Character';
state.hp = 100;
state.xp = 0;
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';
}
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.
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);
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);
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);
}