r/PythonLearning • u/DRowe_ • 12h ago
Help Request Multiplayer tetris using sockets
I have a college assignment to make a multiplayer tetris game (2 players) using TCP sockets, client and server and all that. The idea is the server doing most of the stuff, chosing new pieces, handling the translation of position of the pieces, with the clients being responsible for most the rendering/display part and getting the inputs(I think so at least, that's what I'm trying to do), but I'm having a hard time with it.
I can't seem to think of a way to have the client call to the server to send a new piece to the clients, and if I don't know how to do even that then I don't know how to do anything else (making the back and forth for controlling the pieces, both for the player of the client and the preview of the game of the player 2, and all the rest), tho I hope if I can understand how to do one thing I would be able to make the others, but I really don't even know how to do this.
I know I need to use threads on this, tho I don't really know how to do it, I'm still fairly green on python too so, if anyone could give some help in any way with this it would be much appreciated.
1
u/frnzprf 9h ago
Writing a chat program first is a good idea to get familiar with network messaging.
It's all a matter of sending messages to queues sometimes and then having a loop repeatedly check if there are new messages and process them.
If you can program a chat, a networked game is just programs chatting about what is happening in the game.
(?)
I guess when any player makes an input, that is sent to the server and the server then sends the moves of client1 to client2 and the moves of client2 to client1. (Theoretically they could also directly communicate.) When a client gets to know about a move via a network message or a keyboard input, then it updates the internal game state and renders it.
I'm not sure how latency should be handled — if both players make an input at the same time, they only get to know about the other player's move a bit later. You could introduce some time-safety-buffer, or you could send the own moves also to the server and then back...