From 0ae3d1cfdc5c56da9709b31231b48fa73e9c7937 Mon Sep 17 00:00:00 2001 From: yutaro urata Date: Sun, 17 Dec 2023 19:56:43 -0800 Subject: [PATCH 1/2] Added Morse_trainer.js and associated thumbnail --- games/Morse_trainer.js | 244 ++++++++++++++++++++++++++++++++++++ games/img/Morse_trainer.png | Bin 0 -> 5053 bytes 2 files changed, 244 insertions(+) create mode 100644 games/Morse_trainer.js create mode 100644 games/img/Morse_trainer.png diff --git a/games/Morse_trainer.js b/games/Morse_trainer.js new file mode 100644 index 0000000000..eca4c2d1a6 --- /dev/null +++ b/games/Morse_trainer.js @@ -0,0 +1,244 @@ +/* +Morse code trainer by Yutaro +Has two modes: Morse to text and text to morse +Used for learning morse code +*/ + +//backgrounds +const titleScreen = "t"; +const menuSelect = "m"; + +const maps = [ + map`` +] +setLegend( + [titleScreen,bitmap` +2222222222222222 +2222222222222222 +2222222222222222 +2222222222222222 +2222222222222222 +2222222222222222 +2222222222222222 +2222222222222222 +2222222222222222 +2222222222222222 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000`], + [menuSelect,bitmap` +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000`], +) + +setMap(map`.`) + +let currentState = "title"; +let sound = false; +//display screen drawing function +function drawScreen(){ + clearText() + if (currentState == "title"){ + setBackground(titleScreen); + addText("Morse Trainer", { + x: 4, + y: 4, + color: color`3` + }) + + //sound message + addText(`Sound: ${sound}`, { + x: 4, + y: 6, + color: color`3` + }) + + addText("Press A to start\nD to toggle sound", { + x: 2, + y: 12, + color: color`3` + }) + } + + if (currentState == "modeSelect"){ + setBackground(menuSelect); + addText("W: Instructions", { + x: 1, + y: 5, + color: color`3` + }) + + addText("S: morse -> text", { + x: 1, + y: 7, + color: color`3` + }) + + addText("A: text -> morse", { + x: 1, + y: 9, + color: color`3` + }) + } + +} + +drawScreen(); + + +//character database +const characters = {"0":"-----","1":".----","2":"..---","3":"...--","4":"....-","5":".....","6":"-....","7":"--...","8":"---..","9":"----.","a":".-","b":"-...","c":"-.-.","d":"-..","e":".","f":"..-.","g":"--.","h":"....","i":"..","j":".---","k":"-.-","l":".-..","m":"--","n":"-.","o":"---","p":".--.","q":"--.-","r":".-.","s":"...","t":"-","u":"..-","v":"...-","w":".--","x":"-..-","y":"-.--","z":"--..",".":".-.-.-",",":"--..--","?":"..--..","!":"-.-.--","-":"-....-","/":"-..-.","@":".--.-.","(":"-.--.",")":"-.--.-"} + +//sorted version +const charIndex = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9"] + +//funciton to convert the typed morese code to text +function findCharacter(moresePattern){ + //not found + let ret = "NF"; + let keys = Object.keys(characters); + for(let i = 0;i { + if(currentState == "title"){ + sound = !sound; + drawScreen(); + } + if(currentState == "morseText"){ + currentMorse = ""; + game(); + return; + } + if(currentState == "textMorse"){ + textMorsedisplay = ""; + charLen = 0; + game(); + } +}); + +onInput("a", () => { + if(currentState == "title"){ + currentState = "modeSelect"; + drawScreen(); + return; + } + if(currentState == "modeSelect"){ + currentState = "textMorse"; + game(); + return; + } + if(currentState == "morseText"){ + let tem = findCharacter(currentMorse); + currentMorse = ""; + if(tem != "NF")currentCharacterBuffer+=tem; + game(); + return; + } + + if(currentState == "textMorse"){ + charLen+=characters[charIndex[currentCharIndex]].length+1; + if(charLen>15) {textMorsedisplay+="\n";charLen = 0;} + textMorsedisplay+=characters[charIndex[currentCharIndex]]+" "; + game(); + } +}); + +onInput("w", () => { + if(currentState == "modeSelect"){ + currentState = "instructions"; + game(); + return; + } + if(currentState == "morseText"){ + currentMorse+="."; + game(); + } + if(currentState == "textMorse"){ + if(currentCharIndex { + if(currentState == "modeSelect"){ + currentState = "morseText"; + game(); + return; + } + if(currentState == "morseText"){ + currentMorse+="-"; + game(); + } + if(currentState == "textMorse"){ + if(currentCharIndex>=0)currentCharIndex-=1; + game(); + } +}); + + diff --git a/games/img/Morse_trainer.png b/games/img/Morse_trainer.png new file mode 100644 index 0000000000000000000000000000000000000000..b8eea73caf1008390d4c3ac05c7be7f70baea429 GIT binary patch literal 5053 zcmeHKYfw|^89pq#u9sp5yY7wh0%EunNP;(rktAnWS3*D%B#^`<7a)uN>brT?>CXk-xwm02<_o zm$30J;nSE;0ida5%R=&du)QhsP#hTmJo4XsoJz(g&%=w!smD)cAInJ1j5(j3d@eaV z8D0Yb&?_Y^HS=>)YDPBMD+~vEQN6X{ zFVScAnNP%AyRsoI+xghcmNb)MZ<2^^b3EMKWp{{&d;p+ftb)tT1-pfjLihUvw;(nId7ldAr$(E74;DzqVP> z{kOYvG@JA0=5Dr~d~SK<1OSH~EQcU0=?r=L5*QTstMra426{wz!RZiMNGAp}rmNh_MXcnP z6zpQxEGn@2j|{4=Jy<4@R8zC2B2KXFV8@4}t_O zG{lL)!{%_?0`#cumzb3oGGqcI&;F<1M*@ef|ycC6uhKX3TM667w)S0ff3}|X|7Otih=ShF|J^=iD({fNEgjZyJ zL&CEtWvu&1lyLNUlvK441aiu&X;QxU(j`-Y(OO7JrSrr?mQGZWe3D~{53o@W;~`yK z&s_q-^ZHsIui^#Y33UTT*lWFe#ZmreO@`fJF^UgI*{wEDQe)){MVDP;d}djgQ!moN z_a@SXQKu=oCY@PIz+uVVgxOvwQYakd{D=6u4`;U#{xIyLa*k?1DF*!e(@er7Z)T)w z2*rKnszlgVCdXZIvNMQi#aZH%u8ptJMph3xpuA55Iecf~A_)M6T#T026K-QfvI8e_ zA0@~{CJtjOfejJV{9sW2f>-a?YsjLmnj%YanfvVx7kb^d7LOU(2Rw7Qg-R3!rf4UN zLlo}BreQ;9`&WIm9a+})@KLu@s4lF)97_y(lltMd8QONyiI@II5dd&`=W;klp573I z<%-!c;B0vitA@cJl4?A%8iENCs#xOv1fD`Jb0s$8={Om>5hc?Z+J{i8leaY(=CQu zW(-#r^s4?h0HA<>Ay;j%EBfua`4$DOyW~f@B&lnWZkyZ&0B2aMHKi3Cv~Ipd%l~bc z%+K3(LnRf3^X8;QhxPjw#}t<-6u!ermI;k{2>$+?+F}BE_;f`JrhK)4!78D&FQ$y= zPQ`ovluDY8aDS0FO({tEo2j99kW;eOUzF}tD}ppe@hnQ2W|)o2%H|o2CrcQ8!TQ=% zlWHoLav+|eeQ&umLWQ-kOa(rTno_8_^>D*QV^QJwk^(DJlzXo1%Kz%mq!aA1C+g|U zMG>*MWrl)5Y$8NEoGNpF|m%A55kbBX-l6g21lur#=xWp%=7)ncAirnX5uorXx%A2#8a0{f&I% z$zL47t9%+OZ=&jz(stZk9iqQ5eT6b4pUVriOtVqiM=VD5SX8$mxDyBcj-^t z=jIRc_0li=@MB3zs3Na}(kT@@EFy7+?JnhzO)$6DYx;mYnJf z%2Tw1oR`Ru3+Z$BS9oNJtd$5Ccz#`raZ!tbJ=leUe6yddlh(0;*n0$YM0J`jV_F^d zxjjs9)%eN!zAnu8Q{3RfT^*(INp(U+%lO8I@R2>^KRt>iiv8f%T4b`T`rqKh2B#Kz?k z`Uibf!P~uK_*_eKI}tJ`J~PZAYC4rf|BC{s8J07NLxIFeLyJevO^h5Z!ld8=!c=vF zy=GZrfp>A6HjG6R_(+Fk+xtg86c9SB_}uOeIj0lVXyi2c!KF-nGvF9BeymU?Ty_L0G_u+R zwlt8@>$csyZ>8hJwLDSGx$l&s(04D-u8|M$a5A-8xvaDAk7VEF4uhM;z(jAwqEmm6 WVmDy^SPw4%(ZBxeV8ekkzyCW|QEX2D literal 0 HcmV?d00001 From 2b05d2525362639ef7f0dca9a05d0d7d2f4e5cad Mon Sep 17 00:00:00 2001 From: yutaro urata Date: Thu, 21 Dec 2023 13:04:28 -0800 Subject: [PATCH 2/2] removed unused audio capabilities --- games/Morse_trainer.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/games/Morse_trainer.js b/games/Morse_trainer.js index eca4c2d1a6..e47f94fff5 100644 --- a/games/Morse_trainer.js +++ b/games/Morse_trainer.js @@ -70,11 +70,11 @@ function drawScreen(){ color: color`3` }) - addText("Press A to start\nD to toggle sound", { - x: 2, - y: 12, - color: color`3` - }) + //addText("Press A to start\nD to toggle sound", { + // x: 2, + // y: 12, + // color: color`3` + //}) } if (currentState == "modeSelect"){