diff --git a/funcs/games/gameLoops.py b/funcs/games/gameLoops.py index db6564b..1a9527c 100644 --- a/funcs/games/gameLoops.py +++ b/funcs/games/gameLoops.py @@ -62,7 +62,7 @@ async def runHex(channel,command,user): with open("resources/games/hexGames.json", "r") as f: data = json.load(f) winner = data[str(channel.id)]["winner"] - if winner != 0: + if winner != 0 and data[channel]["players"][0] != data[channel]["players"][1]: # player1 != player2 winnings = data[str(channel.id)]["difficulty"]*10 addMoney(data[str(channel.id)]["players"][winner-1].lower(),winnings) diff --git a/funcs/games/hex.py b/funcs/games/hex.py index 1c7cc12..4295fc0 100644 --- a/funcs/games/hex.py +++ b/funcs/games/hex.py @@ -66,9 +66,13 @@ def parseHex(command, channel, user): elif commands[0] == "swap": if len(data[channel]["gameHistory"]) == 1: # Only after the first move data[channel]["players"] = data[channel]["players"][::-1] # Swaps their player-number + with open("resources/games/hexGames.json", "w") as f: + json.dump(data,f,indent=4) # Swaps the color of the hexes on the board drawing: hexDraw.drawSwap(channel) - return "The color of both players were swapped.", True, True, False, False + player2 = data[channel]["players"][1] + gwendoTurn = (player2 == "Gwendolyn") + return "The color of both players were swapped. It is now {}'s turn".format(player2), True, True, False, gwendoTurn else: return "You can only swap as the second player after the very first move.", False, False, False, False @@ -96,15 +100,13 @@ def hexStart(channel, user, opponent): return "That difficulty doesn't exist", False, False, False, False except: opponent = getID(opponent) - if opponent == user: - return "You can't play against yourself", False, False, False, False - elif opponent == None: + if opponent == None: return "I can't find that user", False, False, False, False else: # Opponent is another player difficulty = 3 diffText = "" - + # board is 11x11 board = [ [ 0 for i in range(BOARDWIDTH) ] for j in range(BOARDWIDTH) ] players = [user,opponent] @@ -132,9 +134,14 @@ def placeHex(channel : str,position : str, user): data = json.load(f) if channel in data: - if user in data[channel]["players"]: + players = data[channel]["players"] + if user in players: turn = data[channel]["turn"] - player = data[channel]["players"].index(user)+1 + if players[0] == players[1]: + player = turn + else: + player = players.index(user)+1 + if player == turn: board = data[channel]["board"] diff --git a/funcs/games/hexDraw.py b/funcs/games/hexDraw.py index 1a6d360..f457a01 100644 --- a/funcs/games/hexDraw.py +++ b/funcs/games/hexDraw.py @@ -162,7 +162,7 @@ def drawSwap(channel): # Write player names and color for p in [1,2]: - playername = getName(data[channel]["players"][p-1]) + playername = getName(data[channel]["players"][p%2]) x = X_NAME[p] x -= NAME_fnt.getsize(playername)[0] if p==2 else 0 # player2's name is right-aligned