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

Function getCanvasString

src/gamesbyexample/etchingdrawer.py:51–91  ·  view source on GitHub ↗

Returns a multiline string of the line drawn in canvasData.

(canvasData, cx, cy)

Source from the content-addressed store, hash-verified

49
50
51def getCanvasString(canvasData, cx, cy):
52 """Returns a multiline string of the line drawn in canvasData."""
53 canvasStr = ''
54
55 """canvasData is a dictionary with (x, y) tuple keys and values that
56 are sets of 'W', 'A', 'S', and/or 'D' strings to show which
57 directions the lines are drawn at each xy point."""
58 for rowNum in range(CANVAS_HEIGHT):
59 for columnNum in range(CANVAS_WIDTH):
60 if columnNum == cx and rowNum == cy:
61 canvasStr += '#'
62 continue
63
64 # Add the line character for this point to canvasStr.
65 cell = canvasData.get((columnNum, rowNum))
66 if cell in (set(['W', 'S']), set(['W']), set(['S'])):
67 canvasStr += UP_DOWN_CHAR
68 elif cell in (set(['A', 'D']), set(['A']), set(['D'])):
69 canvasStr += LEFT_RIGHT_CHAR
70 elif cell == set(['S', 'D']):
71 canvasStr += DOWN_RIGHT_CHAR
72 elif cell == set(['A', 'S']):
73 canvasStr += DOWN_LEFT_CHAR
74 elif cell == set(['W', 'D']):
75 canvasStr += UP_RIGHT_CHAR
76 elif cell == set(['W', 'A']):
77 canvasStr += UP_LEFT_CHAR
78 elif cell == set(['W', 'S', 'D']):
79 canvasStr += UP_DOWN_RIGHT_CHAR
80 elif cell == set(['W', 'S', 'A']):
81 canvasStr += UP_DOWN_LEFT_CHAR
82 elif cell == set(['A', 'S', 'D']):
83 canvasStr += DOWN_LEFT_RIGHT_CHAR
84 elif cell == set(['W', 'A', 'D']):
85 canvasStr += UP_LEFT_RIGHT_CHAR
86 elif cell == set(['W', 'A', 'S', 'D']):
87 canvasStr += CROSS_CHAR
88 elif cell == None:
89 canvasStr += ' '
90 canvasStr += '\n' # Add a newline at the end of each row.
91 return canvasStr
92
93
94moves = []

Callers 1

etchingdrawer.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected