✨ !hex swap
This commit is contained in:
@ -56,10 +56,22 @@ def parseHex(command, channel, user):
|
||||
if user in players:
|
||||
opponent = (players.index(user) + 1) % 2
|
||||
data[channel]["winner"] = opponent + 1
|
||||
return "{} surrendered. That means {} won! ".format(getName(user),getName(players[opponent])), False, False, True, False
|
||||
return "{} surrendered. That means {} won! Adding 30 Gwendobucks to their account.".format(getName(user),getName(players[opponent])), False, False, True, False
|
||||
else:
|
||||
return "You can't surrender when you're not a player.", False, False, False, False
|
||||
|
||||
# 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:
|
||||
hexDraw.drawSwap(channel)
|
||||
return "The color of both players were swapped.", True, True, False, False
|
||||
else:
|
||||
return "You can only swap as the second player after the very first move.", False, False, False, False
|
||||
|
||||
else:
|
||||
return "I didn't get that. Use \"!hex start [opponent]\" to start a game, \"!hex place [position]\" to place a piece, \"!hex undo\" to undo your last move or \"!hex stop\" to stop a current game.", False, False, False, False
|
||||
|
||||
@ -90,7 +102,7 @@ def hexStart(channel, user, opponent):
|
||||
return "I can't find that user", False, False, False, False
|
||||
else:
|
||||
# Opponent is another player
|
||||
difficulty = 5
|
||||
difficulty = 3
|
||||
diffText = ""
|
||||
|
||||
# board is 11x11
|
||||
|
@ -150,3 +150,40 @@ def drawHexPlacement(channel,player,position):
|
||||
im.save(FILEPATH)
|
||||
except:
|
||||
logThis("Error drawing new hex on board (error code 1541")
|
||||
|
||||
def drawSwap(channel):
|
||||
FILEPATH = "resources/games/hexBoards/board"+channel+".png"
|
||||
with open("resources/games/hexGames.json", "r") as f:
|
||||
data = json.load(f)
|
||||
# Opens the image
|
||||
try:
|
||||
with Image.open(FILEPATH) as im:
|
||||
d = ImageDraw.Draw(im,"RGBA")
|
||||
|
||||
# Write player names and color
|
||||
for p in [1,2]:
|
||||
playername = getName(data[channel]["players"][p-1])
|
||||
|
||||
x = X_NAME[p]
|
||||
x -= NAME_fnt.getsize(playername)[0] if p==2 else 0 # player2's name is right-aligned
|
||||
y = Y_NAME[p]
|
||||
|
||||
# Draw a half-size Hexagon to indicate the player's color
|
||||
x -= NAMEHEXPADDING # To the left of both names
|
||||
d.polygon([
|
||||
(x, y),
|
||||
(x+SMOL_WIDTH/2, y-SMOL_SIDELENGTH/2),
|
||||
(x+SMOL_WIDTH, y),
|
||||
(x+SMOL_WIDTH, y+SMOL_SIDELENGTH),
|
||||
(x+SMOL_WIDTH/2, y+SMOL_SIDELENGTH*3/2),
|
||||
(x, y+SMOL_SIDELENGTH),
|
||||
],fill = PIECECOLOR[p % 2 + 1])
|
||||
|
||||
# Save
|
||||
im.save(FILEPATH)
|
||||
except:
|
||||
logThis("Error drawing swap (error code 1542)")
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user