Usage¶
Server¶
The server is built starting from the Django development server, a lightweight Web server written purely in Python. It has been used in order to test and develop things rapidly without having to deal with configuring a production server – such as Apache. So, in order to start the server, you have to launch the following django command:
python3 manage.py runserver
This command starts the development server on localhost
at port 8000. It is also possible to choose the port:
python3 manage.py runserver 8080
It is now possible to navigate the REST API and send requests to the server. To check all the available endpoints and how to use them refer to the REST API Reference.
For example you can start creating a new user:
POST http://127.0.0.1:8000/api/users/sign_up/
In the request body you can simply pass:
{
"username": "cool-username",
"password": "strong-password"
}
Client¶
A simple Python client has been developed to test the REST API server and the Websocket server. It assumes that you're running the server at port 8000.
Launch the client with the following command:
python3 client\pygame_client.py
python3 client/pygame_client.py
The client allows you to login into the system, create or join a match and play against other users. Obviously you can execute two or more instances of the client to simulate more users connected to the system.
Once you are in a match, and the pong screen is shown, you can play the game using the following keyboard commands:
Game controls
- W for moving the paddle upwards,
- S for moving the paddle downwards,
- Left Shift for accelerating the paddle movements.
Enjoy your game! :)