Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Concept of building field in js game

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #152228
    Kuzyo
    Participant

    Hi everyone. Have idea to write simple js game? here I found good example of game http://www.lutanho.net/play/sokoban.html, but have some problem to understand part of code of this game –

    xscrn[n_xscrn++]=
    "############!"+
    "#..  #     ###!"+
    "#..  # $  $  #!"+
    "#..  #$####  #!"+
    "#..    @ ##  #!"+
    "#..  # #  $ ##!"+
    "###### ##$ $ #!"+
    "  # $  $ $ $ #!"+
    "  #    #     #!"+
    "  ############!";
    

    and inti function of the game:

    function Init(ll)
    { var cc, ii, jj, kk;
      for (ii=0; ii < XMax; ii++)
      { for (jj=0; jj < YMax; jj++)
          Fld[ii][jj]=0;
      }
      ii=0; jj=0;
      for (kk=0; kk<scrn[ll].length; kk++)
      { cc=scrn[ll].charAt(kk);
        if (cc==".") Fld[ii][jj]=1;
        if (cc=="#") Fld[ii][jj]=2;
        if (cc=="$") Fld[ii][jj]=3;
        if (cc=="*") Fld[ii][jj]=4;
        if (cc=="@") { Fld[ii][jj]=5; PosX=ii; PosY=jj; }
        if ((cc!=" ")&&(cc!="!")&&(Fld[ii][jj]==0)) alert(cc);
        if (cc=="!") { jj++; ii=0; }
        else ii++;
      }
      MoveCount=0;
      MaxMoveCount=0;
      RefreshScreen();
      window.document.images[0].src = Pic[Series][5].src;
      Now = new Date();
      StartTime = Now.getTime() / 1000;
      IsOver=false;
    }
    

    if i right understood the main purpose of this snippet is decide how looks the play field, can somebody explain concept how this code works?

    Maybe someone had previous experience in writing such games. Thanks guys.

Viewing 1 post (of 1 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.