💌
This commit is contained in:
@ -3,10 +3,10 @@ import random
|
||||
from funcs import logThis
|
||||
from .loveletterDraw import DrawLove
|
||||
|
||||
class HexGame():
|
||||
class LoveLetter():
|
||||
def __init__(self,bot):
|
||||
self.bot = bot
|
||||
self.draw = DrawHex(bot)
|
||||
self.draw = DrawLove(bot)
|
||||
|
||||
# Parses command
|
||||
def parseLove(self, command, channel, user):
|
||||
@ -14,67 +14,51 @@ class HexGame():
|
||||
game = self.bot.database["loveletter games"].find_one({"_id":channel})
|
||||
|
||||
if command == "" or command == " ":
|
||||
logThis(str(user)+"started a Love Letter game with loveStart(). "+)
|
||||
return self.loveStart(channel,user,commands[1]) # commands[1] is the opponent
|
||||
|
||||
elif commands[0] == "start":
|
||||
# Starting a game
|
||||
if len(commands) == 1: # if the commands is "!hex start", the opponent is Gwendolyn at difficulty 2
|
||||
commands.append("2")
|
||||
logThis("Starting a hex game with hexStart(). "+str(user)+" challenged "+commands[1])
|
||||
return self.hexStart(channel,user,commands[1]) # commands[1] is the opponent
|
||||
logThis(str(user)+" started a Love Letter game with loveStart(). ")
|
||||
return self.loveStart(channel)
|
||||
|
||||
# If using a command with no game, return error
|
||||
elif game == None:
|
||||
return "There's no game in this channel", False, False, False, False
|
||||
return "There's no game in this channel", False, False
|
||||
|
||||
# Joining the game
|
||||
elif commands[0] == "join":
|
||||
if game["round"] == 0:
|
||||
if user not in game["player hands"]:
|
||||
# Deal cards
|
||||
card = game["deck"].pop()
|
||||
username = self.bot.funcs.getName(user)
|
||||
game["player hands"][username] = card
|
||||
game["discard piles"][username] = []
|
||||
self.bot.database["loveletter games"].replace_one({"_id":channel},game)
|
||||
return username+" joined the game! Type \"!loveletter begin\" once all players have joined.", False, False
|
||||
else:
|
||||
return "You're already playing!", False, False
|
||||
else:
|
||||
return "It's too late to join", False, False
|
||||
|
||||
# Beginning the game
|
||||
elif commands[0] == "begin":
|
||||
if user in game["player hands"]:
|
||||
if len(game["player hands"]) > 1:
|
||||
pass
|
||||
else:
|
||||
return "AI functionality hasn't been implemented yet. Get another player to join!", False, False
|
||||
else:
|
||||
return "You can't begin a game, when you're not a player!", False, False
|
||||
|
||||
# Stopping the game
|
||||
elif commands[0] == "stop":
|
||||
if user in game["players"]:
|
||||
return "Ending game.", False, False, True, False
|
||||
if user in game["player hands"]:
|
||||
return "Ending game.", False, False
|
||||
else:
|
||||
return "You can't end a game where you're not a player.", False, False, False, False
|
||||
|
||||
# Placing a piece
|
||||
elif commands[0] == "place":
|
||||
try:
|
||||
return self.placeHex(channel,commands[1], user)
|
||||
except:
|
||||
return "I didn't get that. To place a piece use \"!hex place [position]\". A valid position is e.g. \"E2\".", False, False, False, False
|
||||
|
||||
# Undo
|
||||
elif commands[0] == "undo":
|
||||
return self.undoHex(channel, user)
|
||||
|
||||
# Surrender
|
||||
elif commands[0] == "surrender":
|
||||
players = game["players"]
|
||||
if user in players:
|
||||
opponent = (players.index(user) + 1) % 2
|
||||
self.bot.database["hex games"].update_one({"_id":channel},{"$set":{"winner":opponent + 1}})
|
||||
return "{} surrendered. That means {} won! Adding 30 Gwendobucks to their account.".format(self.bot.funcs.getName(user),self.bot.funcs.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":
|
||||
if len(game["gameHistory"]) == 1: # Only after the first move
|
||||
self.bot.database["hex games"].update_one({"_id":channel},
|
||||
{"$set":{"players":game["players"][::-1]}}) # Swaps their player-number
|
||||
|
||||
# Swaps the color of the hexes on the board drawing:
|
||||
self.draw.drawSwap(channel)
|
||||
player2 = game["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
|
||||
return "You can't end a game where you're not a player.", 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
|
||||
return "I didn't get that. Use \"!loveletter\" to start a game or \"!loveletter join\" to join a game. ", False, False
|
||||
|
||||
# Starts the game
|
||||
def loveStart(self, channel, user, opponent):
|
||||
def loveStart(self, channel):
|
||||
game = self.bot.database["loveletter games"].find_one({"_id":channel})
|
||||
|
||||
if game == None:
|
||||
@ -85,7 +69,7 @@ class HexGame():
|
||||
cardAside = deck[0]
|
||||
del deck[0] # The card that is set aside
|
||||
|
||||
newGame = {"_id":channel,"user hands": {},"discard piles":{},"deck":deck,"round":0,"cardAside":cardAside}
|
||||
newGame = {"_id":channel,"player hands": {},"discard piles":{},"deck":deck,"round":0,"cardAside":cardAside}
|
||||
|
||||
self.bot.database["loveletter games"].insert_one(newGame)
|
||||
|
||||
|
@ -140,4 +140,4 @@
|
||||
|
||||
18 - Love Letter
|
||||
1800 - Unspecified error
|
||||
1801 - Error parsing command
|
||||
1801 - Error parsing command
|
||||
|
Reference in New Issue
Block a user