📝 You can now play against yourself
This commit is contained in:
@ -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)
|
||||
|
||||
|
@ -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"]
|
||||
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user