From afb0fa4865fc1a135514fce7f10330bdc546b7eb Mon Sep 17 00:00:00 2001 From: dorian Date: Sat, 22 Feb 2020 08:48:20 +0100 Subject: [PATCH] added some basic network protocol definitions --- README.md | 52 ++++++++++++++++++++++- src/de/itsblue/ConnectFour/GameBoard.java | 2 +- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d86e324..8232f70 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,53 @@ # Connect Four -A simple version of the popular game "connect four" written in Java. \ No newline at end of file +A simple version of the popular game "connect four" written in Java. + +## API docs +### SOCKET API +#### Basic structure +A command consists of a json encoded string of type object which starts with `````` and ends with ``````. +It contains: +- id (int): some number, the response will contain the same number +- header (int): the actual command to execute +- data (mixed): data that has to be passed with the command + +A response consists of a json encoded string of type object which starts with `````` and ends with ``````. +It contains: +- id (int): id of the command +- header (int): return code of the command (see later) +- data (midex): returned data of the command + +#### Return codes +The return codes are mostly identical with the HTTP standard codes. +However there are some additional ones as well: + +#### Enums +Some enumeration types +- PlateType + - 0: X + - 1: O + +#### Commands +- Confirm game start + - command: 1 + - requestdata: + - type: null + - responsedata: + - type: object + - def: + - 'player' + - type: PlateType + - desc: the plate type the client will use +- Insert a plate + - command: 100 + - requestdata: + - type: int + - decs: index of column to insert plate + - replydata: + - type: string + - def: + - 'ok': plate was inserted + - 'err': plate was not inserted (either index out of range or clumn full) + - 'X': insertion resulted in the winning of PlateType X + - 'O': insertion resulted in the winning of PlateType O + diff --git a/src/de/itsblue/ConnectFour/GameBoard.java b/src/de/itsblue/ConnectFour/GameBoard.java index 330f43b..cc66e2f 100644 --- a/src/de/itsblue/ConnectFour/GameBoard.java +++ b/src/de/itsblue/ConnectFour/GameBoard.java @@ -284,7 +284,7 @@ public class GameBoard extends JPanel { } /** - * Override paint function to rescale all caontainers on every repaint + * Override paint function to rescale all containers on every repaint */ @Override public void paint(Graphics g) {