Doudou mini-games written in javascript [Doudou] mini-games _ javascript tips-js tutorial

Source: Internet
Author: User
I used javascript to write a doubebean game. I won't go into details about how to play it. I will find it on the Internet. It's very easy. Interested friends can understand it, it took two days to write a doubebean game using javascript. As for how to play it, I will not elaborate on it. I will find it on the Internet and it is very easy.

The following is the source code, which is released for everyone to learn and exchange.
Because this program does not use an image, the interface beans in ie are square and eye-catching. We recommend that you use chrome or firefox
Demo address: http://www.imkoko.com/app/dadoudou.php
Not to mention, go to the code

The Code is as follows:











Start

Gameplay: click a blank area. You can score the upper, lower, left, and right places if they have the same color or number.



Time remaining: 120


Score: 0


Power by cool net




Script
/*
* Author: Jiang Qi
* Demo site: Cool Network http://www.imkoko.com/app/dadoudou.php
* The program is completely open for free. Please keep this information for reprinting. Thank you.
*/
Function $ (o ){
Return document. getElementById (o );
}
Var MoveObject = {
Down: function (o, fun)
{
Document. onselectstart = new Function ("event. returnValue = false ");
Document. body. setAttribute ('style', '-moz-user-select: none ;');
// E = e? E: window. event;
E = arguments. callee. caller. arguments [0] | window. event;
X = e. clientX;
Y = e. clientY;
Fun ([x, y]);
Return false;
}
};
Var o = new Array ();
Var it = 0;
Var fen = 0;
Function ini (){
Var _ doc = (document. compatMode! = "BackCompat ")? Document.doc umentElement: document. body;
Fly_left = _ doc. scrollLeft + _ doc. clientWidth/2-$ ('fly '). offsetWidth/2;
$ ('Fly '). style. left = fly_left + 'px ';
For (I = 0; I <15; I ++ ){
For (j = 0; j <12; j ++ ){
Tmp = document. createElement ('P ');
Tmp. className = "B ";
Tmp. style. left = (j * 50 + I % 2*25) + 'px ';
Tmp. style. top = I * 25 + 'px ';
$ ('Main'). appendChild (tmp );
}
}
For (I = 0; I <24; I ++ ){
O [I] = new Array ();
}
For (I = 0; I <200; I ++ ){
Var ji = cre ();
Tmp = document. createElement ('P ');
Tmp. innerHTML = t;
Tmp. id = ji [0] + '_' + ji [1];
Tmp. className = "c" + t;
Tmp. style. left = (x * 25) + 'px ';
Tmp. style. top = y * 25 + 'px ';
$ ('Main'). appendChild (tmp );
}
}
Function cre (){
X = parseInt (Math. random () * 24 );
Y = parseInt (Math. random () * 15 );
T = parseInt (Math. random () * 10 + 1 );
If (o [x] [y]> 0 ){
Var re = cre ();
Return re;
} Else {
O [x] [y] = t;
Return [x, y];
}
}
Function cc (p ){
X = parseInt (p [0]-$ ('fly '). offsetLeft)/25 );
Y = parseInt (p [1]-$ ('fly '). offsetTop)/25 );
If (o [x] [y]> 0 ){
Return false;
} Else {
Var finded = [];
For (I = y; I> = 0; I --){
If (o [x] [I]> 0 ){
Finded. push ([o [x] [I], x, I]);
Break;
}
}
For (I = y; I If (o [x] [I]> 0 ){
Finded. push ([o [x] [I], x, I]);
Break;
}
}
For (I = x; I> = 0; I --){
If (o [I] [y]> 0 ){
Finded. push ([o [I] [y], I, y]);
Break;
}
}
For (I = x; I If (o [I] [y]> 0 ){
Finded. push ([o [I] [y], I, y]);
Break;
}
}
Find = 0;
Po (finded, 0 );
If (find = 0 ){
It + = 10;
}
Fen = fen + find;
$ ('Cou'). innerHTML = 'score: '+ fen;
}
}
Function po (obj, n ){
A = obj [n];
Tag = 0;
For (j = n + 1; j If (obj [j] [0] = a [0]) {
O [obj [j] [1] [obj [j] [2] = 0;
Paowuxian. p ($ (obj [j] [1] + '_' + obj [j] [2]);
Obj. splice (j, 1 );
Tag = 1;
Find ++;
} Else {
J ++;
}
}
If (tag = 0 ){
N ++;
} Else {
O [a [1] [a [2] = 0;
Paowuxian. p ($ (a [1] + '_' + a [2]);
Find ++;
Obj. splice (n, 1 );
}
If (n Po (obj, n );
}
}
Function time (){
It ++;
If (it <121 ){
$ ('Time'). innerHTML = 'remaining time: '+ (121-it );
SetTimeout ('time () ', 1000 );
} Else {
$ ('Pin'). style. display = 'block ';
$ ('Menu '). style. display = 'block ';
$ ('Menu '). innerHTML =' Start


'+' Congratulations '+ fen +' points'
}
}
Function start (){
It = 0;
Fen = 0;
$ ('Main'). innerHTML = '';
O = new Array ();
Ini ();
$ ('Pin'). style. display = 'none ';
$ ('Menu '). style. display = 'none ';
Time ();
}
Ini ();
Var paowuxian = {
_ Type: [],
Bot: 0,
O: [],
Ini: function (o ){
For (I = 0; I If (this. o [I] = o ){
Return I;
}
}
For (I = 0; I If (this. _ type [I]. sta =-1 ){
Break;
}
}
O. style. position = 'absolute ';
This. o [I] = o;
This. _ type [I] = {l: o. offsetLeft, t: o. offsetTop, s: 0, nt: 0, sta: 1 };
Return I;
},
P: function (o ){
This. ini (o );
Var _ doc = (document. compatMode! = "BackCompat ")? Document.doc umentElement: document. body;
Var sctop = document.doc umentElement. scrollTop | document. body. scrollTop;
Fly_top = sctop + _ doc. clientHeight
This. bot = fly_top-30;
SetTimeout ("paowuxian. dos (" + I + ")", 20 );
},
Dos: function (I ){
If (this. _ type [I]. nt> this. bot ){
If (this. _ type [I]. sta = 1 ){
Document. body. removeChild (this. o [I]);
This. _ type. sta =-1;
}
} Else {
This. _ type [I]. l = this. _ type [I]. l + 3;
This. _ type [I]. s ++;
This. _ type [I]. nt = this. _ type [I]. t-5 * this. _ type [I]. s + 0.5*1 * this. _ type [I]. s * this. _ type [I]. s;
This. o [I]. style. top = this. _ type [I]. nt + 'px ';
This. o [I]. style. left = this. _ type [I]. l + 'px ';
SetTimeout ("paowuxian. dos (" + I + ")", 20 );
}
}
};
Script



I'm Jiang Qi.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.