You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
1014 B
32 lines
1014 B
9 months ago
|
import socket
|
||
|
|
||
|
class OcaAOcaClient:
|
||
|
def __init__(self, host, port):
|
||
|
self.host = host
|
||
|
self.port = port
|
||
|
self.client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||
|
self.client_socket.connect((self.host, self.port))
|
||
|
|
||
|
def receive_message(self):
|
||
|
return self.client_socket.recv(1024).decode()
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
HOST = '192.168.100.252'
|
||
|
PORT = 2000
|
||
|
|
||
|
client = OcaAOcaClient(HOST, PORT)
|
||
|
current_turn = False
|
||
|
|
||
|
while True:
|
||
|
while current_turn == False:
|
||
|
msg = client.receive_message()
|
||
|
if msg == "your_turn":
|
||
|
current_turn = True
|
||
|
else:
|
||
|
print(msg)
|
||
|
while current_turn == True:
|
||
|
message = input("Type 'roll': ")
|
||
|
client.client_socket.sendall(message.encode('utf-8'))
|
||
|
if message.lower() == 'roll':
|
||
|
client.client_socket.sendall(message.encode('utf-8'))
|
||
|
current_turn = False
|