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

Function getSwappingGems

src/gamesbyexample/pygame_games/gemgem.py:235–262  ·  view source on GitHub ↗
(board, firstXY, secondXY)

Source from the content-addressed store, hash-verified

233
234
235def getSwappingGems(board, firstXY, secondXY):
236 # If the gems at the (X, Y) coordinates of the two gems are adjacent,
237 # then their 'direction' keys are set to the appropriate direction
238 # value to be swapped with each other.
239 # Otherwise, (None, None) is returned.
240 firstGem = {'imageNum': board[firstXY['x']][firstXY['y']],
241 'x': firstXY['x'],
242 'y': firstXY['y']}
243 secondGem = {'imageNum': board[secondXY['x']][secondXY['y']],
244 'x': secondXY['x'],
245 'y': secondXY['y']}
246 highlightedGem = None
247 if firstGem['x'] == secondGem['x'] + 1 and firstGem['y'] == secondGem['y']:
248 firstGem['direction'] = LEFT
249 secondGem['direction'] = RIGHT
250 elif firstGem['x'] == secondGem['x'] - 1 and firstGem['y'] == secondGem['y']:
251 firstGem['direction'] = RIGHT
252 secondGem['direction'] = LEFT
253 elif firstGem['y'] == secondGem['y'] + 1 and firstGem['x'] == secondGem['x']:
254 firstGem['direction'] = UP
255 secondGem['direction'] = DOWN
256 elif firstGem['y'] == secondGem['y'] - 1 and firstGem['x'] == secondGem['x']:
257 firstGem['direction'] = DOWN
258 secondGem['direction'] = UP
259 else:
260 # These gems are not adjacent and can't be swapped.
261 return None, None
262 return firstGem, secondGem
263
264
265def getBlankBoard():

Callers 1

runGameFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected