diff --git a/js/star.js b/js/star.js
index b328fd1..0dc233d 100644
--- a/js/star.js
+++ b/js/star.js
@@ -96,15 +96,36 @@ function won_or_not( state ) {
}
function format_level( state ) {
- var dl = "";
- for each ( c in state.board ) {
- var classes = [ "starcell ", css_classes[ c ] ].join( '' );
- if ( state.moving == c) {
- classes = [ classes, " selected " ].join( '' );
+ function Replacer( conversionObject ) {
+
+ var regexpStr = '';
+ for ( var k in conversionObject ) {
+ regexpStr += ( regexpStr.length ? '|' : '' ) + k;
}
- dl = [ dl, "", c, ""].join( '' );
+ var regexpr = new RegExp( regexpStr, 'mig' ); // g: global, m:multi-line i: ignore case
+ return function(s) {
+ return s.replace( regexpr, function(str, p1, p2, offset, s) {
+ var a = conversionObject[ str ];
+ return a == undefined ? str : a;
+ } );
+ };
}
- return dl;
+
+ var substitutions = {
+ '#': '#',
+ 'x': 'x',
+ ' ': ' '
+ };
+ if ( state.moving == cell.BALL ) {
+ substitutions[ '@' ] = '@';
+ substitutions[ 'H' ] = 'H';
+ }
+ else {
+ substitutions[ '@' ] = '@';
+ substitutions[ 'H' ] = 'H';
+ }
+ var myReplacer = Replacer( substitutions );
+ return myReplacer( state.board );
}
function load_level( levelset, nb ) {