diff --git a/src/GameServer.ts b/src/GameServer.ts index 2ac8736..dc4c177 100644 --- a/src/GameServer.ts +++ b/src/GameServer.ts @@ -120,7 +120,7 @@ throw new Error("Invalid direction."); } - const nextTile = map.layout[i+vec[0]][j+vec[1]]; + const nextTile = map.layout[i-1+vec[0]][j+vec[1]]; state.tileID = nextTile.id; return nextTile; } diff --git a/src/GameServer.ts b/src/GameServer.ts index 2ac8736..dc4c177 100644 --- a/src/GameServer.ts +++ b/src/GameServer.ts @@ -120,7 +120,7 @@ throw new Error("Invalid direction."); } - const nextTile = map.layout[i+vec[0]][j+vec[1]]; + const nextTile = map.layout[i-1+vec[0]][j+vec[1]]; state.tileID = nextTile.id; return nextTile; } diff --git a/src/LabyrinthMiddleware.ts b/src/LabyrinthMiddleware.ts index ebc582d..ed35f2e 100644 --- a/src/LabyrinthMiddleware.ts +++ b/src/LabyrinthMiddleware.ts @@ -26,6 +26,9 @@ "Cancels a currently running game" endGame(userID: String!): Boolean! + + "Moves the user to another tile and returns that tile." + navigate(userID: String!, dir: Direction!): MazeTileQL } type Query { @@ -53,6 +56,25 @@ } } + public static StringToDirection(dir:string): Direction + { + switch(dir) { + case "none": return Direction.none; + case "top": return Direction.top; + case "left": return Direction.left; + case "bottom": return Direction.bottom; + case "right": return Direction.right; + } + } + + public static ConvertToMazeTileQL(tile: MazeTile): MazeTileQL + { + if(tile == null){ + return null; + } + return new MazeTileQL(tile); + } + public id:string; public paths:string[]; @@ -67,9 +89,12 @@ { return { createNewUserID: () => games.createNewUserID(), - currentPostition: ({userID}) => new MazeTileQL(games.currentPosition(userID)), + currentPostition: ({userID}) => MazeTileQL.ConvertToMazeTileQL(games.currentPosition(userID)), endGame: ({userID}) => games.endGame(userID), listMaps: () => games.listMaps(), + navigate: ({userID, dir}: {userID: string, dir:string}) => { + return MazeTileQL.ConvertToMazeTileQL(games.navigate(userID, MazeTileQL.StringToDirection(dir))); + }, startGame: ({userID, mapID}) => games.startGame(userID, mapID), }; }