mirror of
https://github.com/neogeek23/neogeek23.github.io.git
synced 2026-02-04 10:58:21 +00:00
Add files via upload
This commit is contained in:
parent
bf4ba11d61
commit
41bea9fbd0
@ -1,6 +1,7 @@
|
|||||||
window.onload=function(){
|
window.onload=function(){
|
||||||
block_size = 4;
|
block_size = 4;
|
||||||
block_space = 1;
|
block_space = 1;
|
||||||
|
initial_tail_length = 3;
|
||||||
fps = 20;
|
fps = 20;
|
||||||
ms_in_sec = 1000;
|
ms_in_sec = 1000;
|
||||||
setup()
|
setup()
|
||||||
@ -38,6 +39,7 @@ function update(canvas, canvas_context, snek){
|
|||||||
snek.move();
|
snek.move();
|
||||||
snek.trim();
|
snek.trim();
|
||||||
target = snek.check(target);
|
target = snek.check(target);
|
||||||
|
snek.score();
|
||||||
};
|
};
|
||||||
|
|
||||||
function paint_background(canvas, canvas_context){
|
function paint_background(canvas, canvas_context){
|
||||||
@ -98,7 +100,7 @@ class Snek{
|
|||||||
constructor(x, y, direction, board, color){
|
constructor(x, y, direction, board, color){
|
||||||
this.head = new Block(x, y, board, color);
|
this.head = new Block(x, y, board, color);
|
||||||
this.tail = [];
|
this.tail = [];
|
||||||
this.length = 3;
|
this.length = initial_tail_length;
|
||||||
this.alive = 0;
|
this.alive = 0;
|
||||||
this.direction = direction;
|
this.direction = direction;
|
||||||
}
|
}
|
||||||
@ -175,5 +177,13 @@ class Snek{
|
|||||||
}
|
}
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
score(){
|
||||||
|
var score_element = document.getElementsByClassName("points_scored")[0];
|
||||||
|
var score_rate_element = document.getElementsByClassName("point_rate")[0];
|
||||||
|
|
||||||
|
score_element.innerHTML = ((this.length - initial_tail_length) * 100).toString();
|
||||||
|
score_rate_element.innerHTML = ((this.length - initial_tail_length) * 100/this.alive).toString();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user