Puzzle game in Python
This Puzzel Game created in python by using its tkinter GUI package
and we are make it a like guessing Puzzel Game.
Using random method we are changed position of shape..
Puzzle games are games where you have to solve problems or challenges presented by the game. These games can use different techniques to make the gameplay challenging and interesting.
One popular technique used in puzzle games is called backtracking. This method works by trying to solve the puzzle step by step. If a step doesn't work, the algorithm goes back to the previous step and tries again. This technique is often used in games like Sudoku and crossword puzzles.
Another technique used in puzzle games is called a search algorithm. This technique works by exploring all possible options systematically to find the solution to the puzzle. This method is used in games like Minesweeper and sliding puzzles.
There are other techniques used in puzzle games, such as pathfinding algorithms, pattern recognition algorithms, and heuristic algorithms. Pathfinding algorithms help to find the shortest path from one point to another, while pattern recognition algorithms identify and solve repetitive patterns in the puzzle.
Heuristic algorithms estimate the value of a solution and are used in games like chess and Go.
In summary, puzzle games use various techniques to create challenging gameplay. The technique used depends on the specific puzzle game being developed and the desired level of difficulty.
These techniques have made puzzle games more interactive and engaging for players.
from tkinter import * import random from tkinter import ttk window=Tk() window.title('Memory Puzzel Game') tabs = ttk.Notebook(window) root= ttk.Frame(tabs) def draw(c,i,j): global base if c=='A': d=base.create_rectangle(100*i+20,j*100+20,100*i+100-20,100*j+100-20,fill='red') elif c=='B': d=base.create_rectangle(100*i+20,j*100+20,100*i+100-20,100*j+100-20,fill='yellow') elif c=='C': d=base.create_rectangle(100*i+20,j*100+20,100*i+100-20,100*j+100-20,fill='blue') elif c=='D': d=base.create_oval(100*i+20,j*100+20,100*i+100-20,100*j+100-20,fill='red') elif c=='E': d=base.create_oval(100*i+20,j*100+20,100*i+100-20,100*j+100-20,fill='yellow') elif c=='F': d=base.create_oval(100*i+20,j*100+20,100*i+100-20,100*j+100-20,fill='blue') elif c=='G': d=base.create_polygon(100*i+50,j*100+20,100*i+20,100*j+100-20,100*i+100-20,100*j+100-20,fill='red') elif c=='H': d=base.create_polygon(100*i+50,j*100+20,100*i+20,100*j+100-20,100*i+100-20,100*j+100-20,fill='green') def displayBoard(): global base,ans,board,moves cnt=0 for i in range(4): for j in range(4): rect=base.create_rectangle(100*i,j*100,100*i+100,100*j+100,fill="lavender") if(board[i][j]!='.'): draw(board[i][j],i,j) cnt+=1 if cnt==16: base.create_text(200,450,text="Moves: "+str(moves),font=('arial',20)) def callback(event): global base,ans,board,moves,prev i=event.x//100 j=event.y//100 if board[i][j]!='.': return moves+=1 if(prev[0]>4): prev[0]=i prev[1]=j board[i][j]=ans[i][j] displayBoard() else: board[i][j]=ans[i][j] displayBoard() if(ans[i][j]==board[prev[0]][prev[1]]): print("matched") prev=[100,100] displayBoard() return else: board[prev[0]][prev[1]]='.' displayBoard() prev=[i,j] return base=Canvas(root,width=400,height=400) base.pack() ans = list('AABBCCDDEEFFGGHH') random.shuffle(ans) ans = [ans[:4], ans[4:8], ans[8:12], ans[12:]] base.bind("", callback) moves=IntVar() moves=0 prev=[100,100] board=[list('.'*4) for cnt in range(4)] displayBoard() tabs.add(root) tabs.pack(expand = 1, fill ="both") window.mainloop()