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