- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
window.onload = function()
{
m1 = new Matrix('matrix1', 20, 20);
m1.create();
var square = new Square(1, 2, 'right');
square.create();
setInterval(square.move, 50);
}
function Square(row, col, course)
{
this.body = [row, col];
this.course = course;
var that = this; // <-- 100500 iopta !!!
this.create = function()
{
m1.setCell(that.body[0], that.body[1], true);
}
this.move = function()
{
var last_body = that.body;
switch(that.course)
{
case 'right':
that.body[1]++;
break;
case 'left':
break;
case 'down':
break;
case 'up':
break;
}
m1.setCell(last_body[0], last_body[1], false);
m1.setCell(that.body[0], that.body[1], true);
}
}