0

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()
  • Welcome to SO. Please isolate the relevant part of your code. No one really wants to read through 1000 lines. Also what have you tried and what doesn't work? http://stackoverflow.com/help/how-to-ask – Julien Dec 09 '15 at 07:43
  • I removed all of the code that I thought could be irrelevant to the situation. Im not sure how to approach this, and I've only tried what I have listed above – user5522252 Dec 09 '15 at 07:56
  • can you please fix the indentation of `def swap` so that it appears exactly as shown in your program? – esecules Dec 09 '15 at 08:23
  • Also what is the output you are seeing and what output do you expect? – esecules Dec 09 '15 at 08:36
  • I dont see in output in the terminal for the print function, the output I would expect is that when I click on a card and then click on a second card the two images would switch position with eachother – user5522252 Dec 09 '15 at 08:40
  • Have other print statements in your code worked? If not your program's output is getting redirected or that swap is not being called after the second button click. Could you include the function that should call swap()? Also what is the difference between box and selected? – esecules Dec 09 '15 at 08:50

0 Answers0