📝 You can now play against yourself

This commit is contained in:
jona605a
2020-08-11 21:57:17 +02:00
parent 5623accd47
commit f0044bcfb1
3 changed files with 16 additions and 9 deletions

View File

@@ -62,7 +62,7 @@ async def runHex(channel,command,user):
with open("resources/games/hexGames.json", "r") as f: with open("resources/games/hexGames.json", "r") as f:
data = json.load(f) data = json.load(f)
winner = data[str(channel.id)]["winner"] 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 winnings = data[str(channel.id)]["difficulty"]*10
addMoney(data[str(channel.id)]["players"][winner-1].lower(),winnings) addMoney(data[str(channel.id)]["players"][winner-1].lower(),winnings)

View File

@@ -66,9 +66,13 @@ def parseHex(command, channel, user):
elif commands[0] == "swap": elif commands[0] == "swap":
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
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: # Swaps the color of the hexes on the board drawing:
hexDraw.drawSwap(channel) 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: else:
return "You can only swap as the second player after the very first move.", False, False, False, False 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 return "That difficulty doesn't exist", False, False, False, False
except: except:
opponent = getID(opponent) opponent = getID(opponent)
if opponent == user: if opponent == None:
return "You can't play against yourself", False, False, False, False
elif opponent == None:
return "I can't find that user", False, False, False, False return "I can't find that user", False, False, False, False
else: else:
# Opponent is another player # Opponent is another player
difficulty = 3 difficulty = 3
diffText = "" diffText = ""
# board is 11x11 # board is 11x11
board = [ [ 0 for i in range(BOARDWIDTH) ] for j in range(BOARDWIDTH) ] board = [ [ 0 for i in range(BOARDWIDTH) ] for j in range(BOARDWIDTH) ]
players = [user,opponent] players = [user,opponent]
@@ -132,9 +134,14 @@ def placeHex(channel : str,position : str, user):
data = json.load(f) data = json.load(f)
if channel in data: if channel in data:
if user in data[channel]["players"]: players = data[channel]["players"]
if user in players:
turn = data[channel]["turn"] 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: if player == turn:
board = data[channel]["board"] board = data[channel]["board"]

View File

@@ -162,7 +162,7 @@ def drawSwap(channel):
# Write player names and color # Write player names and color
for p in [1,2]: for p in [1,2]:
playername = getName(data[channel]["players"][p-1]) playername = getName(data[channel]["players"][p%2])
x = X_NAME[p] x = X_NAME[p]
x -= NAME_fnt.getsize(playername)[0] if p==2 else 0 # player2's name is right-aligned x -= NAME_fnt.getsize(playername)[0] if p==2 else 0 # player2's name is right-aligned