Ra_ Posted November 14, 2008 Report Share Posted November 14, 2008 ho buttato giù un po' di codice per creare il gioco dell'impiccato in mshell //by ratheking@gmail.com use array,ui,proc,graph,io,files,math; //apertura file di testo dc="e:\\vocabolario.txt"; zc=io.open(dc); wc=files.size(dc); qc=io.read(zc, wc); kc=split(qc, "\n"); mc=len(kc); ac=math.random()*1000000000; bc=ac%mc; word=substr(kc[bc], 0, len(kc[bc])-1); // //variabili generali parola=word; psb=4; print len(parola); z=array.create(len(parola),0); m=array.create(len(parola),"_"); l=array.new(); //graph graph.text(10,15,"L\'impiccato:") graph.text(10,30,"Premi un tasto per iniziare...") graph.text(10,45,"Tentativi:"+str(psb)); for t=0 to len(m)-1 do graph.text(10+10*t,200,m[t]); end; graph.show(); // ui.keys(false); ui.cmd(); //ciclo controllo while array.index(m, "_")#-1 do form=ui.query("inserisci lettera", "L'impiccato", ""); lettera=lower(form); if len(form)>1 then proc.stop(); else array.insert(l,0,form); //controllo lettera e creazione array for b=0 to len(parola)-1 do a=index(parola, lettera, b, true); array.fill(z, a, b, 1); end; //controllo possibilita'ÃÂ tentativo=array.index(z, -1); if tentativo=0 then psb--; if psb=0 then //graph graph.clear(); graph.text(130,120,"Sei morto!"); graph.text(30,200,"Soluzione: "+parola); //corpo graph.line(35,170,100,170); graph.line(35,80,35,170); graph.line(35,80,70,80); graph.line(70,80,70,90); graph.circle(60,90,20); graph.text(63,102,"xx"); graph.line(70,110,70,150); graph.line(70,110,55,120); graph.line(70,110,85,120); graph.line(70,150,55,160); graph.line(70,150,85,160); graph.show(); sleep(5000); // proc.stop(); end; else //sostituzione _ con lettere for c=0 to len(parola)-1 do if m[c]="_" then if c=z[c] then array.fill(m, lettera, c, 1); end; end; end; end; end; //graph e disegno tentativi graph.clear(); graph.text(10,15,"L\'impiccato:"); graph.text(10,45,"Tentativi:"+str(psb)); for t=0 to len(l)-1 do graph.text(220,20+t*20,l[t]); end; if psb=3 then graph.line(35,170,100,170); graph.line(35,80,35,170); graph.line(35,80,70,80); graph.line(70,80,70,90); elsif psb=2 then graph.line(35,170,100,170); graph.line(35,80,35,170); graph.line(35,80,70,80); graph.line(70,80,70,90); graph.circle(60,90,20); graph.line(70,110,70,150); graph.line(70,110,55,120); elsif psb=1 then graph.line(35,170,100,170); graph.line(35,80,35,170); graph.line(35,80,70,80); graph.line(70,80,70,90); graph.circle(60,90,20); graph.line(70,110,70,150); graph.line(70,110,55,120); graph.line(70,110,85,120); graph.line(70,150,55,160); graph.line(70,150,85,160); end; for t=0 to len(m)-1 do graph.text(10+10*t,200,m[t]); end; graph.show(); // ui.keys(false); ui.cmd(); end // graph.clear(); graph.text(50,120,"Hai vinto!"); graph.show(); sleep(2000); // le parole devono essere in "vocabolario.txt" su E: non è un codice molto "pulito" se fate delle migliorie postatele... Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now