Vous êtes sur la page 1sur 3

[tutor] minesweeper implementing 20%, weird problem with matrixes[tutor]

minesweeper implementing 20%, weird problem with matrixes


alberto troiano albertito_g at hotmail.com
wed jul 13 23:36:44 cest 2005
previous message: [tutor] deleting files that are older than x days old
next message: [tutor] minesweeper implementing 20%, weird problem with
matrixes
messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

hey tutors

i think i got this a little, but i have a very weird problem

this is the code i'm using:

######################

class buscaminas(object):

def __init__(self):
self.col=0
self.marcas=tkinter.booleanvar()
self.color=tkinter.booleanvar()
self.sonido=tkinter.booleanvar()
self.fil=0
self.byob=0
menubar= menu(root)
archivo=menu(menubar,tearoff=0)

archivo.add_command(label="nuevo",underline=0,command=self.initialize)
archivo.add_radiobutton(label="f�cil",underline=0,command=lambda:
self.nivel(9,9,10))
archivo.add_radiobutton(label="medio",underline=0,command=lambda:
self.nivel(16,16,40))
archivo.add_radiobutton(label="dificil",underline=0,command=lambda:
self.nivel(16,30,99))

archivo.add_radiobutton(label="personalizado",underline=0,command=self.hello)
archivo.add_separator()
archivo.add_checkbutton(label="marcas
(?)",variable=self.marcas,underline=0,command=self.hello)

archivo.add_checkbutton(label="color",underline=0,command=self.hello)

archivo.add_checkbutton(label="sonido",underline=1,command=self.hello)
archivo.add_separator()
archivo.add_command(label="mejores
tiempos",underline=8,command=self.hello)
archivo.add_separator()
archivo.add_command(label="salir",underline=0,command=root.destroy)
menubar.add_cascade(label="juego",underline=0,menu=archivo)
help = menu(menubar, tearoff=0)
help.add_command(label="contenido", command=self.hello)
help.add_command(label="indice de ayuda", command=self.hello)
help.add_command(label="como usar la ayuda", command=self.hello)
help.add_separator()
help.add_command(label="acerca de...", command=self.hello)
menubar.add_cascade(label="ayuda",underline=1, menu=help)
root.config(menu=menubar)
root.bind_all("<f1>",lambda d: self.hello())
root.bind_all("<f2>",lambda s: self.initialize())
root.bind_all("<control-x>",lambda x: root.destroy())

def hello(self):
print "funca"

def initialize(self):
self.buttonmatrix=[]
self.statematrix=[]
self.bombmatrix=[]
for i in range(self.fil):
aux=[]
for j in range(self.col):
aux.append(none)
self.buttonmatrix.append(aux)
self.bombmatrix.append(aux)
self.statematrix.append(aux)
self.bombs()

def nivel(self,f,c,b):
self.col=c
self.fil=f
self.byob=b
self.initialize()

def bombs(self):
c=0
while not c==self.byob:
fi=random.randrange(self.fil)
co=random.randrange(self.col)
if self.bombmatrix[fi][co]==none:
self.bombmatrix[fi][co]=9
c+=1
self.numbers()

def putnumber(self,row,column):
c=0
fi=row-1
ci=column-1
ff=row+2
cf=column+2
for i in range(fi,ff):
for j in range(ci,cf):
if (i<0) or (i>=self.fil) or (j<0) or (j>=self.col):
pass
elif self.bombmatrix[i][j]==9:
c+=1
else:
pass
return c

def numbers(self):
for i in range(self.fil):
for j in range(self.col):
if self.bombmatrix[i][j]==9:
pass
else:
self.bombmatrix[i][j]=self.putnumber(i,j)
self.nuevo()

def nuevo(self):
for el in self.buttonmatrix:
print el
for l in self.statematrix:
print l
for e in self.bombmatrix:
print e

def main():
global root
root=tk()
root.title("buscaminas")
root.iconbitmap("images\mina.ico")
a=buscaminas()
root.mainloop()

main()

##############

the following variables are the one with the problem:

self.bombmatrix, self.buttonmatrix, self.statematrix

i initialize them by putting none along all the fields (this is to allow the
user to have any size of matrix) then i charge with numbers the
self.bombmatrix but weirdly the others variables are filled with the same
values, which is very strange to me since i'm not assigning them each others

any hint?

thanks in advanced and sorry for the long piece of code

alberto

previous message: [tutor] deleting files that are older than x days old
next message: [tutor] minesweeper implementing 20%, weird problem with
matrixes
messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

more information about the tutor mailing list

Vous aimerez peut-être aussi