-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.py
More file actions
56 lines (51 loc) · 1.72 KB
/
Copy pathPlayer.py
File metadata and controls
56 lines (51 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from gameboard import GameBoard
import numpy as np
class Player:
board_size = 10
# create new gameboard object
_board = GameBoard(board_size)
# is game running?
_game = True
# board the player sees
display_board = np.full((board_size, board_size), '#')
def __init__(self):
# generate the board
self._board = self._board.generate_board()
# if the player's first click is on a bomb, sucks to suck
# ill fix it later
def player_click(self, x, y):
match self._board[x][y]:
# lose condition
case -1:
_game = False
# recursively uncover zeroes
case 0:
pass
# uncover number
case _:
self.display_board[x][y] = self._board[x][y]
def uncover_zeroes(self, x, y):
if self._board[x][y] != 0:
return
else:
self.display_board[x][y] = 0
# search up
if y - 1 >= 0 and self.display_board[x][y - 1] == '#':
self.uncover_zeroes(x, y - 1)
# search down
if y + 1 < self.board_size and self.display_board[x][y + 1] == '#':
self.uncover_zeroes(x, y + 1)
# search left
if x - 1 >= 0 and self.display_board[x - 1][y] == '#':
self.uncover_zeroes(x - 1, y)
# search right
if x + 1 < self.board_size and self.display_board[x + 1][y] == '#':
self.uncover_zeroes(x + 1, y)
# print board
def __str__(self):
board_str = ""
for r in range(self.board_size):
for c in range(self.board_size):
board_str += str(self.display_board[r][c]) + " "
board_str += "\n"
return board_str