doing the tests with sockets for lan multiplayer
This commit is contained in:
parent
ddeeed525d
commit
093decb9ae
11
client.py
Normal file
11
client.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import socket
|
||||
|
||||
HOST = "127.0.0.1" # The server's hostname or IP address
|
||||
PORT = 65432 # The port used by the server
|
||||
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||
s.connect((HOST, PORT))
|
||||
s.sendall(b"Hello, world")
|
||||
data = s.recv(1024)
|
||||
|
||||
print(f"Received {data!r}")
|
||||
6
main.py
6
main.py
|
|
@ -82,12 +82,8 @@ def checkWin(board, player):
|
|||
if all(board[col + i][row - i] == player for i in range(winCount)):
|
||||
return [(col + i, row - i) for i in range(winCount)]
|
||||
|
||||
# Board will be 7x6.
|
||||
|
||||
# O = open, R = red, Y = yellow
|
||||
# because this is defined like this, you could technically save a game then load from where you left off
|
||||
|
||||
# This is defined as columns, not rows. So tile 0 on column 0 is the bottom left tile of the board
|
||||
# you index like board[column][row]
|
||||
board = [
|
||||
['O', 'O', 'O', 'O', 'O', 'O'],
|
||||
['O', 'O', 'O', 'O', 'O', 'O'],
|
||||
|
|
|
|||
16
server.py
Normal file
16
server.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import socket
|
||||
|
||||
HOST = "0.0.0.0"
|
||||
PORT = 65432
|
||||
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||
s.bind((HOST, PORT))
|
||||
s.listen()
|
||||
conn, addr = s.accept()
|
||||
with conn:
|
||||
print(f"Connected by {addr}")
|
||||
while True:
|
||||
data = conn.recv(1024)
|
||||
if not data:
|
||||
break
|
||||
conn.sendall(data)
|
||||
Loading…
Reference in New Issue
Block a user