@@ -75,7 +75,14 @@ function weightedChoice(weights) {
7575 *
7676 *
7777 * TODO:
78- * work on tutorial pane.
78+ * change populations implementation to be separate class:
79+ * array of arrays of keys. outer array holds pool of keys
80+ * that have been spawned <outer-index> times. Initially all in
81+ * outer entry #zero, which is shuffled once on start. When spawned,
82+ * shuffled into next outer-entry at random spot. When spawning,
83+ * go through each key in order until one is found that can spawn there.
84+ *
85+ * fix the broken progress/difficulty bar (broken because of cs selectors)
7986 * fix bugs with the new backtracking.
8087 *
8188 * make game runner_catch and gameover sounds.
@@ -193,18 +200,15 @@ class Game {
193200 this . restartButton . blur ( ) ;
194201
195202 // Apply any restart-only settings changes:
196- this . language = new Map ( Object . entries ( languages [
197- document . getElementById ( 'langSelect' ) . value ]
198- ) ) ;
203+ document . getElementById ( 'languageSource' ) . href =
204+ 'assets/languages/' + langSel . value + '.js' ;
205+ this . language = createLanguageInterpreter ( ) ;
199206 this . speed = Object . assign ( { } , Game . speeds [
200207 document . getElementById ( 'speedSelect' ) . value ]
201208 ) ;
202209
203210 // Reset all display-key populations:
204- this . populations = new Map ( ) ;
205- for ( const key of this . language . keys ( ) ) {
206- this . populations . set ( key , 0 ) ;
207- }
211+ this . populations = new Populations ( this . language . allKeys ( ) ) ;
208212 this . targets = [ ] ;
209213 this . corrupted = [ ] ;
210214 this . heat = 0 ;
@@ -318,11 +322,13 @@ class Game {
318322 const weights = new Map ( ) ;
319323 const lowest = Math . min ( ...this . populations . values ( ) ) ;
320324
325+ // TODO: see note for this class.
321326 const neighbors = this . adjacent ( pos , 2 ) ;
322- this . language . forEach ( ( val , key , map ) => {
323- if ( ! neighbors . some ( ( nbTile ) =>
324- ( nbTile . seq . includes ( val ) || val . includes ( nbTile . seq ) )
325- ) ) {
327+ this . language . allKeys ( ) . forEach ( ( key ) => {
328+ if ( ! neighbors . some ( ( nbTile ) => {
329+ let seq = this . language . key2seq ( key ) ;
330+ return ( nbTile . seq . includes ( seq ) || seq . includes ( nbTile . seq ) ) ;
331+ } ) ) {
326332 weights . set ( key , 4 ** ( lowest - this . populations . get ( key ) ) ) ;
327333 }
328334 } , this ) ;
@@ -331,7 +337,7 @@ class Game {
331337 this . populations . set ( choice , this . populations . get ( choice ) + 1 ) ;
332338 const tile = this . tileAt ( pos ) ;
333339 tile . key = choice ;
334- tile . seq = this . language . get ( choice ) ;
340+ tile . seq = this . language . key2seq ( choice ) ;
335341
336342 // If corrupting a tile:
337343 } else {
@@ -438,9 +444,11 @@ class Game {
438444 return closest ;
439445 }
440446
441- /* TODO: this will need to somehow tell
442- * which player triggered the event.
443- * triggered by some incoming remote data package:
447+ /* Handles restart and pause key commands,
448+ * and delegates backtrack and move commands
449+ * to their corresponding player. Players
450+ * make their inputs unique through keyboard
451+ * toggles {CapsLock, NumLock, & ScrollLock}.
444452 */
445453 movePlayer ( event ) {
446454 // Check if a single player wants to pause or restart:
@@ -466,13 +474,21 @@ class Game {
466474 if ( event . key . length > 1 && ! ( Player . backtrackKeys . has ( event . key ) ) ) {
467475 return ;
468476 }
469- // Temporary way to decide which
470- // player the move belongs to:
471- if ( ! event . shiftKey ) {
472- this . allPlayers [ 0 ] . move ( event . key ) ;
473- } else if ( this . allPlayers . length > 1 ) {
474- this . allPlayers [ 1 ] . move ( event . key ) ;
477+ // Decide which player the move belongs to:
478+ let playerNum = 0 ;
479+ playerNum &= event . getModifierState ( 'CapsLock' ) << 0 ;
480+ playerNum &= event . getModifierState ( 'NumLock' ) << 1 ;
481+ playerNum &= event . getModifierState ( 'ScrollLock' ) << 2 ;
482+
483+ // Clean input and send to handler:
484+ let key = event . key ;
485+ if ( key . length == 0 ) {
486+ key = key . toLowerCase ( ) ;
487+ if ( event . shiftKey ) {
488+ key = key . toUpperCase ( ) ;
489+ }
475490 }
491+ this . allPlayers [ playerNum ] . move ( key ) ;
476492 }
477493
478494 /* Chaser moves in the direction of the player.
@@ -831,7 +847,9 @@ class Game {
831847 return counter ;
832848 }
833849 tileAt ( pos ) { return this . grid [ pos . y * this . width + pos . x ] ; }
834- isCharacter ( tile ) { return ! ( this . language . has ( tile . key ) ) ; }
850+ isCharacter ( tile ) {
851+ return tile . key in Object . entries ( ) ;
852+ }
835853
836854 get misses ( ) {
837855 return parseInt ( this . misses_ . innerHTML ) ;
0 commit comments