🗃️ UserID's instead of display names

This commit is contained in:
Nikolaj Danger
2020-08-04 16:59:13 +02:00
parent 4bcc8cbf59
commit 2ea11eb51f
11 changed files with 201 additions and 111 deletions

View File

@ -4,7 +4,7 @@ import copy
import math
from . import fourInARowDraw
from funcs import logThis
from funcs import logThis, getName, getID
AIScores = {
"middle": 3,
@ -26,48 +26,52 @@ def fourInARowStart(channel, user, opponent):
with open("resources/games/games.json", "r") as f:
data = json.load(f)
if user.lower() != opponent.lower():
if channel not in data["4 in a row games"]:
if channel not in data["4 in a row games"]:
if opponent in ["1","2","3","4","5"]:
difficulty = int(opponent)
diffText = " with difficulty "+opponent
opponent = "Gwendolyn"
elif opponent.lower() == "gwendolyn":
difficulty = 3
diffText = " with difficulty 3"
opponent = "Gwendolyn"
else:
try:
int(opponent)
return "That difficulty doesn't exist", False, False, False, False
except:
# Opponent is another player
if opponent in ["1","2","3","4","5"]:
difficulty = int(opponent)
diffText = " with difficulty "+opponent
opponent = "Gwendolyn"
elif opponent.lower() == "gwendolyn":
difficulty = 3
diffText = " with difficulty 3"
opponent = "Gwendolyn"
else:
try:
int(opponent)
return "That difficulty doesn't exist", False, False, False, False
except:
# Opponent is another player
opponent = getID(opponent)
if opponent != None:
difficulty = 5
diffText = ""
else:
return "I can't find that user", False, False, False, False
if user == opponent:
return "You can't play against yourself", False, False, False, False
board = [ [ 0 for i in range(columnCount) ] for j in range(rowCount) ]
players = [user,opponent]
random.shuffle(players)
board = [ [ 0 for i in range(columnCount) ] for j in range(rowCount) ]
players = [user,opponent]
random.shuffle(players)
data["4 in a row games"][channel] = {"board": board,"winner":0,"win direction":"",
"win coordinates":[0,0],"players":players,"turn":0,"difficulty":difficulty}
data["4 in a row games"][channel] = {"board": board,"winner":0,"win direction":"",
"win coordinates":[0,0],"players":players,"turn":0,"difficulty":difficulty}
with open("resources/games/games.json", "w") as f:
json.dump(data,f,indent=4)
with open("resources/games/games.json", "w") as f:
json.dump(data,f,indent=4)
fourInARowDraw.drawImage(channel)
fourInARowDraw.drawImage(channel)
gwendoTurn = False
gwendoTurn = False
if players[0] == "Gwendolyn":
gwendoTurn = True
if players[0] == "Gwendolyn":
gwendoTurn = True
return "Started game against "+opponent+diffText+". It's "+players[0]+"'s turn", True, False, False, gwendoTurn
else:
return "There's already a 4 in a row game going on in this channel", False, False, False, False
return "Started game against "+getName(opponent)+diffText+". It's "+getName(players[0])+"'s turn", True, False, False, gwendoTurn
else:
return "You can't play against yourself", False, False, False, False
return "There's already a 4 in a row game going on in this channel", False, False, False, False
# Places a piece at the lowest available point in a specific column
def placePiece(channel : str,player : int,column : int):
@ -97,7 +101,7 @@ def placePiece(channel : str,player : int,column : int):
data["4 in a row games"][channel]["win direction"] = winDirection
data["4 in a row games"][channel]["win coordinates"] = winCoordinates
message = data["4 in a row games"][channel]["players"][won-1]+" won."
message = getName(data["4 in a row games"][channel]["players"][won-1])+" won."
winAmount = int(data["4 in a row games"][channel]["difficulty"])^2+5
if data["4 in a row games"][channel]["players"][won-1] != "Gwendolyn":
message += " Adding "+str(winAmount)+" GwendoBucks to their account."
@ -106,7 +110,7 @@ def placePiece(channel : str,player : int,column : int):
message = "It's a draw!"
else:
gameWon = False
message = data["4 in a row games"][channel]["players"][player-1]+" placed a piece in column "+str(column+1)+". It's now "+data["4 in a row games"][channel]["players"][turn]+"'s turn."
message = getName(data["4 in a row games"][channel]["players"][player-1])+" placed a piece in column "+str(column+1)+". It's now "+getName(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)