themaze.py

Created by mathieu-croslacoste

Created on September 16, 2025

9.8 KB

Themaze for casio ported. needs https://my.numworks.com/python/mathieu-croslacoste/themaze_utils


from themaze_utils import*
class Player:
 def __init__(s,id):s.name=Dialogues[id];s.img=(p1(),p2(),p3())[id];s.hp=10;s.maxHp=10;s.Epee=id
 def AddHp(s,hp):s.hp=min(s.hp+hp,s.maxHp)
class Monster:
 def __init__(s,img,hp,atk):s.img=img;s.hp=hp;s.atk=atk
 def ApplyDmg(s,dmg):s.hp-=dmg;return s.hp<=0
guiSwitchChest=Gui();guiChest=Gui()
class Chest:
 def __init__(s,plat):s.plat=plat;s.InitGuiSel()
 def InitGuiSel(s):guiSwitchChest.Clr();s.guiSwitch=guiSwitchChest;s.guiSwitch.Locate(p1(),1,0);s.guiSwitch.Locate(p2(),1,int(dim[0]//3)+1);s.guiSwitch.Locate(p3(),1,int(dim[0]*2//3)+1);s.guiSwitch.Locate(Btn(s.guiSwitch.cur," ["+Dialogues[0]+"] "),dim[1]-2,0);s.guiSwitch.Locate(Btn(s.guiSwitch.cur," ["+Dialogues[1]+"] "),dim[1]-2,int(dim[0]//3)+1);s.guiSwitch.Locate(Btn(s.guiSwitch.cur," ["+Dialogues[2]+"] "),dim[1]-2,int(dim[0]*2//3)+1);s.guiSwitch.PlaceCenter("Qui recevra le cadeau ?",0)
 def Start(s):
  guiChest.Clr();s.gui=guiChest;s.gui.Locate(chest(),0,0);s.gui.PlaceCenter(Dialogues[10],0);s.actB=Btn(s.gui.cur,"[OK]");s.gui.PlaceCenter(s.actB,dim[1]-1);s.gui.BtnInput();lst=["une Epée","Plus de Coeurs"];st=30;n=R(st,st+10+len(lst)*3)
  for i in range(n):print("-> "+lst[i%len(lst)]);P(.4*(i/n))
  P(.6);BoxConfOK("Vous avez gagné "+lst[i%len(lst)]);id=i%len(lst)
  if id==0:
   swo=R(0,len(Swords)-1);BoxConfOK("Vous avez gagné l'épee : "+Swords[swo][0]);retour=s.guiSwitch.BtnInput();p=s.plat.players[retour]
   if Swords[p.Epee][1]>Swords[swo][1]:BoxConfOK("l'épee que vous avez reçue est moins puissante, par conséquent vous l'avez jetée")
   else:p.Epee=swo
  elif id==1:retour=s.guiSwitch.BtnInput();p=s.plat.players[retour];p.maxHp=min(p.maxHp+3,99);p.hp=p.maxHp
guiActFight=Gui();guiSwitchFight=Gui();guiFight=Gui()
class Fight:
 def __init__(s,plat,m):
  s.plat=plat;s.m=m;s.pId=0
  if s.plat.players[0].hp>0:s.pId=0
  elif s.plat.players[1].hp>0:s.pId=1
  elif s.plat.players[2].hp>0:s.pId=2
  guiFight.Clr();s.gui=guiFight;s.gui.Locate(m.img,0,10);txt=Dialogues[R(5,7)];cont=Btn(s.gui.cur," [Continuer]");s.gui.Locate(cont,dim[1]-1,0);s.gui.Locate(txt,dim[1]-2,0);s.gui.Draw();s.gui.DelWidget(cont);s.gui.DelWidget(txt);s.gui.DelWidget(m.img);BoxConfOK(Dialogues[3]);s.InitGuiAct();s.InitGuiSwitch();s.gui.Locate(m.img,1,15);
  s.gui.Locate(s.plat.players[s.pId].img,2,2);
  s.hp=StrVar(str(s.plat.players[s.pId].hp)+" <3");s.gui.Locate(s.hp,0,0);s.hpM=StrVar(str(m.hp)+" <3");s.gui.Locate(s.hpM,0,dim[0]-8);s.actB=Btn(s.gui.cur,"[Actions]");s.gui.Locate(s.actB,dim[1]-1,1)
 def InitGuiAct(s):guiActFight.Clr();s.guiAct=guiActFight;s.guiAct.PlaceCenter("Choisissez une action",0);s.guiAct.PlaceCenter(Btn(s.guiAct.cur,"[Attaquer]"+" "*13),2);s.guiAct.PlaceCenter(Btn(s.guiAct.cur,"[Changer de personnage]"),3);s.guiAct.PlaceCenter(Btn(s.guiAct.cur,"[Se proteger]"+" "*10),4)
 def InitGuiSwitch(s):guiSwitchFight.Clr();s.guiSwitch=guiSwitchFight;s.guiSwitch.Locate(p1(),0,0);s.guiSwitch.Locate(p2(),0,int(dim[0]//3)+1);s.guiSwitch.Locate(p3(),0,int(dim[0]*2//3)+1);s.guiSwitch.Locate(Btn(s.guiSwitch.cur," ["+Dialogues[0]+"] "),dim[1]-3,0);s.guiSwitch.Locate(Btn(s.guiSwitch.cur," ["+Dialogues[1]+"] "),dim[1]-3,int(dim[0]//3)+1);s.guiSwitch.Locate(Btn(s.guiSwitch.cur," ["+Dialogues[2]+"] "),dim[1]-3,int(dim[0]*2//3)+1);s.guiSwitch.Locate(Btn(s.guiSwitch.cur," [Retour] "),dim[1]-1,int(dim[0]*2//3)+2)
 def GuiSwitch(s):
  while 1:
   retour=s.guiSwitch.BtnInput()
   if retour==3:return 0
   if s.plat.players[retour].hp<=0:BoxConfOK(Dialogues[4])
   else:s.gui.DelWidget(s.plat.players[s.pId].img);s.pId=retour;s.gui.Locate(s.plat.players[s.pId].img,2,2);return 1
 def Atk(s):
  prob=5
  if s.pId==1:prob+=2
  n=R(0,10)<=prob
  if n:
   dmg=Swords[s.plat.players[s.pId].Epee][1];BoxConfOK("Vous avez infligé "+str(dmg)+" points de dégat");prob=3
   if s.pId==2:prob+=2
   n=R(0,10)<=prob
   if n:
    crit=3
    if s.pId==2:crit+=2
    BoxConfOK("Coup Critique : Vous avez touché un point faible du monstre, par conséquent vous avez infligé "+str(crit)+" points de dégat supplémentaire");dmg+=crit
   return s.m.ApplyDmg(dmg)
  else:BoxConfOK("Vous avez manqué votre attaque");return 0
 def pAlive(s):return any(p.hp>0 for p in s.plat.players)
 def Start(s):
  while s.m.hp>0 and s.pAlive():
   s.hpM.dat=str(s.m.hp)+" <3";s.hp.dat=str(s.plat.players[s.pId].hp)+" <3";s.gui.Draw();sel=0;ProbEnn=5
   if s.pId==0:ProbEnn-=1
   while not sel:
    retour=s.guiAct.BtnInput()
    if retour==0:
     sel=1
     if s.Atk():break
    elif retour==1:sel=s.GuiSwitch()
    elif retour==2:
     sel=1;ProbEnn-=3;s.plat.players[s.pId].AddHp(1)
     if s.pId==0:s.plat.players[s.pId].AddHp(1)
     break
   if s.m.hp<=0:break
   s.hpM.dat=str(s.m.hp)+" <3";s.hp.dat=str(s.plat.players[s.pId].hp)+" <3";s.gui.Locate("Waiting...",dim[1]-1,1);s.gui.Print();s.gui.DelWidget("Waiting...");P(.6);BoxConfOK("L'ennemi attaque !");n=R(0,10)<=ProbEnn
   if n:
    dmg=s.m.atk
    if s.pId==1:dmg-=1
    s.plat.players[s.pId].hp-=dmg;BoxConfOK("Vous avez pris "+str(dmg)+" points de degat")
   else:BoxConfOK("L'ennemi a rate son attaque")
   if s.plat.players[s.pId].hp<=0:
    BoxConfOK(([Dialogues[0],Dialogues[1],Dialogues[2]])[s.pId]+" est mort !");s.gui.DelWidget(s.plat.players[s.pId].img)
    if s.plat.players[0].hp>0:s.pId=0
    elif s.plat.players[1].hp>0:s.pId=1
    elif s.plat.players[2].hp>0:s.pId=2
    s.gui.Locate(s.plat.players[s.pId].img,2,2)
  if s.m.hp<=0:BoxConfOK(Dialogues[8]);return 1
  else:BoxConfOK(Dialogues[9]);return 0
guiInv=Gui();guiPlat=Gui();guiMapEXT=Gui()
class Plateau:
 def __init__(s,x,y,maze,seed):s.players=[Player(0),Player(1),Player(2)];s.Map=maze;s.X,s.Y=x,y;s.seed=seed;s.diff=1;s.Blocks=[];s.gui=guiPlat;s.DontSpawn=[str(s.X)+":"+str(s.Y)];s.InvInit()
 def InvInit(s):s.guiInv=guiInv;s.guiInv.PlaceCenter(Btn(s.guiInv.cur,"[Retour]     "),2);s.guiInv.PlaceCenter(Btn(s.guiInv.cur,"[Sauvegarder]"),3);s.guiInv.PlaceCenter(Btn(s.guiInv.cur,"[Carte]"+" "*6),4);s.guiInv.PlaceCenter(Btn(s.guiInv.cur,"[Quitter]    "),6)
 def ClrRoom(s):
  s.gui.Clr();s.Blocks=[]
  for i in range(dim[1]//2):
   temp=[]
   for o in range(dim[0]//2):temp.append(Block())
   s.Blocks.append(temp)
 def PrintMap(s):
  NewImg=[];y=0
  for i in s.Map:
   temp=[];x=0
   for o in i:
    if o=="S":temp.append("D")
    elif o=="X":temp.append("F")
    elif s.X==x and s.Y==y:temp.append("X")
    else:temp.append(o)
    x+=1
   NewImg.append(temp);y+=1
  guiMapEXT.Clr();guiMap=guiMapEXT;guiMap.Locate(Img(NewImg),-1,-1);guiMap.Locate(Btn(guiMap.cur,""),dim[1]-1,0);guiMap.Draw()
 def MakeRoom(s):
  s.ClrRoom();lst=["|","-","+"];print(s.Y,s.X)
  if len(s.Map)>s.Y+1 :
   if s.Map[s.Y+1][s.X]in lst:
    for i in range(len(s.Blocks[0])):s.Blocks[-1][i]=Wall()
   else:s.Blocks[-1][dim[0]//4]=Door(s.gui)
  if 0<=s.Y-1:
   if s.Map[s.Y-1][s.X]in lst:
    for i in range(len(s.Blocks[0])):s.Blocks[0][i]=Wall()
   else:s.Blocks[0][dim[0]//4]=Door(s.gui)
  if 0<=s.X-1:
   if s.Map[s.Y][s.X-1]in lst:
    for i in range(len(s.Blocks)):s.Blocks[i][0]=Wall()
   else:s.Blocks[dim[1]//4][0]=Door(s.gui)
  if len(s.Map[0])>s.X :
   if s.Map[s.Y][s.X+1]in lst:
    for i in range(len(s.Blocks)):s.Blocks[i][-1]=Wall()
   else:s.Blocks[dim[1]//4][-1]=Door(s.gui)
  s.Blocks[0][0]=Wall();s.Blocks[-1][0]=Wall();s.Blocks[0][-1]=Wall();s.Blocks[-1][-1]=Wall();indY=0
  for i in s.Blocks:
   indX=0
   for o in i:s.gui.Locate(o.Get(),indY*2,indX*2);indX+=1
   indY+=1
 def Spawn(s):
  if not str(s.X)+":"+str(s.Y)in s.DontSpawn:
   s.DontSpawn.append(str(s.X)+":"+str(s.Y));n=R(0,1)
   if n==0:m=Monster(([Monster1(),Monster2()])[R(0,1)],int(5*s.diff),int(2*s.diff));fight=Fight(s,m);vict=fight.Start();s.diff+=.1;return vict
   elif n>=1:c=Chest(s);c.Start()
  return 1
 def GetInfos(s):dat=(s.seed,s.X,s.Y,min(int(s.diff),9),s.players[0].maxHp,s.players[0].Epee,s.players[1].maxHp,s.players[1].Epee,s.players[2].maxHp,s.players[2].Epee);return dat,(2,2,2,1,2,1,2,1,2,1)
 def Save(s):
  dat,poid=s.GetInfos();res=""
  for i in range(len(dat)):res+="00"[:poid[i]-len(str(data[i]))]+str(data[i])
  return res
 def Load(s,Str):
  _,poid=s.GetInfos();dat=[];i=0
  while len(Str):dat.append(int(Str[:poid[i]]));Str=Str[poid[i]:];i+=1
  s.seed=dat[0];s.X=dat[1];s.Y=dat[2];s.diff=dat[3];s.players[0].maxHp=dat[4];s.players[0].Epee=Swords[dat[5]];s.players[1].maxHp=dat[6];s.players[1].Epee=Swords[dat[7]];s.players[2].maxHp=dat[8];s.players[2].Epee=Swords[dat[9]];s.DontSpawn.append(str(s.X)+":"+str(s.Y))
 def Inv(s):
  retour=s.guiInv.BtnInput()
  if retour==0:return 1
  elif retour==1:BoxConfOK("voici le code qu'il faut noter : "+str(s.Save()));return 1
  elif retour==2:s.PrintMap();return 1
  elif retour==3:n=BoxConfValid("Etes-vous sur de vouloir quitter ?");return not n
 def Move(s):
  if s.Map[s.Y][s.X]=="X":
   for i in Dialogues[12]:BoxConfOK(i)
   return 0
  s.MakeRoom();s.gui.Print();battle=s.Spawn()
  if not battle:return 0
  retour=None
  while retour==None:
   retour,cmd,_=s.gui.Draw()
   if retour==None:s.gui.UpCursor()
   if cmd=="9":n=s.Inv();return n
  btn=s.gui.cur.Btns[retour];id=s.gui.WidgetId(btn);widget=s.gui.Widgets[id];Wx,Wy=widget[3],widget[2];print(Wx,Wy,s.X,s.Y)
  if Wx==0:s.X-=1
  elif Wx==dim[0]-2:s.X+=1
  elif Wy==0:s.Y-=1
  elif Wy==dim[1]-2:s.Y+=1
  return 1
def Start(seed=0,code=None):
 symbols=('S','X','|','-','+',' ');Tmaze=str(C_Maze(15,4,0,symbols));print(Tmaze);Maze=[];x,y=0,0;indY=0
 for i in Tmaze.split("\n"):
  temp=[];indX=0
  for o in i:
   if o=='S':x,y=indX,indY
   temp.append(o);indX+=1
  Maze.append(temp);indY+=1
 if len(Maze[-1])<len(Maze[0]):del Maze[-1]
 plat=Plateau(x,y,Maze,seed)
 if code:plat.Load(code)
 return plat
_quit=0
if dim[0]%2!=0 or dim[1]%2!=0:BoxConfOK("La résolution de votre écran n'est pas un multiple de 2");_quit=1
while 1-_quit:
 choix=MainMenu();_quit=1
 if choix==0:
  for i in Dialogues[11]:BoxConfOK(i)
  seed=R(0,99);plat=Start(seed);res=1
  while res:res=plat.Move()
 elif choix==1:
  Clr();code=input("Entrez le code:");plat=Start(code=code);res=1
  while res:res=plat.Move()
 elif choix==2:_quit=1

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.