Html>
<meta charset= "Utf-8" >
<style>
#conatiner {
width:400px;
height:500px;
border:1px solid #eee;
position:relative;
}
</style>
<body>
<span>typing</span>
<div>
<span id= "score" >0</span> score;
Need: <span id= "need" ></span> points;
</div>
<div id= "Conatiner" >
</div>
<button id= "Start" > Start Game </button>
</body>
<script>
var Econatiner = document.getElementById ("Conatiner");
var escore = document.getElementById ("score");
var getrandom = function () {
Immediately a character from 97 to 122;
var charcode = 97+math.floor (Math.random () *26);
var speed = Math.ceil (Math.random ());
return {
Code:String.fromCharCode (CharCode),
Speed:speed,
y:0,
X:math.floor (Math.random () *390),
}
};
function Game (n, score, Econatiner, Escore, need) {
This.need = need;
This.need.innerHTML = score;
This.showarr = []; List of Character objects
this.shoted = 0;
THIS.N = n;
This.score = score;
This.econatiner = Econatiner;
This.escore = Escore;
This.events ();
This.run ();
This.timer = SetInterval (This.run.bind (this), game.gamepad[n].speed);
}
Game.gamepad = {
1: {
speed:100
},
2 4 5
Speed:90
},
3: {
Speed:70
},
4: {
Speed:40
},
5: {
Speed:20
}
}
Game.prototype.keyup = function (EV) {
Showarr = This.showarr;
for (var i=0; i < showarr.length; i++) {
if (Showarr[i].code = = = Ev.key | | String.fromCharCode (Ev.keycode). toLowerCase () = = Showarr[i].code) {
Showarr.splice (i,1);
this.shoted++;
This.eScore.innerHTML = this.shoted;
if (this.shoted = = = This.score && game.gamepad[this.n+1] = = = undefined) {
Alert ("Little man Hello, you are fast, really good fast");
}else if (this.shoted = = = This.score) {
This.unbind ();
Alert ("Go to the next level");
New Game (this.n+1, this.score+10, This.econatiner, This.escore, this.need);
}
Return
}
}
}
Game.prototype.events = function () {
This.keyup = This.keyup.bind (this);
Window.addeventlistener ("KeyUp", This.keyup);
}
Game.prototype.unbind = function () {
Clearinterval (This.timer);
Window.removeeventlistener ("KeyUp", This.keyup);
}
A random character object that contains the character's motion speed, the value of the character
Let Showarr the data movement of this array;
Game.prototype.run = function () {
Showarr = This.showarr;
Randomly generated character objects
if (Math.random () >0.9) {
var obj = Getrandom ();
Showarr.push (obj);
}
Let elements move
for (var i=0; i < showarr.length; i++) {
Showarr[i].y+=showarr[i].speed;
if (showarr[i].y>500) {
Alert ("Game failed");
Location.reload ();
}
}
This.eConatiner.innerHTML = "";
Allow elements to be added to the interface;
for (var i=0; i < showarr.length; i++) {
var Espan = document.createelement ("span");
ESpan.style.position = "absolute";
espan.innerhtml = Showarr[i].code;
ESpan.style.left = showarr[i].x;
ESpan.style.top = SHOWARR[I].Y;
This.eConatiner.appendChild (Espan);
}
}
document.getElementById ("Start"). AddEventListener ("click", Function () {
New Game (1, ten, Econatiner, Escore, document.getElementById ("need"));
});
</script>
Very interesting a typing game, welcome to visit