Four in a row is almost done

This commit is contained in:
NikolajDanger
2020-07-31 15:49:58 +02:00
parent 796b209a5b
commit daa2d0ddde
7 changed files with 338 additions and 31 deletions

View File

@ -4,7 +4,7 @@ from . import draw4InARow
from funcs import logThis
# Starts the game
def fourInARowStart(channel):
def fourInARowStart(channel, user, opponent):
with open("resources/games/games.json", "r") as f:
data = json.load(f)
@ -13,14 +13,14 @@ def fourInARowStart(channel):
board = [ [ 0 for i in range(7) ] for j in range(6) ]
data["4 in a row games"][channel] = {"board": board,"winner":0,"win direction":"",
"win coordinates":[0,0],"players":["",""]}
"win coordinates":[0,0],"players":[user,opponent],"turn":0}
with open("resources/games/games.json", "w") as f:
json.dump(data,f,indent=4)
draw4InARow.drawImage(channel)
return "Started game", True, False, False
return "Started game. It's "+user+"'s turn", True, False, False
else:
return "There's already a 4 in a row game going on in this channel", False, False, False
@ -42,6 +42,8 @@ def placePiece(channel : str,player : int,column : int):
if placementx != -1:
board[placementx][placementy] = player
data["4 in a row games"][channel]["board"] = board
turn = (data["4 in a row games"][channel]["turn"]+1)%2
data["4 in a row games"][channel]["turn"] = turn
with open("resources/games/games.json", "w") as f:
json.dump(data,f,indent=4)
@ -57,7 +59,7 @@ def placePiece(channel : str,player : int,column : int):
message = data["4 in a row games"][channel]["players"][won-1]+" won"
else:
gameWon = False
message = "Placed a piece"
message = "Placed a piece. It's now "+data["4 in a row games"][channel]["players"][turn]+"'s turn."
with open("resources/games/games.json", "w") as f:
json.dump(data,f,indent=4)
@ -72,8 +74,24 @@ def placePiece(channel : str,player : int,column : int):
# Parses command
def parseFourInARow(command, channel, user):
print(command)
if command == "" or command == " ":
return fourInARowStart(channel)
return "I didn't get that. \"Use !fourinarow start\" to start a game.", False, False, False
elif command.startswith(" start "):
command = command.replace(" start ","")
return fourInARowStart(channel,user,command)
elif command.startswith(" stop"):
with open("resources/games/games.json", "r") as f:
data = json.load(f)
if user in data["4 in a row games"][channel]["players"]:
return "Ending game.", False, False, True
else:
return "You can't end a game where you're not a player.", False, False, False
elif command.startswith(" place"):
commands = command.split(" ")
#try: