Skip to content

Commit

Permalink
switch to async/await
Browse files Browse the repository at this point in the history
  • Loading branch information
ghuysmans committed Jul 19, 2021
1 parent cc52f70 commit eeb4bab
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 100 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ The library gives access to a few different functions. The most important ones a
```
io.println() : Prints a message inside the "console".
io.printhr() : Prints a large horizontal bar inside the "console".
yield io.input(): Creates a inline input box inside the "console"; the user must hit Enter to submit the input.
yield io.click(): Creates a horizontal list of buttons for the user to click on.
yield sleep(ms) : Sleep ms milliseconds (and refresh the screen during sleep).
await io.input(): Creates a inline input box inside the "console"; the user must hit Enter to submit the input.
await io.click(): Creates a horizontal list of buttons for the user to click on.
await sleep(ms) : Sleep ms milliseconds (and refresh the screen during sleep).
io.clr() : Clear all text inside the "console".
io.close() : If your program has finished, you can clearly indicate that by calling close().
```
Expand All @@ -68,10 +68,10 @@ Here is a small JavaScript demonstration program (it's really self-explanatory!)
io.printhr();
io.println('Are you happy?!');
var r=yield io.click('yes','no');
var r=await io.click('yes','no');
io.println('you clicked '+r+'\n');
var s=yield io.input('Enter your name:');
var s=await io.input('Enter your name:');
io.println('Hello '+s+'\n');
io.close();
```
Expand Down
8 changes: 4 additions & 4 deletions demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ <h1>Learn Javascript</h1>
<script>
"use strict";
var io=new IOKranf('iokranf_container');
co(function*(){
(async function(){

io.println('Hello!');
io.printhr();

io.println('Are you happy?!');
var r=yield io.click('yes','no');
var r=await io.click('yes','no');
io.println('you clicked '+r+'\n');

var s=yield io.input('Enter your name:');
var s=await io.input('Enter your name:');
io.println('Hello '+s+'\n');
io.close();

})</script>
})();</script>
</body>
</html>
6 changes: 3 additions & 3 deletions demos/Mental_calculation.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ <h1>Mental calculation</h1>
alarm=setTimeout(refreshTimer,100);
}

co(function*(){
(async function(){
var maxNumber=10;
var a=Math.floor(Math.random()*maxNumber+1);
var b=Math.floor(Math.random()*maxNumber+1);
response=a+b;
alarm=setTimeout(refreshTimer,100);
var x=yield io.input(a+" + "+b+" =? ");
var x=await io.input(a+" + "+b+" =? ");
clearTimeout(alarm);
if (Number(x)!=response) io.println("You lost! The correct answer was "+response);
else
Expand All @@ -54,7 +54,7 @@ <h1>Mental calculation</h1>
io.println("You win in "+Math.round(elapsedTime/10)/100+" second(s) (or "+elapsedTime+" milliseconds).");
}
io.close();
})
})();

</script>
</body>
Expand Down
6 changes: 3 additions & 3 deletions demos/draw_square_v1.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ <h1>Learn Javascript</h1>
<script>
"use strict";
var io=new IOKranf('iokranf_container');
co(function*(){
(async function() {
var j;
io.println('Hello World!');
io.printhr();
var n=yield io.input("What's the square size? ");
var n=await io.input("What's the square size? ");
if(n==1)
io.print("*");
else
Expand Down Expand Up @@ -55,6 +55,6 @@ <h1>Learn Javascript</h1>
io.println('**********');
*/
io.close();
})</script>
})();</script>
</body>
</html>
6 changes: 3 additions & 3 deletions demos/draw_square_v1_FR.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ <h1>Learn Javascript</h1>
<script>
"use strict";
var io=new IOKranf('iokranf_container');
co(function*(){
(async function() {
var j;
io.println('Hello World!');
io.printhr();
var n=yield io.input('Donnez la taille du carré:');
var n=await io.input('Donnez la taille du carré:');
if(n==1)
io.print("*");
else
Expand Down Expand Up @@ -55,6 +55,6 @@ <h1>Learn Javascript</h1>
io.println('**********');
*/
io.close();
})</script>
})();</script>
</body>
</html>
6 changes: 3 additions & 3 deletions demos/draw_square_v2.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h1>Learn Javascript</h1>
<script>
"use strict";
var io=new IOKranf('iokranf_container');
co(function*(){
(async function() {
var j;
io.println('Hello World!');
io.printhr();
Expand All @@ -21,7 +21,7 @@ <h1>Learn Javascript</h1>

var s="";

var n=yield io.input("What's the square size? ");
var n=await io.input("What's the square size? ");
if(n==1) s="*";
else
{
Expand Down Expand Up @@ -51,6 +51,6 @@ <h1>Learn Javascript</h1>
io.print(s);

io.close();
})</script>
})();</script>
</body>
</html>
6 changes: 3 additions & 3 deletions demos/draw_square_v2_FR.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h1>Learn Javascript</h1>
<script>
"use strict";
var io=new IOKranf('iokranf_container');
co(function*(){
(async function() {
var j;
io.println('Hello World!');
io.printhr();
Expand All @@ -21,7 +21,7 @@ <h1>Learn Javascript</h1>

var s="";

var n=yield io.input('Donnez la taille du carré:');
var n=await io.input('Donnez la taille du carré:');
if(n==1) s="*";
else
{
Expand Down Expand Up @@ -51,6 +51,6 @@ <h1>Learn Javascript</h1>
io.print(s);

io.close();
})</script>
})();</script>
</body>
</html>
8 changes: 4 additions & 4 deletions demos/simple_tetrisk_v0.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<script>
"use strict";
var io=new IOKranf('iokranf_container');
co(function*(){
(async function() {

var music=new Audio("media/tetrisk_Music_GameBoy.m4a"); music.loop=true; music.volume=0.3;
var s;
Expand Down Expand Up @@ -55,22 +55,22 @@

{
io.println("Ready?");
yield io.click("Yes!");
await io.click("Yes!");
io.clr();
music.play();
var y=0;
for(y=0;y<16;y+=1)
{
initializeS();
drawTetrisL(4,y);
yield sleep(200);
await sleep(200);
io.clr(); io.print(s);
}
new Audio("media/tetrisk_land.mp3").play();
music.pause(); music.currentTime=0;
io.close();
}
})
})();
</script>
</body>
</html>
6 changes: 3 additions & 3 deletions demos/simple_tetrisk_v1.html
Original file line number Diff line number Diff line change
Expand Up @@ -613,9 +613,9 @@
else if ((event.keyCode === 32)||(event.keyCode === 38)) tourner();
}

co(function*(){
(async function() {
io.println("\nSelect\n Music:\n");
var r=yield io.click("99","GameBoy","Blitz","No Music");
var r=await io.click("99","GameBoy","Blitz","No Music");
if(r=="99") musicB.play();
else if(r=="GameBoy") musicC.play();
else if(r=="Blitz") musicA.play();
Expand All @@ -626,7 +626,7 @@
augmenterScore(0);
document.addEventListener("keydown",keyPressed);
reveil = setTimeout(bougerPiece,1);
})
})();
</script>
</body>
</html>
6 changes: 3 additions & 3 deletions demos/tetrisk.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
var musicC=new Audio("media/tetrisk_Music_GameBoy.m4a"); musicC.loop=true; musicC.volume=0.30;
var io=new IOKranf('iokranf_container');
var io2=new IOKranf('container2');
co(function*(){
(async function() {
var s="",n=10;
var alarm;

Expand Down Expand Up @@ -324,7 +324,7 @@
piece_id=piece_id_next; piece_id_next=Math.floor(Math.random()*7);

io.println("\nSelect\n Music:\n");
var r=yield io.click("99","GameBoy","Blitz","No Music");
var r=await io.click("99","GameBoy","Blitz","No Music");
if(r=="99") musicB.play();
else if(r=="GameBoy") musicC.play();
else if(r=="Blitz") musicA.play();
Expand All @@ -334,7 +334,7 @@
document.addEventListener("keydown",keyPressed);
alarm = setTimeout(dropPiece,1);
}
})
})();
</script>
</body>
</html>
6 changes: 3 additions & 3 deletions demos/tetrisk_FR.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
var musicC=new Audio("media/tetrisk_Music_GameBoy.m4a"); musicC.loop=true; musicC.volume=0.30;
var io=new IOKranf('iokranf_container');
var io2=new IOKranf('container2');
co(function*(){
(async function() {
var s="",n=10;
var reveil;

Expand Down Expand Up @@ -340,7 +340,7 @@
piece_id=piece_id_suivant; piece_id_suivant=Math.floor(Math.random()*7);

io.println("\nSelect\n Music:\n");
var r=yield io.click("99","GameBoy","Blitz","No Music");
var r=await io.click("99","GameBoy","Blitz","No Music");
if(r=="99") musicB.play();
else if(r=="GameBoy") musicC.play();
else if(r=="Blitz") musicA.play();
Expand All @@ -350,7 +350,7 @@
document.addEventListener("keydown",keyPressed);
reveil = setTimeout(bougerPiece,1);
}
})
})();
</script>
</body>
</html>
14 changes: 7 additions & 7 deletions demos/zork_mini_FR.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,26 @@ <h1>Mini Zork</h1>
var io2=new IOKranf('container2');
var status="naked";

function *pageCour()
async function pageCour()
{
io.printhr();
new Audio("media/tetrisk_move.mp3").play();
io.printImage("media/zork_castle_court.jpg","300px");
io.println("\nVous vous trouvez dans la cour intérieure du château.");
var x=yield io.click("Aller à la porte du château","Entrer dans l'armurerie");
if (x=="Entrer dans l'armurerie") co(pageArmurie());
var x=await io.click("Aller à la porte du château","Entrer dans l'armurerie");
if (x=="Entrer dans l'armurerie") await pageArmurie();
else if (x=="Aller à la porte du château") pagePorte();
}

function *pageArmurie()
async function pageArmurie()
{
new Audio("media/tetrisk_move.mp3").play();
io.printhr();
io.printImage("media/zork_castle_armory.jpg","300px");
io.println("\nVous êtes dans l'armurerie, il y a plein d'armes et une bouteille.");
for(;;)
{
var x=yield io.click("Prendre une arme","Boire la bouteille","Retourner dans la cour");
var x=await io.click("Prendre une arme","Boire la bouteille","Retourner dans la cour");
if (x=="Prendre une arme")
{
if (status=="naked")
Expand Down Expand Up @@ -70,7 +70,7 @@ <h1>Mini Zork</h1>
}
else if (x=="Retourner dans la cour") break;
}
co(pageCour());
await pageCour();
}

function pagePorte()
Expand All @@ -96,7 +96,7 @@ <h1>Mini Zork</h1>
io.autoScroll(true);
io.println("OBJECTIF : Vous devez vous échapper du château.\n");
io2.printImage("media/zork_inventory1.png","120px");
co(pageCour());
pageCour();
}
</script>
</body>
Expand Down
Loading

0 comments on commit eeb4bab

Please sign in to comment.