Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- import random
- class Pieza():
- def __init__(self,valor,hide):
- self.valor = valor
- self.hide = hide
- def getValor(self):
- return self.valor
- def setValor(self,valor):
- self.valor = valor
- def getHide(self):
- return self.hide
- def sethide(self,hide):
- self.hide = hide
- def crearTabla(x,y):
- temp = [[0 for i in range(x)] for i in range(y)]
- for i in range(0,x):
- for j in range(0,y):
- if random.randrange(10) < 2:
- temp[i][j] = -1
- else:
- temp[i][j] = 0
- return temp
- def addVecinos(tabla,i,j):
- for x in range(0,i):
- for y in range(0,j):
- if tabla[x][y] == -1:
- if x>=0:
- if tabla[x-1][y]>=0:
- tabla[x-1][y] = tabla[x-1][y] + 1
- if y-1>=0:
- if tabla[x-1][y-1]>=0:
- tabla[x-1][y-1] = tabla[x-1][y-1] + 1
- if y+1<j:
- if tabla[x-1][y+1]>=0:
- tabla[x-1][y+1] = tabla[x-1][y+1] + 1
- if y>=0:
- if tabla[x][y-1]>=0:
- tabla[x][y-1] = tabla[x][y-1] + 1
- if y+1<j:
- if tabla[x][y+1]>=0:
- tabla[x][y+1] = tabla[x][y+1] + 1
- if x+1<i:
- if tabla[x+1][y]>=0:
- tabla[x+1][y] = tabla[x+1][y] + 1
- if y-1>=0:
- if tabla[x+1][y-1]>=0:
- tabla[x+1][y-1] = tabla[x+1][y-1] + 1
- if y+1<j:
- if tabla[x+1][y+1]>=0:
- tabla[x+1][y+1] = tabla[x+1][y+1] + 1
- def tableToList(tabla,x,y):
- temp = [[0 for i in range(x)] for i in range(y)]
- for i in range(0,x):
- for j in range(0,y):
- temp[i][j] = Pieza(tabla[i][j],True)
- return temp
- def test(x,y,piezas):
- piezas[x][y].sethide(False)
- print(piezas[x][y].getValor())
- def toggle(x,y):
- buttonTable[x][y]["text"]=tabla[x][y]
- buttonTable[x][y]["relief"]="sunken"
- if __name__ == "__main__":
- buttonTable = [[0 for i in range(10)] for i in range(10)]
- tabla = crearTabla(10,10)
- addVecinos(tabla,10,10)
- piezas = tableToList(tabla,10,10)
- root = tk.Tk()
- root.title("Buscaminas")
- inicio = tk.Button(root,text =":)")
- inicio.grid(row=0,column=5)
- for x in range(0,10):
- for y in range(0,10):
- cmd=lambda:toggle(x,y)
- buttonTable[x][y] = tk.Button(root,text="",relief="raised",width=5,command=cmd)
- buttonTable[x][y].grid(row=x+1,column=y)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement