MCPcopy Create free account
hub / github.com/asweigart/PythonStdioGames / DropspinBoard

Class DropspinBoard

inprogress/dropspin.py:20–134  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18
19
20class DropspinBoard:
21 def __init__(self, size):
22 assert size % 2 == 0, 'Board size must be even.'
23 assert size < 100, 'Board size must be less than 100.'
24 self.size = size
25
26 self.clear()
27
28
29 def clear(self):
30 self.board = {} # Keys are (x, y) tuples, values are Boolean.
31 for column in range(self.size):
32 for row in range(self.size):
33 self.board[(column, row)] = EMPTY
34 self.moves = []
35 self.rememberBoard()
36
37
38 def display(self):
39 # Print the column labels:
40 print(' ', end='') # Print a space to make room for the left edge border.
41 for columnNumber in range(10, self.size + 1, 10):
42 print((' ' * 9) + str(columnNumber // 10), end='')
43 print() # Print a newline.
44 print(' ', end='') # Print a space to make room for the left edge border.
45 for columnNumber in range(1, self.size + 1):
46 print(str(columnNumber % 10), end='')
47 print() # Print a newline.
48
49 # Print the top edge of the border:
50 print(BORDER_CHAR * (self.size + 2))
51
52 for row in range(0, self.size, 2):
53 print(BORDER_CHAR, end='') # Print the left edge border.
54 for column in range(self.size):
55 if self.board[(column, row)] == FILLED and self.board[(column, row + 1)] == FILLED:
56 print(FULL_BLOCK, end='')
57 elif self.board[(column, row)] == FILLED and self.board[(column, row + 1)] == EMPTY:
58 print(TOP_BLOCK, end='')
59 elif self.board[(column, row)] == EMPTY and self.board[(column, row + 1)] == FILLED:
60 print(BOTTOM_BLOCK, end='')
61 elif self.board[(column, row)] == EMPTY and self.board[(column, row + 1)] == EMPTY:
62 print(NO_BLOCK, end='')
63 #if self.board[(column, row)]:
64 # print(BLOCK_CHAR, end='')
65 #else:
66 # print('.', end='')
67 print(BORDER_CHAR, end='') # Print the right edge border.
68 print() # Print a newline.
69
70 # Print the bottom edge of the border:
71 print(BORDER_CHAR * (self.size + 2))
72
73
74 def dropOnColumn(self, column):
75 if self.board[(column, 0)] == FILLED:
76 # This column is completely full, do nothing:
77 return

Callers 1

dropspin.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected