Implementing network-based multiplayer games is a challenge. At the same time, game development has always been a popular choice among beginners.
For this reason I have developed a lightweight server and framework for turn-based multiplayer games. It was primarily designed for a programming course where students work on projects in small groups. However, the use of the server is not limited to educational scenarios.
- Implementing clients is easy thanks to a user-friendly API.
- Adding new games is accomplished by deriving from a base class and overriding its methods.
Here is a short demo of the API usage:
from game_server_api import GameServerAPI, IllegalMove
game = GameServerAPI(server='127.0.0.1', port=4711,
game='Yahtzee', session='mygame', players=3)
my_id = game.join() # start/join a session
state = game.state() # returns a dictionary
while not state['gameover']:
# print game board here
if my_id in state['current']: # my turn
pos = None
# read user input here
try:
game.move(position=pos) # perform a move (**kwargs)
except IllegalMove as e:
# something went wrong
else:
# opponent's turn
state = game.state()
# end of game
I'm interested in any feedback. Is this project worth putting more work into? So far, it's been fun to work on, and I've learned a lot. But do you think there's an audience for this kind of project?
By the way, here it is. It's open source: github.com/feberts/python-game-server
Top comments (0)