-Ajout de la liste globale adirection qui fait varier le sens de départ de l'électron dans la fonction nextgrid. Dans Swap on décale de 1 vers la gauche les éléments de la liste.
-Ajout de la création automatique du fichier pref.dat et déplacement de celui-ci dans un dossier user. -Déplacement des données de niveaux personnalisés vers le dossier user. -Evite le rechargement des niveaux dans la variable items par la fonction readlittlegrid, en vérifiant l'existence de la clé "cout"
This commit is contained in:
parent
2763399ce2
commit
a43a457589
38
WireChem.py
38
WireChem.py
|
@ -46,7 +46,7 @@ def loaditems(n,file):
|
||||||
return len(liste)-1
|
return len(liste)-1
|
||||||
|
|
||||||
def initgrid(x,y):
|
def initgrid(x,y):
|
||||||
global sizeworld,finished,allcout,selected,world,level,over,mousel,mouser,mousem,sizex,sizey,world_old,world_new,world_art,items,direction,zoom,play,stat,cycle,cout,thecout,rayon,unroll,debug,temp,decx,decy,nrj,tech,victory,current,names,thecolors,maxnrj,maxrayon,maxcycle,maxtemp,nom,descriptif,element
|
global adirection,sizeworld,finished,allcout,selected,world,level,over,mousel,mouser,mousem,sizex,sizey,world_old,world_new,world_art,items,direction,zoom,play,stat,cycle,cout,thecout,rayon,unroll,debug,temp,decx,decy,nrj,tech,victory,current,names,thecolors,maxnrj,maxrayon,maxcycle,maxtemp,nom,descriptif,element
|
||||||
|
|
||||||
''' Directions des electrons en fonction de la position de la queue '''
|
''' Directions des electrons en fonction de la position de la queue '''
|
||||||
direction = {}
|
direction = {}
|
||||||
|
@ -58,6 +58,7 @@ def initgrid(x,y):
|
||||||
direction[(+1,-1)]=[(-1,+1),(+0,+1),(-1,+0),(+1,+1),(-1,-1),(+1,+0),(+0,-1),(+1,-1)]
|
direction[(+1,-1)]=[(-1,+1),(+0,+1),(-1,+0),(+1,+1),(-1,-1),(+1,+0),(+0,-1),(+1,-1)]
|
||||||
direction[(+1,+0)]=[(-1,+0),(-1,+1),(-1,-1),(+0,+1),(+0,-1),(+1,+1),(+1,-1),(+1,+0)]
|
direction[(+1,+0)]=[(-1,+0),(-1,+1),(-1,-1),(+0,+1),(+0,-1),(+1,+1),(+1,-1),(+1,+0)]
|
||||||
direction[(+1,+1)]=[(-1,-1),(-1,+0),(+0,-1),(-1,+1),(+1,-1),(+0,+1),(+1,+0),(+1,+1)]
|
direction[(+1,+1)]=[(-1,-1),(-1,+0),(+0,-1),(-1,+1),(+1,-1),(+0,+1),(+1,+0),(+1,+1)]
|
||||||
|
adirection=[(-1,-1),(-1,+0),(-1,+1),(+0,-1),(+0,+1),(+1,-1),(+1,+0),(+1,+1)]
|
||||||
items = {}
|
items = {}
|
||||||
sizeworld=loaditems(int("0x40000", 16),"data/worlds.dat")
|
sizeworld=loaditems(int("0x40000", 16),"data/worlds.dat")
|
||||||
loaditems(int("0x30000", 16),"data/elements2.dat")
|
loaditems(int("0x30000", 16),"data/elements2.dat")
|
||||||
|
@ -94,7 +95,7 @@ def initgrid(x,y):
|
||||||
|
|
||||||
def readpref(file):
|
def readpref(file):
|
||||||
global finished
|
global finished
|
||||||
with open(file, 'rb') as f:
|
with open(file, 'a+') as f:
|
||||||
try:
|
try:
|
||||||
finished=list(csv.reader(f,delimiter=';'))[0]
|
finished=list(csv.reader(f,delimiter=';'))[0]
|
||||||
f.close()
|
f.close()
|
||||||
|
@ -103,7 +104,7 @@ def readpref(file):
|
||||||
|
|
||||||
def writepref(file):
|
def writepref(file):
|
||||||
global finished
|
global finished
|
||||||
with open(file, 'wb') as f:
|
with open(file, 'wb+') as f:
|
||||||
writer = csv.writer(f, delimiter=';', quotechar='', quoting=csv.QUOTE_NONE)
|
writer = csv.writer(f, delimiter=';', quotechar='', quoting=csv.QUOTE_NONE)
|
||||||
writer.writerow(finished)
|
writer.writerow(finished)
|
||||||
f.close()
|
f.close()
|
||||||
|
@ -357,6 +358,7 @@ def drawworld():
|
||||||
for i in range(sizeworld):
|
for i in range(sizeworld):
|
||||||
ele=items[items[int("0x40000",16)+i]]
|
ele=items[items[int("0x40000",16)+i]]
|
||||||
if ele['world']==world:
|
if ele['world']==world:
|
||||||
|
if 'cout' not in ele:
|
||||||
readlittlegrid(ele['file'],items[int("0x40000",16)+i])
|
readlittlegrid(ele['file'],items[int("0x40000",16)+i])
|
||||||
if items[int("0x40000",16)+i] not in finished and not (ele['world']==0 and ele['grid']==0):
|
if items[int("0x40000",16)+i] not in finished and not (ele['world']==0 and ele['grid']==0):
|
||||||
glColor3ub(60,60,60)
|
glColor3ub(60,60,60)
|
||||||
|
@ -572,7 +574,7 @@ def levels(dummy1,dummy2,dummy3,dummy4):
|
||||||
for i in range(sizeworld):
|
for i in range(sizeworld):
|
||||||
ele=items[items[int("0x40000",16)+i]]
|
ele=items[items[int("0x40000",16)+i]]
|
||||||
if ele['world']==world and ele['grid']==level:
|
if ele['world']==world and ele['grid']==level:
|
||||||
writegrid(ele['file']+".user")
|
writegrid("user/"+ele['file'])
|
||||||
level=-1
|
level=-1
|
||||||
|
|
||||||
def exits(dummy1,dummy2,dummy3,dummy4):
|
def exits(dummy1,dummy2,dummy3,dummy4):
|
||||||
|
@ -642,6 +644,7 @@ def retriern():
|
||||||
world_art[x][y]=items['triern'+idtri+"-"+idtri+acttri]['value']
|
world_art[x][y]=items['triern'+idtri+"-"+idtri+acttri]['value']
|
||||||
|
|
||||||
def swap():
|
def swap():
|
||||||
|
global adirection
|
||||||
for dx,dy in direction:
|
for dx,dy in direction:
|
||||||
if random.randint(0,100)>50:
|
if random.randint(0,100)>50:
|
||||||
temps=direction[(dx,dy)][1]
|
temps=direction[(dx,dy)][1]
|
||||||
|
@ -655,6 +658,15 @@ def swap():
|
||||||
temps=direction[(dx,dy)][5]
|
temps=direction[(dx,dy)][5]
|
||||||
direction[(dx,dy)][5]=direction[(dx,dy)][6]
|
direction[(dx,dy)][5]=direction[(dx,dy)][6]
|
||||||
direction[(dx,dy)][6]=temps
|
direction[(dx,dy)][6]=temps
|
||||||
|
bdirection=copy.deepcopy(adirection)
|
||||||
|
adirection[0]=bdirection[1]
|
||||||
|
adirection[1]=bdirection[2]
|
||||||
|
adirection[2]=bdirection[3]
|
||||||
|
adirection[3]=bdirection[4]
|
||||||
|
adirection[4]=bdirection[5]
|
||||||
|
adirection[5]=bdirection[6]
|
||||||
|
adirection[6]=bdirection[7]
|
||||||
|
adirection[7]=bdirection[0]
|
||||||
|
|
||||||
def gameover_ok():
|
def gameover_ok():
|
||||||
global over,level,sizeworld
|
global over,level,sizeworld
|
||||||
|
@ -663,7 +675,7 @@ def gameover_ok():
|
||||||
if ele['world']==world and ele['grid']==level:
|
if ele['world']==world and ele['grid']==level:
|
||||||
readcondgrid(ele['file'])
|
readcondgrid(ele['file'])
|
||||||
erase()
|
erase()
|
||||||
writegrid(ele['file']+".user")
|
writegrid("user/"+ele['file'])
|
||||||
clock.schedule_once(menu,2,level)
|
clock.schedule_once(menu,2,level)
|
||||||
|
|
||||||
def itsvictory_ok():
|
def itsvictory_ok():
|
||||||
|
@ -673,9 +685,9 @@ def itsvictory_ok():
|
||||||
if ele['world']==world and ele['grid']==level:
|
if ele['world']==world and ele['grid']==level:
|
||||||
readcondgrid(ele['file'])
|
readcondgrid(ele['file'])
|
||||||
erase()
|
erase()
|
||||||
writegrid(ele['file']+".user")
|
writegrid("user/"+ele['file'])
|
||||||
finished.extend(ele['validate'])
|
finished.extend(ele['validate'])
|
||||||
writepref('data/pref.dat')
|
writepref('user/pref.dat')
|
||||||
clock.schedule_once(menu,2,-1)
|
clock.schedule_once(menu,2,-1)
|
||||||
|
|
||||||
def gameover(x):
|
def gameover(x):
|
||||||
|
@ -793,7 +805,7 @@ def isdroite(n):
|
||||||
return n[0]==-1 and n[1]==0
|
return n[0]==-1 and n[1]==0
|
||||||
|
|
||||||
def nextgrid():
|
def nextgrid():
|
||||||
global play,cycle,temp,rayon,nrj,current
|
global play,cycle,temp,rayon,nrj,current,adirection
|
||||||
world_old=copy.deepcopy(world_new)
|
world_old=copy.deepcopy(world_new)
|
||||||
swap()
|
swap()
|
||||||
for x in range(1,sizex-1):
|
for x in range(1,sizex-1):
|
||||||
|
@ -813,7 +825,7 @@ def nextgrid():
|
||||||
if world_old[x][y] == items['headp']['value']:
|
if world_old[x][y] == items['headp']['value']:
|
||||||
world_new[x][y]=items['tailp']['value']
|
world_new[x][y]=items['tailp']['value']
|
||||||
elif world_old[x][y] >= items['head']['value']:
|
elif world_old[x][y] >= items['head']['value']:
|
||||||
for dx,dy in ((-1,-1),(-1,+0),(-1,+1),(+0,-1),(+0,+1),(+1,-1),(+1,+0),(+1,+1)):
|
for dx,dy in adirection:
|
||||||
if world_old[x+dx][y+dy]>=value>>8:
|
if world_old[x+dx][y+dy]>=value>>8:
|
||||||
break
|
break
|
||||||
for ex,ey in direction[(dx,dy)]:
|
for ex,ey in direction[(dx,dy)]:
|
||||||
|
@ -983,7 +995,7 @@ ambiance = pyglet.media.Player()
|
||||||
sound = pyglet.media.Player()
|
sound = pyglet.media.Player()
|
||||||
ambiance.queue(pyglet.resource.media("music/ambiance1.mp3"))
|
ambiance.queue(pyglet.resource.media("music/ambiance1.mp3"))
|
||||||
ambiance.play()
|
ambiance.play()
|
||||||
readpref('data/pref.dat')
|
readpref('user/pref.dat')
|
||||||
world=0
|
world=0
|
||||||
for i in range(sizeworld):
|
for i in range(sizeworld):
|
||||||
if items[int("0x40000",16)+i] in finished and items[items[int("0x40000",16)+i]]['world']>world:
|
if items[int("0x40000",16)+i] in finished and items[items[int("0x40000",16)+i]]['world']>world:
|
||||||
|
@ -1019,7 +1031,7 @@ def on_key_press(symbol, modifiers):
|
||||||
|
|
||||||
@win.event
|
@win.event
|
||||||
def on_mouse_motion(x, y, dx, dy):
|
def on_mouse_motion(x, y, dx, dy):
|
||||||
global world,selected,allcout,over,level,sizeworld
|
global world,selected,allcout,over,level,sizeworld,finished
|
||||||
if level>=0:
|
if level>=0:
|
||||||
realx=(x-decx)/zoom
|
realx=(x-decx)/zoom
|
||||||
realy=(y-decy)/zoom
|
realy=(y-decy)/zoom
|
||||||
|
@ -1039,7 +1051,7 @@ def on_mouse_motion(x, y, dx, dy):
|
||||||
for i in range(sizeworld):
|
for i in range(sizeworld):
|
||||||
ele=items[items[int("0x40000",16)+i]]
|
ele=items[items[int("0x40000",16)+i]]
|
||||||
if ele['world']==world:
|
if ele['world']==world:
|
||||||
if x>ele['coordx']+20 and x<ele['coordx']+100 and y>ele['coordy']+0 and y<ele['coordy']+110 :
|
if x>ele['coordx']+20 and x<ele['coordx']+100 and y>ele['coordy']+0 and y<ele['coordy']+110 and (items[ele['value']] in finished or items[ele['value']]=="level0-0"):
|
||||||
selected=ele
|
selected=ele
|
||||||
if x>940 and y>win.height-100 and x<1024 and y<win.height:
|
if x>940 and y>win.height-100 and x<1024 and y<win.height:
|
||||||
selected=-2
|
selected=-2
|
||||||
|
@ -1096,7 +1108,7 @@ def on_mouse_press(x, y, button, modifiers):
|
||||||
world=world+1
|
world=world+1
|
||||||
elif selected>-1:
|
elif selected>-1:
|
||||||
level=selected['grid']
|
level=selected['grid']
|
||||||
if readgrid(selected['file']+".user")==False : readgrid(selected['file'])
|
if readgrid("user/"+selected['file'])==False : readgrid(selected['file'])
|
||||||
if selected['tuto']!="":
|
if selected['tuto']!="":
|
||||||
player.queue(pyglet.resource.media(selected['tuto']))
|
player.queue(pyglet.resource.media(selected['tuto']))
|
||||||
player.play()
|
player.play()
|
||||||
|
|
Loading…
Reference in New Issue