Compare commits
1 Commits
10290dba54
...
edca936325
| Author | SHA1 | Date | |
|---|---|---|---|
| edca936325 |
@ -18,23 +18,23 @@ async function main() {
|
|||||||
console.log("Initial player position is", game.player.position);
|
console.log("Initial player position is", game.player.position);
|
||||||
|
|
||||||
let moveResult;
|
let moveResult;
|
||||||
const playerUuid = game.player.uuid;
|
const playerId = game.player.id;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.log("Trying to move right");
|
console.log("Trying to move right");
|
||||||
moveResult = await fh.move(playerUuid, sdk.Direction.RIGHT);
|
moveResult = await fh.move(playerId, sdk.Direction.RIGHT);
|
||||||
console.log("Successfully moved to", moveResult.player.position);
|
console.log("Successfully moved to", moveResult.player.position);
|
||||||
|
|
||||||
console.log("Trying to move right");
|
console.log("Trying to move right");
|
||||||
moveResult = await fh.move(playerUuid, sdk.Direction.RIGHT);
|
moveResult = await fh.move(playerId, sdk.Direction.RIGHT);
|
||||||
console.log("Successfully moved to", moveResult.player.position);
|
console.log("Successfully moved to", moveResult.player.position);
|
||||||
|
|
||||||
console.log("Trying to move right");
|
console.log("Trying to move right");
|
||||||
moveResult = await fh.move(playerUuid, sdk.Direction.RIGHT);
|
moveResult = await fh.move(playerId, sdk.Direction.RIGHT);
|
||||||
console.log("Successfully moved to", moveResult.player.position);
|
console.log("Successfully moved to", moveResult.player.position);
|
||||||
|
|
||||||
console.log("Trying to move down");
|
console.log("Trying to move down");
|
||||||
moveResult = await fh.move(playerUuid, sdk.Direction.DOWN);
|
moveResult = await fh.move(playerId, sdk.Direction.DOWN);
|
||||||
console.log("Successfully moved to", moveResult.player.position);
|
console.log("Successfully moved to", moveResult.player.position);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err instanceof sdk.PositionError) {
|
if (err instanceof sdk.PositionError) {
|
||||||
|
|||||||
@ -76,8 +76,8 @@ class FairHopper {
|
|||||||
return await r.json();
|
return await r.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
async getPlayerInfo(playerUuid) {
|
async getPlayerInfo(playerId) {
|
||||||
const r = await fetch(this.formatUrl(`/player/${playerUuid}`), {
|
const r = await fetch(this.formatUrl(`/player/${playerId}`), {
|
||||||
headers: this.defaultHeaders,
|
headers: this.defaultHeaders,
|
||||||
});
|
});
|
||||||
switch (r.status) {
|
switch (r.status) {
|
||||||
@ -89,24 +89,24 @@ class FairHopper {
|
|||||||
return await r.json();
|
return await r.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
async moveLeft(playerUuid) {
|
async moveLeft(playerId) {
|
||||||
return await this.move(playerUuid, "left");
|
return await this.move(playerId, "left");
|
||||||
}
|
}
|
||||||
|
|
||||||
async moveRight(playerUuid) {
|
async moveRight(playerId) {
|
||||||
return await this.move(playerUuid, "right");
|
return await this.move(playerId, "right");
|
||||||
}
|
}
|
||||||
|
|
||||||
async moveUp(playerUuid) {
|
async moveUp(playerId) {
|
||||||
return await this.move(playerUuid, "up");
|
return await this.move(playerId, "up");
|
||||||
}
|
}
|
||||||
|
|
||||||
async moveDown(playerUuid) {
|
async moveDown(playerId) {
|
||||||
return await this.move(playerUuid, "down");
|
return await this.move(playerId, "down");
|
||||||
}
|
}
|
||||||
|
|
||||||
async move(playerUuid, direction) {
|
async move(playerId, direction) {
|
||||||
const url = this.formatUrl(`/player/${playerUuid}/move/${direction}`);
|
const url = this.formatUrl(`/player/${playerId}/move/${direction}`);
|
||||||
const r = await fetch(url, {
|
const r = await fetch(url, {
|
||||||
method: "post",
|
method: "post",
|
||||||
headers: this.defaultHeaders,
|
headers: this.defaultHeaders,
|
||||||
|
|||||||
@ -18,23 +18,23 @@ def main() -> None:
|
|||||||
print()
|
print()
|
||||||
print("Initial player position is", game.player.position)
|
print("Initial player position is", game.player.position)
|
||||||
|
|
||||||
player_uuid = game.player.uuid
|
player_id = game.player.id
|
||||||
|
|
||||||
try:
|
try:
|
||||||
print("Trying to move right")
|
print("Trying to move right")
|
||||||
moveResult = fh.move(player_uuid, Direction.RIGHT)
|
moveResult = fh.move(player_id, Direction.RIGHT)
|
||||||
print("Successfully moved to", moveResult.player.position)
|
print("Successfully moved to", moveResult.player.position)
|
||||||
|
|
||||||
print("Trying to move right")
|
print("Trying to move right")
|
||||||
moveResult = fh.move(player_uuid, Direction.RIGHT)
|
moveResult = fh.move(player_id, Direction.RIGHT)
|
||||||
print("Successfully moved to", moveResult.player.position)
|
print("Successfully moved to", moveResult.player.position)
|
||||||
|
|
||||||
print("Trying to move right")
|
print("Trying to move right")
|
||||||
moveResult = fh.move(player_uuid, Direction.RIGHT)
|
moveResult = fh.move(player_id, Direction.RIGHT)
|
||||||
print("Successfully moved to", moveResult.player.position)
|
print("Successfully moved to", moveResult.player.position)
|
||||||
|
|
||||||
print("Trying to move down")
|
print("Trying to move down")
|
||||||
moveResult = fh.move(player_uuid, Direction.DOWN)
|
moveResult = fh.move(player_id, Direction.DOWN)
|
||||||
print("Successfully moved to", moveResult.player.position)
|
print("Successfully moved to", moveResult.player.position)
|
||||||
except PositionError:
|
except PositionError:
|
||||||
print("Cant't move in this direction")
|
print("Cant't move in this direction")
|
||||||
|
|||||||
@ -42,7 +42,7 @@ class Destination(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
class Player(BaseModel):
|
class Player(BaseModel):
|
||||||
uuid: str
|
id: str
|
||||||
name: str
|
name: str
|
||||||
active: bool
|
active: bool
|
||||||
position: Position
|
position: Position
|
||||||
@ -95,8 +95,8 @@ class FairHopper:
|
|||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
return GameInfoResponse(**r.json())
|
return GameInfoResponse(**r.json())
|
||||||
|
|
||||||
def get_player_info(self, uuid: str) -> PlayerInfoResponse:
|
def get_player_info(self, id: str) -> PlayerInfoResponse:
|
||||||
r = requests.get(self.format_url(f"/player/{uuid}"))
|
r = requests.get(self.format_url(f"/player/{id}"))
|
||||||
|
|
||||||
if r.status_code == 403:
|
if r.status_code == 403:
|
||||||
raise PlayerInactiveError()
|
raise PlayerInactiveError()
|
||||||
@ -107,20 +107,20 @@ class FairHopper:
|
|||||||
|
|
||||||
return PlayerInfoResponse(**r.json())
|
return PlayerInfoResponse(**r.json())
|
||||||
|
|
||||||
def move_left(self, uuid: str) -> PlayerInfoResponse:
|
def move_left(self, id: str) -> PlayerInfoResponse:
|
||||||
return self.move(uuid, Direction.LEFT)
|
return self.move(id, Direction.LEFT)
|
||||||
|
|
||||||
def move_right(self, uuid: str) -> PlayerInfoResponse:
|
def move_right(self, id: str) -> PlayerInfoResponse:
|
||||||
return self.move(uuid, Direction.RIGHT)
|
return self.move(id, Direction.RIGHT)
|
||||||
|
|
||||||
def move_up(self, uuid: str) -> PlayerInfoResponse:
|
def move_up(self, id: str) -> PlayerInfoResponse:
|
||||||
return self.move(uuid, Direction.UP)
|
return self.move(id, Direction.UP)
|
||||||
|
|
||||||
def move_down(self, uuid: str) -> PlayerInfoResponse:
|
def move_down(self, id: str) -> PlayerInfoResponse:
|
||||||
return self.move(uuid, Direction.DOWN)
|
return self.move(id, Direction.DOWN)
|
||||||
|
|
||||||
def move(self, uuid: str, direction: Direction) -> PlayerInfoResponse:
|
def move(self, id: str, direction: Direction) -> PlayerInfoResponse:
|
||||||
path = f"/player/{uuid}/move/{direction}"
|
path = f"/player/{id}/move/{direction}"
|
||||||
r = requests.post(self.format_url(path))
|
r = requests.post(self.format_url(path))
|
||||||
|
|
||||||
if r.status_code == 403:
|
if r.status_code == 403:
|
||||||
|
|||||||
Reference in New Issue
Block a user