This commit is contained in:
jona605a
2020-08-11 21:31:50 +02:00
parent 71467bbe16
commit 5623accd47

View File

@ -17,6 +17,9 @@ HEX_DIRECTIONS = [(0,1),(-1,1),(-1,0),(0,-1),(1,-1),(1,0)]
# Parses command
def parseHex(command, channel, user):
commands = command.lower().split()
with open("resources/games/hexGames.json", "r") as f:
data = json.load(f)
if command == "" or command == " ":
return "I didn't get that. Use \"!hex start [opponent]\" to start a game.", False, False, False, False
@ -27,11 +30,12 @@ def parseHex(command, channel, user):
logThis("Starting a hex game with hexStart(). "+str(user)+" challenged "+commands[1])
return hexStart(channel,user,commands[1]) # commands[1] is the opponent
# If using a command with no game, return error
elif channel not in data:
return "There's no game in this channel", False, False, False, False
# Stopping the game
elif commands[0] == "stop":
with open("resources/games/hexGames.json", "r") as f:
data = json.load(f)
if user in data[channel]["players"]:
return "Ending game.", False, False, True, False
else:
@ -50,8 +54,6 @@ def parseHex(command, channel, user):
# Surrender
elif commands[0] == "surrender":
with open("resources/games/hexGames.json", "r") as f:
data = json.load(f)
players = data[channel]["players"]
if user in players:
opponent = (players.index(user) + 1) % 2
@ -62,8 +64,6 @@ def parseHex(command, channel, user):
# Swap
elif commands[0] == "swap":
with open("resources/games/hexGames.json", "r") as f:
data = json.load(f)
if len(data[channel]["gameHistory"]) == 1: # Only after the first move
data[channel]["players"] = data[channel]["players"][::-1] # Swaps their player-number
# Swaps the color of the hexes on the board drawing: