Skip to content

Commit 923310a

Browse files
committed
API (constructor): make parameter token optional
1 parent e1c2700 commit 923310a

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ Module `game_server_api` provides an API for communicating with the server. It a
4848
- passively observe another player
4949
- start a new game within the current session
5050

51-
Here is a simplified example of the API usage:
51+
Here is a short demo of the API usage:
5252

5353
```py
5454
from game_server_api import GameServerAPI
5555

5656
game = GameServerAPI(server='127.0.0.1', port=4711, game='TicTacToe', players=2,
57-
token='mygame') # pass 'auto' to auto-join a session
57+
token='mygame') # pass 'auto' to auto-join a session (default)
5858

5959
my_id = game.join() # start/join a session - each client is assigned an ID
6060
game.move(position=5) # perform a move - the function accepts keyword arguments (**kwargs)

client/game_server_api.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,16 @@ class GameServerAPI:
4646
This class provides API functions to communicate with the game server.
4747
"""
4848

49-
def __init__(self, server, port, game, token, players=None, name=''):
49+
def __init__(self, server, port, game, token='auto', players=None, name=''):
5050
"""
5151
Parameters needed in order to connect to the server and to start or join
5252
a game session are passed to this constructor. Parameter game specifies
5353
the game to be started. It corresponds to the name of the game class on
5454
the server. To be able to join a specific game session, all participants
5555
need to agree on a token and pass it to the constructor. The token is
56-
used to identify the game session. It can be any string. Alternatively,
57-
you can have the server automatically assign you to a session by passing
58-
the string 'auto' as the token. Refer to function join for more
56+
used to identify the game session. Alternatively, you can have the
57+
server automatically assign you to a session by passing 'auto' as the
58+
token (this is the default). Refer to function join for more
5959
information.
6060
6161
The optional parameter players is required by function join in order to
@@ -73,7 +73,7 @@ def __init__(self, server, port, game, token, players=None, name=''):
7373
server (str): server
7474
port (int): port number
7575
game (str): name of the game
76-
token (str): name of the game session, 'auto' for automatic assignment
76+
token (str): name of the session (optional), 'auto' for auto-join (default)
7777
players (int): total number of players (optional)
7878
name (str): player name (optional)
7979

0 commit comments

Comments
 (0)