48 lines
1.6 KiB
JavaScript
48 lines
1.6 KiB
JavaScript
const sdk = require("./fh_sdk");
|
|
|
|
const FAIRHOPPER_HOST = "https://api.fairhopper.mjerenja.com";
|
|
|
|
async function main() {
|
|
const fh = new sdk.FairHopper(FAIRHOPPER_HOST);
|
|
|
|
console.log(`Pinging FairHopper server on ${FAIRHOPPER_HOST}`);
|
|
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();
|
|
console.log("Initial player position is", game.player.position);
|
|
|
|
let moveResult;
|
|
const playerId = game.player.id;
|
|
|
|
try {
|
|
console.log("Trying to move right");
|
|
moveResult = await fh.move(playerId, sdk.Direction.RIGHT);
|
|
console.log("Successfully moved to", moveResult.player.position);
|
|
|
|
console.log("Trying to move right");
|
|
moveResult = await fh.move(playerId, sdk.Direction.RIGHT);
|
|
console.log("Successfully moved to", moveResult.player.position);
|
|
|
|
console.log("Trying to move right");
|
|
moveResult = await fh.move(playerId, sdk.Direction.RIGHT);
|
|
console.log("Successfully moved to", moveResult.player.position);
|
|
|
|
console.log("Trying to move down");
|
|
moveResult = await fh.move(playerId, 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);
|
|
}
|
|
}
|
|
}
|
|
|
|
main();
|