Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A 4x4 Field in Pygame
#3
You can make a dictionary for the spaces. You can type out the dictionary or do this
mapDict = {}

for x in range(1, 17): #repeat 16 times
    mapDict.update({x : None}) #None means it isn't occupied
This function will check if the card can be moved
def CheckIfPossible(direction, space): #direction is the direction they are trying to move the card in. space is the space the card is in
    coordDict = {'x1' : 'left', 'x4' : 'right', 'y1' : 'up', 'y4' : 'down'} #Directions the card cannot go if at a specific coord
    y = #Get y coord as in 2 if it were in the 2nd row
    x = #Get x coord for example 1 if it were in the first column
    if x == 1 and coordDict['x1'] == direction.lower():
        return False
    elif x == 4 and coordDict['x4'] == direction.lower():
        return False
    elif y == 1 and coordDict['y1'] == direction.lower():
        return False
    elif y == 4 and coordDict['y4'] == direction.lower():
        return False
    return True
Hope this helps!
Reply


Messages In This Thread
A 4x4 Field in Pygame - by Piethon - Aug-11-2019, 04:29 PM
RE: A 4x4 Field in Pygame - by metulburr - Aug-11-2019, 10:06 PM
RE: A 4x4 Field in Pygame - by SheeppOSU - Aug-12-2019, 08:15 PM
RE: A 4x4 Field in Pygame - by Piethon - Aug-13-2019, 09:28 AM
RE: A 4x4 Field in Pygame - by Windspar - Aug-13-2019, 10:38 AM
RE: A 4x4 Field in Pygame - by Piethon - Aug-14-2019, 07:44 AM
RE: A 4x4 Field in Pygame - by Windspar - Aug-14-2019, 12:24 PM
RE: A 4x4 Field in Pygame - by Piethon - Aug-18-2019, 09:50 AM
RE: A 4x4 Field in Pygame - by Piethon - Aug-19-2019, 10:08 AM
RE: A 4x4 Field in Pygame - by Windspar - Aug-18-2019, 11:26 AM
RE: A 4x4 Field in Pygame - by metulburr - Aug-18-2019, 12:23 PM
RE: A 4x4 Field in Pygame - by metulburr - Aug-19-2019, 11:33 AM
RE: A 4x4 Field in Pygame - by Windspar - Aug-19-2019, 11:38 AM
RE: A 4x4 Field in Pygame - by Piethon - Aug-19-2019, 12:09 PM
RE: A 4x4 Field in Pygame - by metulburr - Aug-19-2019, 01:07 PM
RE: A 4x4 Field in Pygame - by Windspar - Aug-19-2019, 04:37 PM
RE: A 4x4 Field in Pygame - by Piethon - Aug-19-2019, 06:49 PM
RE: A 4x4 Field in Pygame - by Windspar - Aug-19-2019, 09:21 PM
RE: A 4x4 Field in Pygame - by metulburr - Aug-19-2019, 10:49 PM
RE: A 4x4 Field in Pygame - by Piethon - Aug-20-2019, 08:51 AM
RE: A 4x4 Field in Pygame - by Windspar - Aug-20-2019, 10:38 AM
RE: A 4x4 Field in Pygame - by metulburr - Aug-20-2019, 12:03 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020