Answer the question
In order to leave comments, you need to log in
I'm trying to write a 2048 game in the javascript programming language, and errors began to pour in. How to fix?
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
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 questionAsk a Question
731 491 924 answers to any question