🚧 Started on 4 in a row game

This commit is contained in:
NikolajDanger
2020-07-28 22:10:23 +02:00
parent 44a6ef65ca
commit 94c6289cc1
10 changed files with 148 additions and 10 deletions

65
funcs/games/fourInARow.py Normal file
View File

@ -0,0 +1,65 @@
import json
from . import draw4InARow
def fourInARowStart(channel):
with open("resources/games/games.json", "r") as f:
data = json.load(f)
if channel not in data["4 in a row games"]:
board = [ [ 0 for i in range(7) ] for j in range(6) ]
data["4 in a row games"][channel] = {"board": board}
with open("resources/games/games.json", "w") as f:
json.dump(data,f,indent=4)
draw4InARow.drawImage(channel)
return "Started game", True
else:
return "There's already a 4 in a row game going on in this channel", False
def placePiece(channel : str,player : int,column : int):
with open("resources/games/games.json", "r") as f:
data = json.load(f)
if channel in data["4 in a row games"]:
board = data["4 in a row games"][channel]["board"]
placementx, placementy = -1, column
for x in range(len(board)):
if board[x][column] == 0:
placementx = x
if placementx != -1:
board[placementx][placementy] = player
data["4 in a row games"][channel]["board"] = board
with open("resources/games/games.json", "w") as f:
json.dump(data,f,indent=4)
draw4InARow.drawImage(channel)
return "Placed the piece", True
else:
return "There isn't any room in that column", True
else:
return "There's no game in this channel", False
def decipherCommand(command, channel, user):
if command == "" or command == " ":
return fourInARowStart(channel)
elif command.startswith(" place"):
commands = command.split(" ")
try:
return placePiece(channel,int(commands[2]),int(commands[3])-1)
except:
return "I didn't quite get that", False
else:
return "I didn't get that", False