Fixed various bugs in packets.py, and rejiggered spelling_mp.py to use QuickStreamClient and QuickStreamServer.
This commit is contained in:
parent
56f53dccfe
commit
d5f984e687
3 changed files with 68 additions and 35 deletions
|
@ -57,21 +57,25 @@ def server():
|
|||
player2 = Player()
|
||||
|
||||
#print("Tell your friend to connect to " + socket.gethostbyname(socket.gethostname()))
|
||||
#Linus only, duct tape quick fix:
|
||||
#Linus only, duck tape quick fix:
|
||||
ip = input("Your ip addr: ")
|
||||
|
||||
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
#server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
#server_socket.bind((socket.gethostname(), 1028))
|
||||
server_socket.bind((ip, 1028))
|
||||
server_socket.listen(1)
|
||||
(client_socket, address) = server_socket.accept()
|
||||
server_socket.close()
|
||||
#server_socket.bind((ip, 1028))
|
||||
#server_socket.listen(1)
|
||||
#(client_socket, address) = server_socket.accept()
|
||||
#server_socket.close()
|
||||
|
||||
client_socket = packets.QuickStreamServer(ipAddress = ip)
|
||||
|
||||
player1.name = input("What's your name? ")
|
||||
print("Waiting for the other player...")
|
||||
|
||||
player2.name = packets.get_str(client_socket)
|
||||
packets.send_str(client_socket, player1.name)
|
||||
#player2.name = packets.get_str(client_socket)
|
||||
player2.name = client_socket.getString()[0]
|
||||
#packets.send_str(client_socket, player1.name)
|
||||
client_socket.sendString(player1.name)
|
||||
|
||||
while(min(player1.hp, player2.hp) > 0):
|
||||
print(player1.name + ": " + str(player1.hp) + " hp", end = " ")
|
||||
|
@ -79,16 +83,21 @@ def server():
|
|||
else: print()
|
||||
spell1, word1 = player1.cast_spell()
|
||||
print("Waiting for " + player2.name + "'s move...")
|
||||
word2 = packets.get_str(client_socket)
|
||||
#word2 = packets.get_str(client_socket)
|
||||
word2 = client_socket.getString()[0]
|
||||
spell2 = spell.Spell(word2)
|
||||
spell.compare_spells(spell1, spell2)
|
||||
spell1.affect(spell2, player1)
|
||||
spell2.affect(spell1, player2)
|
||||
status.apply(player1)
|
||||
packets.send_int(client_socket, (spell2.total_damage, spell1.values["o"],
|
||||
spell1.total_damage, spell2.values["o"],
|
||||
player1.hp, player2.hp, player2.status))
|
||||
packets.send_str(client_socket, word1)
|
||||
#packets.send_int(client_socket, (spell2.total_damage, spell1.values["o"],
|
||||
# spell1.total_damage, spell2.values["o"],
|
||||
# player1.hp, player2.hp, player2.status))
|
||||
client_socket.sendShort((spell2.total_damage, spell1.values["o"],
|
||||
spell1.total_damage, spell2.values["o"],
|
||||
player1.hp, player2.hp, player2.status))
|
||||
#packets.send_str(client_socket, word1)
|
||||
client_socket.sendString(word1)
|
||||
print("\n" + player2.name + " casted \"" + word2 + "\"!\n")
|
||||
print(player1.name + " took " + str(spell2.total_damage) + " damage, and healed " + str(spell1.values["o"]) + " hp!")
|
||||
print(player1.name + " now has " + str(player1.hp) + " hp!\n")
|
||||
|
@ -105,14 +114,18 @@ def client():
|
|||
player2 = Player()
|
||||
|
||||
ip_addr = input("IP or hostname of your host: ")
|
||||
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
client_socket.connect((ip_addr, 1028))
|
||||
#client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
#client_socket.connect((ip_addr, 1028))
|
||||
|
||||
client_socket = packets.QuickStreamClient(ip_addr)
|
||||
|
||||
player2.name = input("What's your name? ")
|
||||
print("Waiting for the other player...")
|
||||
|
||||
packets.send_str(client_socket, player2.name)
|
||||
player1.name = packets.get_str(client_socket)
|
||||
#packets.send_str(client_socket, player2.name)
|
||||
client_socket.sendString(player2.name)
|
||||
#player1.name = packets.get_str(client_socket)
|
||||
player1.name = client_socket.getString()
|
||||
|
||||
while(min(player1.hp, player2.hp) > 0):
|
||||
print(player2.name + ": " + str(player2.hp) + " hp", end = " ")
|
||||
|
@ -120,13 +133,16 @@ def client():
|
|||
else: print()
|
||||
spell2, word2 = player2.cast_spell() #spell 2 ends up getting thrown out
|
||||
print("Waiting for " + player1.name + "'s move...")
|
||||
packets.send_str(client_socket, word2)
|
||||
packet = packets.get_int(client_socket)
|
||||
#packets.send_str(client_socket, word2)
|
||||
client_socket.sendString(word2)
|
||||
#packet = packets.get_int(client_socket)
|
||||
packet = client_socket.getShort()
|
||||
player1.hp = packet[4]
|
||||
player2.hp = packet[5]
|
||||
player2.status = packet[6]
|
||||
status.apply(player2)
|
||||
word1 = packets.get_str(client_socket)
|
||||
#word1 = packets.get_str(client_socket)
|
||||
word1 = client_socket.getString()
|
||||
print("\n" + player1.name + " casted \"" + word1 + "\"!\n")
|
||||
print(player1.name + " took " + str(packet[0]) + " damage, and healed " + str(packet[1]) + " hp!")
|
||||
print(player1.name + " now has " + str(packet[4]) + " hp!\n")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue