Long story short I am building a game of tetris to make sure I don’t get rusty on my python skills for next year. I plan to make it into a GUI version once I have the basic game completed.
The issue I am having is in relation to “IF” statements. For some reason the logic is getting caught in these statements and deleting itself from existence. I spent a while already narrowing it down and I have gotten it to the point where it half works, though the falling blocks end up overlapping.
The basic function of how my program works is I have two dictionaries running in parallel with the main one (self.game in the code) being cleared and overwritten by an up to date dictionary at the end. The main issue is with the first “IF” statement which should check if the block is falling and then determine if the spot directly below it is filled or not. For some reason only about half the blocks that should go through this section actually go though it with the rest disappearing.
If anyone can help I’d really appreciate it. I’ve attached a picture of the section of code that isn’t working.
Edit: self.size[x/y] are the upper bounds of the grid the game is played on
def has_touched_down(self):
"""
Determines if the block has touched another block or the ground
If a block is determined to have touched the ground converts it to a stationary block which is no longer
effected by player actions
"""
key_list = list(self.game.keys())
my_dict = {}
for (x, y) in key_list:
if self.game.get((x, y)) == "Falling_Block" and (self.game.get(x, y + 1) == "Stationary_Block" or y + 1 == self.sizey):
my_dict.clear()
for key in key_list:
my_dict[key] = "Stationary_Block"
break
else:
if self.game.get((x, y)) == "Stationary_Block":
my_dict[(x, y)] = "Stationary_Block"
elif self.sizey <= y:
for key in key_list:
my_dict[key] = "Stationary_Block"
elif self.game.get((x, y)) == "Falling_Block":
my_dict[(x, y)] = "Falling_Block"
self.game.clear()
self.game.update(my_dict)