I am working on my first Python game but before I get started, I am working through some tutorials and trying to modify them. I found a great "bejeweled" style game that I am trying to make some changes to, however I am running into one problem.
The game normally used seven different images. When the game would start, it would place the gems in a somewhat random order but it checked to make sure it wasn't putting a ton of the same gems next to each other.
What I am wanting to do is greatly increase the number of images to seventeen. All the images load correctly, however some of the images I want to limit the number of times they appear. For example, I want gem1 through gem3 to be the more common gem, while all the others do not appear as often. I am thinking of doing something like using random. Have it pick a number between 1-5. If 1-4 is picked, either gem1, gem2, or gem3 will be picked. If 5 is picked, any of the other gems will appear but it always needs to follow the possibleGems code to make sure a bunch of the same images are not appearing next to each other. Any ideas on how to make this work?
I have included some of the tutorial code in the places that are the most important to the gems. You can also look up the full source code by searching for gemgem.py in google.
possibleGems = list(range(len(GEMIMAGES)))
for offsetX, offsetY in ((0, -1), (1, 0), (0, 1), (-1, 0)):
# Narrow down the possible gems we should put in the
# blank space so we don't end up putting an two of
# the same gems next to each other when they drop.
neighborGem = getGemAt(boardCopy, x + offsetX, y + offsetY)
if neighborGem != None and neighborGem in possibleGems:
possibleGems.remove(neighborGem)
newGem = random.choice(possibleGems)
boardCopy[x][y] = newGem
dropSlots[x].append(newGem)
Code to load the images
# Load the images
GEMIMAGES = []
for i in range(1, NUMGEMIMAGES+1):
gemImage = pygame.image.load('gem%s.png' % i)
if gemImage.get_size() != (GEMIMAGESIZE, GEMIMAGESIZE):
gemImage = pygame.transform.smoothscale(gemImage, (GEMIMAGESIZE, GEMIMAGESIZE))
GEMIMAGES.append(gemImage)