K
K
KeterVik2018-06-18 12:17:18
Python
KeterVik, 2018-06-18 12:17:18

How to implement a network for playing in the terminal?

There are two players. The action of each player is limited to one command in the terminal. That is, while player1 enters a command, player2 is blocked from entering the keyboard and entering commands. After each press of Enter, data is sent to another player and this is how players exchange data, but how to do this? For example, I need the players to enter the host and port into the terminal (that is, the game by agreement), and thus connect to each other.
All this needs to be implemented for the tic-tac-toe game, which is completely ready, but only with the "on one keyboard" mode. Everything works in the terminal, without gui, only symbols and commands. Written, as is already clear, in Python.
In order to understand, I read this article https://www.ibm.com/developerworks/ru/library/l-py...but didn't understand much. I don't know how to implement checking and connecting players, as well as what data players need to send to each other. In this case, the data is one single file (module) - a picture of characters, with variables, where the data is written.
UPD. As I see it all:
- two addresses are connected to the same port
- one of them is overlaid with a method that blocks the keyboard
- player1, whose keyboard is not blocked, enters a command and sends all files to player2
- player1 is overlaid with a method that blocks the keyboard
- player2 receives all the necessary game files and he is given the opportunity to enter commands
- ...
— *after the victory of one of the parties, the game is frozen, all players are given the opportunity to enter commands
*Freezing the game has already been implemented. Entering certain commands after the victory is also there.
That is, what is the point - the player after the command simply transfers all his files to another player and his keyboard is blocked and so on in a circle. How to implement this, I do not know.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question