Question: Create the slider puzzle game in python 3 , it should be a 3x3 grid and have each square be a number 1 through 8

Create the slider puzzle game in python 3, it should be a 3x3 grid and have each square be a number 1 through 8 with one blank square. Each square should be a button in Tkinter. Only Tkinter and Math may be imported. I've attached what I have so far below.

class eight_puzzel: def _init__(self): self.moves = dict() self.moves[0] = [1, 3] self.moves[1] = [0, 2, 4] self.moves[2] = [1, 5] self.moves[3] = [0, 4, 6] self.moves[4] = [3, 5, 7] self.moves[5] = [2, 4, 8] self.moves[6] = [3, 7] self.moves[7] = [4, 6, 8] self.moves[8] = [5, 7]

self.config = ['1', '2', '3', '4', '5', '6', '7', '8', ' '] shuffle(self.config)

def display(self): if self.window != None: self.window = Tk()

def gui_move(self, event): self.move(self.button_locs(event.widget)

def move(self, tile): tile_loc = self.config.index(str(tile)) blank_loc = self.config.index(' ') if tile_loc in self.moves[blank_loc]: self.config[tile_loc] = ' ' self.config[blank_loc] = str(tile) self.display()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!