Commit 9d7a9011 authored by Jesse Bakker's avatar Jesse Bakker

Add examples

parent fe2b7b8f
......@@ -82,6 +82,8 @@ class HandshakeParams {
}
```
[Example](examples/handshake_request.json)
_Response_:
- result: `HandshakeResult`
......@@ -93,6 +95,8 @@ class HandshakeResult {
}
```
[Example](examples/handshake_response.json)
### Rooms
#### Get rooms
......@@ -101,6 +105,8 @@ _Request_:
- method: 'getRooms'
[Example](examples/getRooms_request.json)
_Response_:
- result: `Room[]`
......@@ -119,6 +125,11 @@ class Player {
}
```
Examples:
- [3 players](examples/getRooms_3player_response.json)
- [4 players](examples/getRooms_4player_response.json)
#### Join room
_Request_:
......@@ -133,11 +144,22 @@ class JoinRoomParams {
}
```
Examples:
- [Without team](examples/joinRoom__withoutteam_request)
- [With team](examples/joinRoom_withteam_request)
_Errors_:
- Room is full: `ERROR_ROOM_FULL`
- Team is full: `ERROR_TEAM_FULL`
Examples:
- [Success](examples/joinRoom_success_response)
- [Room full](examples/joinRoom_roomfull_response)
- [Team full](examples/joinRoom_teamfull_response)
### Game
#### Start game
......@@ -153,6 +175,8 @@ class StartGameParams {
}
```
[Example](examples/startGame_notification.json)
#### Next turn
_Notification_:
......@@ -163,8 +187,8 @@ _Notification_:
```java
class NextTurnParams {
int round;
PlayerScore[];
String[][] fields;
PlayerScore[] scores;
}
class PlayerScore {
......@@ -172,9 +196,10 @@ class PlayerScore {
Optional<char> team;
int score;
}
```
[Example (starting position, 2 players)](examples/nextTurn_notification.json)
#### Make move
_Request_:
......@@ -195,11 +220,19 @@ class Coordinate {
}
```
[Example](examples/makeMove_request.json)
_Errors_:
- The lance is invalid, because it is too long, does not just contain the player's own/team's marbles or is not in a straight line: `ERROR_INVALID_LANCE`
- The given lance cannot move to the specified coordinate, e.g. because it moves more than one field over, moves off the board, or is blocked: `ERROR_INVALID_MOVE`
Examples:
- [Success](examples/makeMove_success_response.json)
- [Lance too long](examples/makeMove_invalidlance_response.json)
- [Move blocked](examples/makeMove_invalidmove_response.json)
#### End game
_Notification_:
......@@ -213,6 +246,12 @@ class EndGameParams {
}
```
Examples:
- [Player won](examples/endGame_playerwon_notification.json)
- [Team won](examples/endGame_teamwon_notification.json)
- [Draw](examples/endGame_draw_notification.json)
## Error codes
```java
......@@ -221,4 +260,4 @@ class ErrorCodes {
int ERROR_TEAM_FULL = 1;
int ERROR_INVALID_LANCE = 2;
int ERROR_INVALID_MOVE = 3;
}
\ No newline at end of file
}
{
"method": "endGame",
"params": {
"winner": null
}
}
\ No newline at end of file
{
"method": "endGame",
"params": {
"winner": 1
}
}
\ No newline at end of file
{
"method": "endGame",
"params": {
"winner": "A"
}
}
\ No newline at end of file
{
"id": 2,
"result": [
{
"id": 1,
"maxNPlayers": 3,
"playersInRoom": [
{
"id": 1,
"name": "Player 1"
},
{
"id": 2,
"name": "Player 2"
}
]
},
{
"id": 2,
"maxNPlayers": 2,
"playersInRoom": []
}
]
}
\ No newline at end of file
{
"id": 2,
"result": [
{
"id": 1,
"maxNPlayers": 4,
"playersInRoom": [
{
"id": 1,
"name": "Player 1",
"team": "A"
},
{
"id": 2,
"name": "Player 2",
"team": "B"
},
{
"id": 3,
"name": "Player 3",
"team": "B"
}
]
}
]
}
\ No newline at end of file
{
"id": 2,
"method": "getRooms",
"params": {}
}
\ No newline at end of file
{
"id": 1,
"method": "handshake",
"params": {
"name": "Player 1",
"supportedExtensions": ["chat"]
}
}
\ No newline at end of file
{
"id": 1,
"result": {
"clientId": 1,
"supportedExtensions": ["chat", "authentication"]
},
"error": null
}
\ No newline at end of file
{
"id": 4,
"error": {
"code": 0,
"message": "Room is full"
}
}
\ No newline at end of file
{
"id": 4,
"result": {}
}
\ No newline at end of file
{
"id": 4,
"error": {
"code": 1,
"message": "Team is full"
}
}
\ No newline at end of file
{
"id": 4,
"method": "joinRoom",
"params": {
"roomId": 1
}
}
\ No newline at end of file
{
"id": 4,
"method": "joinRoom",
"params": {
"roomId": 1,
"team": "A"
}
}
\ No newline at end of file
{
"id": 19,
"error": {
"code": 2,
"message": "Lance too long"
}
}
\ No newline at end of file
{
"id": 19,
"error": {
"code": 3,
"message": "Move blocked"
}
}
\ No newline at end of file
{
"id": 19,
"params": {
"lanceHead": "A1",
"lanceTail": "A3",
"newLanceHead": "A2"
}
}
\ No newline at end of file
{
"id": 19,
"result": {}
}
\ No newline at end of file
{
"method": "nextTurn",
"params": {
"round": 12,
"scores": [
{
"playerId": 0,
"score": 0
},
{
"playerId": 1,
"score": 0
}
],
"fields": [
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1],
[null, null, 1, 1, 1, null, null],
[null, null, null, null, null, null, null, null],
[null, null, null, null, null, null, null, null, null],
[null, null, null, null, null, null, null, null],
[null, null, 0, 0, 0, null, null],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0]
]
}
}
\ No newline at end of file
{
"method": "startGame",
"params": {
"players": [
{
"id": 1,
"name": "Player 1"
},
{
"id": 2,
"name": "Player 2"
}
]
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment