stores player as R or Y not an entire ANSI string lmao
This commit is contained in:
parent
c002cebc8e
commit
7b2936ed02
28
main.py
28
main.py
|
|
@ -9,12 +9,11 @@ def clear():
|
||||||
os.system('clear')
|
os.system('clear')
|
||||||
|
|
||||||
def printBoard(board):
|
def printBoard(board):
|
||||||
|
|
||||||
rows = []
|
rows = []
|
||||||
for i in range(6):
|
for i in range(6):
|
||||||
row = ""
|
row = ""
|
||||||
for column in board:
|
for column in board:
|
||||||
row += "| " + column[i] + " "
|
row += "| " + colourTile(column[i]) + " "
|
||||||
row += "|"
|
row += "|"
|
||||||
rows.append(row)
|
rows.append(row)
|
||||||
|
|
||||||
|
|
@ -24,10 +23,8 @@ def printBoard(board):
|
||||||
for row in rows:
|
for row in rows:
|
||||||
toPrint += (row + "\n")
|
toPrint += (row + "\n")
|
||||||
|
|
||||||
print(f"""
|
line = '=' * (len(board) * 4 + 1)
|
||||||
=============================
|
print(f"{line}\n{toPrint[:-1]}\n{line}")
|
||||||
{toPrint[:-1]}
|
|
||||||
=============================""")
|
|
||||||
|
|
||||||
def getIntInput(prompt):
|
def getIntInput(prompt):
|
||||||
success = False
|
success = False
|
||||||
|
|
@ -44,6 +41,14 @@ def getIntInput(prompt):
|
||||||
|
|
||||||
return inp
|
return inp
|
||||||
|
|
||||||
|
def colourTile(tile):
|
||||||
|
if tile == 'R':
|
||||||
|
return f"{Colours.BOLD}{Colours.RED}R{Colours.END}"
|
||||||
|
elif tile == 'Y':
|
||||||
|
return f"{Colours.BOLD}{Colours.YELLOW}Y{Colours.END}"
|
||||||
|
else:
|
||||||
|
return "O"
|
||||||
|
|
||||||
def checkWin(board):
|
def checkWin(board):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
@ -64,7 +69,7 @@ board = [
|
||||||
]
|
]
|
||||||
|
|
||||||
playing = True
|
playing = True
|
||||||
turn = f'{Colours.RED}{Colours.BOLD}O{Colours.END}'
|
player = 'R'
|
||||||
|
|
||||||
while playing:
|
while playing:
|
||||||
clear()
|
clear()
|
||||||
|
|
@ -73,7 +78,7 @@ while playing:
|
||||||
tile = ""
|
tile = ""
|
||||||
while tile == "":
|
while tile == "":
|
||||||
try:
|
try:
|
||||||
chosenColumn = getIntInput(f"{turn} where do you want to drop your tile? 0-6.\n>>> ")
|
chosenColumn = getIntInput(f"{colourTile(player)} where do you want to drop your tile? 0-6.\n>>> ")
|
||||||
tile = board[chosenColumn].index("O")
|
tile = board[chosenColumn].index("O")
|
||||||
break
|
break
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
|
@ -87,6 +92,9 @@ while playing:
|
||||||
print("You chose a column outside of the board. Try again")
|
print("You chose a column outside of the board. Try again")
|
||||||
tile = ""
|
tile = ""
|
||||||
|
|
||||||
board[chosenColumn][tile] = turn
|
board[chosenColumn][tile] = player
|
||||||
|
|
||||||
turn = f'{Colours.YELLOW}{Colours.BOLD}O{Colours.END}' if turn == f'{Colours.RED}{Colours.BOLD}O{Colours.END}' else f'{Colours.RED}{Colours.BOLD}O{Colours.END}'
|
if player == 'R':
|
||||||
|
player = 'Y'
|
||||||
|
else:
|
||||||
|
player = 'R'
|
||||||
Loading…
Reference in New Issue
Block a user