44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
from fh_sdk import Direction, FairHopper, PositionError
|
|
|
|
FAIRHOPPER_HOST = "https://api.fairhopper.mjerenja.com"
|
|
|
|
|
|
def main() -> None:
|
|
fh = FairHopper(FAIRHOPPER_HOST)
|
|
|
|
print(f"Pinging FairHopper server on {FAIRHOPPER_HOST}")
|
|
res = fh.ping()
|
|
print("Ping result:", res)
|
|
print()
|
|
|
|
game = fh.start_game(player_name="Mirko")
|
|
print("Board dimensions:", game.board)
|
|
print("Destination position:", game.destination.position)
|
|
print()
|
|
print("Initial player position is", game.player.position)
|
|
|
|
player_id = game.player.id
|
|
|
|
try:
|
|
print("Trying to move right")
|
|
moveResult = fh.move(player_id, Direction.RIGHT)
|
|
print("Successfully moved to", moveResult.player.position)
|
|
|
|
print("Trying to move right")
|
|
moveResult = fh.move(player_id, Direction.RIGHT)
|
|
print("Successfully moved to", moveResult.player.position)
|
|
|
|
print("Trying to move right")
|
|
moveResult = fh.move(player_id, Direction.RIGHT)
|
|
print("Successfully moved to", moveResult.player.position)
|
|
|
|
print("Trying to move down")
|
|
moveResult = fh.move(player_id, Direction.DOWN)
|
|
print("Successfully moved to", moveResult.player.position)
|
|
except PositionError:
|
|
print("Cant't move in this direction")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|