Skip to content

Commit bb01d34

Browse files
committed
Add example for basic API usage
1 parent 282bda7 commit bb01d34

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,20 @@ Module `game_server_api` provides an API for communicating with the server. It a
4545
- passively observe another player
4646
- start a new game within the current session
4747

48-
The [API module](client/game_server_api.py) itself is documented in detail. You can also take a look at the demo clients and the wiki.
48+
Here is a simplified example of the API usage:
49+
50+
```py
51+
from game_server_api import GameServerAPI
52+
53+
game = GameServerAPI(server='127.0.0.1', port=4711, game='TicTacToe', token='mygame', players=2)
54+
55+
my_id = game.join() # starting/joining a game - each client is assigned an ID
56+
game.move(position=5) # performing a move - the function accepts keyword arguments (**kwargs)
57+
state = game.state() # returns a dictionary representing the game state,
58+
# including the ID of the current player(s)
59+
```
60+
61+
The [API module](client/game_server_api.py) itself is documented in detail. You can also take a look at the demo clients and the [wiki](https://github.com/feberts/python-game-server/wiki).
4962

5063
## Adding new games
5164

0 commit comments

Comments
 (0)