made pretty. cleaned i think

This commit is contained in:
Vincent Rodley 2025-08-01 21:57:54 +12:00
parent 91b2ef653e
commit f5615b0bd6

32
main.py
View File

@ -4,28 +4,10 @@ from colours import Colours
def clear(): def clear():
if sys.platform.startswith('win'): if sys.platform.startswith('win'):
# For Windows
os.system('cls') os.system('cls')
else: else:
# For Linux and macOS
os.system('clear') os.system('clear')
def findLowest(board, column):
return board[column].index("O")
"""
This is how the board should output:
===============
|O|O|O|O|O|O|O|
|O|O|O|O|O|O|O|
|O|O|O|O|O|O|O|
|O|O|O|O|O|O|O|
|O|O|O|O|O|O|O|
|O|O|O|O|O|O|O|
===============
"""
def printBoard(board): def printBoard(board):
rows = [] rows = []
@ -42,7 +24,10 @@ def printBoard(board):
for row in rows: for row in rows:
toPrint += (row + "\n") toPrint += (row + "\n")
print(f"=============================\n{toPrint[:-1]}\n=============================") print(f"""
=============================
{toPrint[:-1]}
=============================""")
def getIntInput(prompt): def getIntInput(prompt):
success = False success = False
@ -59,6 +44,9 @@ def getIntInput(prompt):
return inp return inp
def checkWin(board):
return False
# Board will be 7x6. # Board will be 7x6.
# O = open, R = red, Y = yellow # O = open, R = red, Y = yellow
@ -76,7 +64,7 @@ board = [
] ]
playing = True playing = True
turn = f'{Colours.RED}{Colours.BOLD}R{Colours.END}' turn = f'{Colours.RED}{Colours.BOLD}O{Colours.END}'
while playing: while playing:
clear() clear()
@ -86,7 +74,7 @@ while playing:
while tile == "": while tile == "":
try: try:
chosenColumn = getIntInput(f"{turn} where do you want to drop your tile? 0-6.\n>>> ") chosenColumn = getIntInput(f"{turn} where do you want to drop your tile? 0-6.\n>>> ")
tile = findLowest(board, chosenColumn) tile = board[chosenColumn].index("O")
break break
except ValueError: except ValueError:
clear() clear()
@ -101,4 +89,4 @@ while playing:
board[chosenColumn][tile] = turn board[chosenColumn][tile] = turn
turn = f'{Colours.YELLOW}{Colours.BOLD}Y{Colours.END}' if turn == f'{Colours.RED}{Colours.BOLD}R{Colours.END}' else f'{Colours.RED}{Colours.BOLD}R{Colours.END}' 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}'