Okay, I am a little stuck here, I am trying to create a game that a user can choose a game mode, and based on this it pulls resources of pictures out and puts them into a 5x6 grid, I then have to swap the images - in one game mode - so that all of the same images are in a column and in the other game mode all of the images of the same color are in a row. How can I fix this swap? I tried using the variables card1_x, card1_y etc.. etc that is commented out as well as what the defined swap function is.
#List of white cards
whitecards = ["shape1.png", "shape2.png", "shape3.png", "shape4.png", "shape5.png", "shape6.png"]
#variables to keep track of where the user clicked
box_x = -1
box_y = -1
selected_x = -1
selected_y = -1
#variables to keep track of mouse clicks
first_click = False
second_click = False
def colorlessBoard():
# one dimensional list
icons = []
for card in whitecards:
icons.append(card)
icons.append(card)
icons.append(card)
icons.append(card)
icons.append(card)
random.shuffle(icons)
# two dimensional list
board = []
for x in range(grid_height):
column = []
for y in range(grid_width):
column.append(icons[0])
del icons[0]
board.append(column)
return board
colorlessboard = colorlessBoard()
def swap(box_x, box_y, selected_x, selected_y):
temp = mycards[box_x * grid_width + box_y]
print (temp)
mycards[box_x * grid_width + box_y] = mycards[selected_x * grid_width +selected_y]
mycards[selected_x * grid_width + selected_y] = temp
##def swap(card1_x, card1_y, card2_x, card2_y):
## temp = whitecards[card1_x * grid_width + card1_y]
## whitecards[card1_x * grid_width + card1_y] = whitecards[card2_x * grid_width + card2_y]
## whitecards[card2_x * grid_width +card2_y] = temp
rowindex = 0
for cardlist in colorlessboard:
colindex = 0
for card in cardlist:
imgx = colindex * box_width + play_lcorner_x
imgy = rowindex * box_width + play_lcorner_y
myimg = pygame.image.load(cardlist[colindex])
pygame.draw.rect(dispWindow, black, (imgx,imgy,box_width, box_width),2)
dispWindow.blit(myimg, (imgx, imgy))
colindex += 1
rowindex += 1
pygame.display.update()
pygame.display.update()