K
K
krll-k2015-08-09 22:49:35
JavaScript
krll-k, 2015-08-09 22:49:35

I'm trying to write a 2048 game in the javascript programming language, and errors began to pour in. How to fix?

88d57440a0524799a9907d92aa3c44a0.png
jsbin.com/fivotoxuqu/edit?js ,console
Why is the following expression wrong? game.right(start)What did I not take into account, or how is it correct?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Taratin, 2015-08-09
@krll-k

function Game() {
  this.grid = ;
}
  
Game.prototype.right = function(){
    var grid = this.grid;
    //проверяем по горизонтали
    for(var x = 0; x < 4; x++){
      //проверяем по вертикали
      for(var y = 0; y < 4; y++){
        //если два последующих элемента равны
        if(grid[x][y] == grid[x][++y]){
           //то первое обнуляется
           grid[x][y] = 0;
           //второе умножается на двое
           grid[x][++y] = grid[x][y] + grid[x][++y];
        }
      }
    }
};

var start = new Game();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question