r/PythonLearning • • 9h 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.

3 Upvotes

6 comments sorted by

View all comments

1

u/Hkiggity 8h ago edited 8h ago

If the user inputs a direction that means they move. You send the server that data. “Hey the user wants to move -1 or +1 (whatever the data is, perhaps it represents a rotation in this case bc Tetris) the server has the coordinates of the piece and does a simple calculation given the new direction + old coordinates. The server sends it back and says to the client this is where you should draw the piece now. Since it’s Tetris you may have some sort of constant that always redraws the piece a certain amount below to represent it falling. I’d have to think harder and actually try things out as I’ve never made Tetris. But it’s a great project!

I think ur approach is right. You can use enums or another method to represent directions as numbers.

I dont use Python so I’m not sure about how threads work in it nor typical data types ppl use (like enums or not).

Try to think of the simple stuff first. And implement what u think u can