From 0af1832ee5051006ed67f6a15eae48021bbd5304 Mon Sep 17 00:00:00 2001 From: benjamyn Date: Sat, 13 Aug 2022 04:37:55 +1000 Subject: [PATCH] initial --- .gitignore | 1 + TODO.md | 6 +++++ main.py | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 .gitignore create mode 100644 TODO.md create mode 100644 main.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dbe9c82 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.vscode/ \ No newline at end of file diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..e577ee9 --- /dev/null +++ b/TODO.md @@ -0,0 +1,6 @@ +# Shit to do + +- Add victory logic +- Separate game logic and graphics system +- Get board working correctly - Done +- Store player data in board - Done diff --git a/main.py b/main.py new file mode 100644 index 0000000..fd020b1 --- /dev/null +++ b/main.py @@ -0,0 +1,76 @@ +#!/usr/bin/python3 + +import time +import os + +class Game: + def __init__(self): + self.player = 1 + self.board = [[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0]] + self.labels = [1, 2, 3, 4, 5, 6, 7] + + def draw_board(self): + for x in self.board: + for y in range(len(x)): + + print(x[y], end=" ") + print("") + + def draw_labels(self): + for x in self.labels: + print(x, end=" ") + print("") + + def turn(self, slot): + landed_piece = False + if slot > 6: + raise Exception("You fucked up") + if self.board[0][slot] != 0: + # The space is filled and no longer valid + return + for x in range(len(self.board)): + if self.board[x][slot] != 0: + self.board[x-1][slot] = self.player + landed_piece = True + break + if landed_piece is False: + self.board[len(self.board) - 1][slot] = self.player + + self.player = 2 if self.player == 1 else 1 + + def check_victory(self): + # Write logic to determine winner + for x in range(len(self.board)): + if any(self.board[x]): + for y in range(len(self.board[x])): + if self.board[x][y] != 0: + current_value = self.board[x][y] + print(f"checking current value: {current_value}") + + pass + return False + + +if __name__ == '__main__': + playing = True + game = Game() + + while playing is True: + os.system('clear') + game.check_victory() + print(f"It is player {game.player}'s turn") + game.draw_board() + print('-------------') + game.draw_labels() + in_data = input("(q/quit) Where do you want to put your piece? ") + + if in_data == 'q' or in_data == "quit": + playing = False + break + + try: + in_data = int(in_data) - 1 + game.turn(in_data) + except Exception as e: + print(f"Got an error: {e}") +