initial
This commit is contained in:
commit
0af1832ee5
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
.vscode/
|
||||||
6
TODO.md
Normal file
6
TODO.md
Normal file
@ -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
|
||||||
76
main.py
Normal file
76
main.py
Normal file
@ -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}")
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user