aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <l.leblansch@gmail.com>2021-02-10 17:20:48 +0100
committerlonkaars <l.leblansch@gmail.com>2021-02-10 17:20:48 +0100
commit4686fe29b1e9e9f1545deef500fe3bc462527ed4 (patch)
tree3b000cfa95157f233299be6693f3182337415bad
parent2ad2c61721484b50295dd1f0ce1c4770b89f866c (diff)
semi-working connect-4 game implementation
-rw-r--r--console/main.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/console/main.py b/console/main.py
new file mode 100644
index 0000000..dbf414f
--- /dev/null
+++ b/console/main.py
@@ -0,0 +1,36 @@
+from colorama import Fore
+import os
+
+DISC_SHAPE = "o"
+DISC_A = Fore.RED + DISC_SHAPE + Fore.RESET
+DISC_B = Fore.BLUE + DISC_SHAPE + Fore.RESET
+EMPTY = Fore.LIGHTBLACK_EX + "_" + Fore.RESET
+
+class bord:
+ def __init__(self, w, h):
+ self.board = [[EMPTY for x in range(w)] for u in range(h)]
+
+ def print(self):
+ print("\n".join([" ".join(y) for y in self.board]))
+
+ def drop_fisje(self, column, disc):
+ row = -1
+ for r in range(len(self.board)):
+ if self.board[r][column] != EMPTY:
+ row = r - 1
+ break
+ self.board[row][column] = disc
+
+def main():
+ disc_a = True
+ gert = bord(7, 6)
+ while True:
+ gert.print()
+ column = int(input("column?: ")) - 1
+ os.system("clear")
+ gert.drop_fisje(column, DISC_A if disc_a else DISC_B)
+ disc_a = not disc_a
+
+if __name__ == "__main__":
+ main()
+