45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
from fh_sdk import Direction, FairHopper, PositionError
|
|
|
|
FAIRHOPPER_HOST = "http://127.0.0.1"
|
|
FAIRHOPPER_PORT = 8010
|
|
|
|
|
|
def main() -> None:
|
|
fh = FairHopper(FAIRHOPPER_HOST, FAIRHOPPER_PORT)
|
|
|
|
print(f"Pinging FairHopper server on {FAIRHOPPER_HOST}:{FAIRHOPPER_PORT}")
|
|
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_uuid = game.player.uuid
|
|
|
|
try:
|
|
print("Trying to move right")
|
|
moveResult = fh.move(player_uuid, Direction.RIGHT)
|
|
print("Successfully moved to", moveResult.player.position)
|
|
|
|
print("Trying to move right")
|
|
moveResult = fh.move(player_uuid, Direction.RIGHT)
|
|
print("Successfully moved to", moveResult.player.position)
|
|
|
|
print("Trying to move right")
|
|
moveResult = fh.move(player_uuid, Direction.RIGHT)
|
|
print("Successfully moved to", moveResult.player.position)
|
|
|
|
print("Trying to move down")
|
|
moveResult = fh.move(player_uuid, Direction.DOWN)
|
|
print("Successfully moved to", moveResult.player.position)
|
|
except PositionError:
|
|
print("Cant't move in this direction")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|