Python SDK demo

This commit is contained in:
Eden Kirin
2023-03-27 13:33:23 +02:00
parent cf0605c83c
commit 5e8981953f
3 changed files with 66 additions and 9 deletions

View File

@ -5,37 +5,42 @@ const FAIRHOPPER_PORT = 8010;
async function main() {
const fh = new sdk.FairHopper(FAIRHOPPER_HOST, FAIRHOPPER_PORT);
await fh.ping();
console.log(`Pinging FairHopper server on ${FAIRHOPPER_HOST}:${FAIRHOPPER_PORT}`);
const pingResult = await fh.ping();
console.log("Ping result:", pingResult);
console.log();
game = await fh.startGame("Mirko");
console.log("Board dimensions:", game.board);
console.log("Destination position:", game.destination.position);
console.log();
const playerUuid = game.player.uuid;
console.log("Current position is", game.player.position);
console.log("Initial player position is", game.player.position);
let moveResult;
const playerUuid = game.player.uuid;
try {
console.log("Trying to move right");
moveResult = await fh.move(playerUuid, "right");
moveResult = await fh.move(playerUuid, sdk.Direction.RIGHT);
console.log("Successfully moved to", moveResult.player.position);
console.log("Trying to move right");
moveResult = await fh.move(playerUuid, "right");
moveResult = await fh.move(playerUuid, sdk.Direction.RIGHT);
console.log("Successfully moved to", moveResult.player.position);
console.log("Trying to move right");
moveResult = await fh.move(playerUuid, "right");
moveResult = await fh.move(playerUuid, sdk.Direction.RIGHT);
console.log("Successfully moved to", moveResult.player.position);
console.log("Trying to move down");
moveResult = await fh.move(playerUuid, "down");
moveResult = await fh.move(playerUuid, sdk.Direction.DOWN);
console.log("Successfully moved to", moveResult.player.position);
} catch (err) {
if (err instanceof sdk.PositionError) {
console.error("Cant't move in this direction");
} else {
console.error(err);
}
}
}