Skip to content

Commit c0fe316

Browse files
committed
Add usage instructions to README
1 parent bd3446c commit c0fe316

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,47 @@
44

55
The Java client library for [CodeGame](https://code-game.org).
66

7+
## Installation
8+
9+
Add this to your *pom.xml*:
10+
```xml
11+
<dependency>
12+
<groupId>org.codegame</groupId>
13+
<artifactId>client</artifactId>
14+
<version>0.1.0</version>
15+
</dependency>
16+
```
17+
18+
## Usage
19+
20+
```java
21+
// Create a new game socket.
22+
var socket = new GameSocket("games.code-game.org/example");
23+
24+
// Create a new private game.
25+
var game = socket.createGame(false, false, null);
26+
27+
// Join a game.
28+
socket.join(game.id, "username");
29+
30+
// Spectate a game.
31+
socket.spectate(game.id);
32+
33+
// Connect with an existing session.
34+
socket.restoreSession("username");
35+
36+
// Register an event listener for the `my_event` event.
37+
socket.on("my_event", MyEvent.class, (data) -> {
38+
// TODO: do something with `data`
39+
});
40+
41+
// Send a `hello_world` command.
42+
socket.send("hello_world", new HelloWorldCmd("Hello, World!"));
43+
44+
// Wait until the connection is closed.
45+
socket.listen();
46+
```
47+
748
## License
849

950
MIT License

0 commit comments

Comments
 (0)