Started on Hex. Also fourinarow difficulty

Difficulty added when starting a game of fourinarow, on a scale of 1-5.
The Hex functions are added, but right now they are mostly copies of the fourinarow functions, and do not work
This commit is contained in:
jona605a
2020-08-04 10:18:30 +02:00
parent ee53f87c32
commit 5a656b1fb2
6 changed files with 452 additions and 21 deletions

View File

@ -21,6 +21,79 @@ blackjackDecks = 4
# Variable for reacting to messages
meanWords = ["stupid", "bitch", "fuck", "dumb", "idiot"]
# Runs Hex
async def hex(channel,command,user):
try:
response, showImage, deleteImage, gameDone, gwendoTurn = parseHex(command,str(channel),user)
except:
logThis("Error parsing command (error code 1510)")
await channel.send(response)
logThis(response,str(channel))
if showImage:
if deleteImage:
try:
oldImage = await deleteMessage("hex"+str(channel),channel)
except:
logThis("Error deleting old image (error code 1501)")
oldImage = await channel.send(file = discord.File("resources/games/hexBoards/board"+str(channel)+".png"))
if gameDone == False:
if gwendoTurn:
try:
response, showImage, deleteImage, gameDone, gwendoTurn = hexAI(str(channel))
except:
logThis("AI error (error code 1420)")
await channel.send(response)
logThis(response,str(channel))
if showImage:
if deleteImage:
await oldImage.delete()
oldImage = await channel.send(file = discord.File("resources/games/4InARowBoards/board"+str(channel)+".png"))
if gameDone == False:
with open("resources/games/oldImages/fourInARow"+str(channel), "w") as f:
f.write(str(oldImage.id))
try:
reactions = ["1","2","3","4","5","6","7"]
for reaction in reactions:
await oldImage.add_reaction(reaction)
except:
logThis("Image deleted before I could react to all of them")
else:
with open("resources/games/oldImages/fourInARow"+str(channel), "w") as f:
f.write(str(oldImage.id))
try:
reactions = ["1","2","3","4","5","6","7"]
for reaction in reactions:
await oldImage.add_reaction(reaction)
except:
logThis("Image deleted before I could react to all of them")
# else:
# with open("resources/games/oldImages/fourInARow"+str(channel), "w") as f:
# f.write(str(oldImage.id))
if gameDone:
with open("resources/games/games.json", "r") as f:
data = json.load(f)
try:
with open("resources/games/oldImages/fourInARow"+str(channel), "r") as f:
oldImage = await channel.fetch_message(int(f.read()))
await oldImage.delete()
except:
logThis("The old image was already deleted")
winner = data["4 in a row games"][str(channel)]["winner"]
if winner != 0:
addMoney(data["4 in a row games"][str(channel)]["players"][winner-1].lower(),20)
with open("resources/games/games.json", "r") as f:
data = json.load(f)
deleteGame("4 in a row games",str(channel))
# Runs Four in a Row
async def fiar(channel,command,user):
try:
@ -673,8 +746,14 @@ async def parseCommands(message,content):
await fiar(message.channel,command,message.author.display_name)
except:
logThis("Something went wrong (error code 1400)")
# Runs a game of Hex
elif content.startswith("hex"):
try:
command = content.replace("hex","")
await hex(message.channel,command,message.author.display_name)
except:
logThis("Something went wrong (error code 1500)")
# Not a command
else: