JavaScript中實(shí)現(xiàn)猜拳小游戲

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>頁(yè)面布局</title>

<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">

<style>

html{

font-size: 125%;

margin: 0rem;

}

.wap-main{

background: -webkit-linear-gradient(right,#7e2b9a,#ac3e34); /*safari 5.1 to 6.0*/

background: -o-linear-gradient(right,#7e2b9a,#ac3e34); /*opera 11.1 to 12.0*/

background: -moz-linear-gradient(right,#7e2b9a,#ac3e34);/*firefox 3.6 to 15*/

background: linear-gradient(to right,#7e2b9a,#ac3e34);/*#7e2b9a,#ac3e34*/

height: 32rem;

}

/*動(dòng)畫猜拳區(qū)域*/

.game-content{

position: fixed;

background: url(img/bg_ring@2x.png)no-repeat center/contain;

width: 13.36rem;

height: 16.64rem;

left: 50%;

margin-left: -6.68rem;

top: 2.56rem;

}

.list1{

position: absolute;

width: 7.2rem;

height: 4.2rem;

background: url(img/bg-round1.png)no-repeat center/contain;

? ? left: 50%;

? ? margin-left: -3.34rem;

top: 4.5rem;

}

.list2{

position: absolute;

width: 7.2rem;

height: 3.2rem;

background: url(img/countdown_ready@2x.png)no-repeat center/contain;

? ? left: 50%;

? ? margin-left: -3.34rem;

top: 8.5rem;

}

.list3{

position: absolute;

width: 6.2rem;

height: 2.0rem;

background: url(img/tip_choosegesture@2x.png)no-repeat center/contain;

? ? left: 50%;

? ? margin-left: -3rem;

top: 15rem;

}

/*石頭剪刀布選擇區(qū)域*/

.game-btn{

position: absolute;

background-color: #df574a;

width: 14.48rem;

height: 4.8rem;

left: 50%;

margin-left: -7.24rem;

top: 20rem;

border: 0.2rem #f8e71c solid;

/*圓角矩形*/

border-radius: 1em;

}

.btn{

width: 3.5rem;

height: 3.5rem;

float: left;

margin-left: 1rem;

margin-top: 0.6rem;

/*background: url();*/

}

.btn1{

background: url(img/btn_gesture_jiandao@2x.png)no-repeat center/contain;

}

.btn2{

background: url(img/btn_gesture_shitou@3x.png)no-repeat center/contain;

}

.btn3{

background: url(img/btn_gesture_bu@2x.png)no-repeat center/contain;

}

.game-chong{

position: absolute;

width: 6.2rem;

height: 10rem;

background: url(img/chongxinkaishi.png)no-repeat center/contain;

? ? left: 50%;

? ? margin-left: -3rem;

top: 15rem;

}

/*倒計(jì)時(shí)*/

.game-time{

position: absolute;

width: 6rem;

height: 8rem;

top: 3rem;

left: 50%;

margin-left: -3rem;

animation: imgmove1 1s linear;

animation-fill-mode: forwards;

-moz-animation: imgmove1 1s linear;

-moz-animation-fill-mode: forwards;

-webkit-animation: imgmove1 1s linear;

-webkit-animation-fill-mode: forwards;

}

@keyframes imgmove1{

from{

transform: scale(0);

opacity: 1;

}

to{

transform: scale(1.5);

opacity: 0;

}

}

/*結(jié)果樣式*/

.game-result{

? ? position: absolute;

? ? top:5rem;

? ? left: 50%;

? ? margin-left: -3.8rem;

? ? width: 7.6rem;

? ? height:6.08rem;

? ? animation: move 1.5s linear ;

? ? ? ? animation-fill-mode: forwards;

}

@keyframes move{

? ? 0%{

? ? ? ? /*transform: translateY(0rem);*/

? ? ? ? top:6rem;

? ? ? ? margin-left: -3rem;

? ? ? ? width: 3.8rem;

? ? height:3.04rem;

? ? }

? ? 100%{

? ? ? ? /*transform: translateY(-2rem);*/

? ? ? ? width: 7.6rem;

? ? height:6.08rem;

? ? }

}

/*出拳動(dòng)畫樣式*/

.game-enemy, .game-player{

? ? position: absolute;

? ? left: 50%;

? ? margin-left:-1.5rem;

? ? width: 3.2rem;

? ? height: 6.4rem;

}

.game-enemy{

? ? top:-6.4rem;

? ? animation: move1 1.5s linear ;

? ? animation-fill-mode: forwards;

? ? -webkit-animation: move1 1.5s linear ;

? ? -moz-animation: move1 1.5s linear ; ;

? ? -moz-animation-fill-mode:forwards ;

? ? -webkit-animation-fill-mode:forwards ;

}

@keyframes move1{

? ? 0%{

? ? ? ? /*transform: translateY(0rem);*/

? ? ? ? top:-6.4rem

? ? }

? ? 100%{

? ? ? ? /*transform: translateY(-2rem);*/

? ? ? ? top:-2rem

? ? }

}

.game-player{

? ? bottom: -6.4rem;

? ? animation: move2 1.5s linear ;

? ? animation-fill-mode: forwards;

? ? -webkit-animation: move2 1.5s linear ;

? ? -moz-animation: move2 1.5s linear ; ;

? ? -moz-animation-fill-mode:forwards ;

? ? -webkit-animation-fill-mode:forwards ;

}

@keyframes move2{

? ? 0%{

? ? ? ? /*transform: translateY(0rem);*/

? ? ? ? bottom:-6.4rem

? ? }

? ? 100%{

? ? ? ? /*transform: translateY(-2rem);*/

? ? ? ? bottom:-1rem

? ? }

}

</style>

<script>

function aa(n){

//電腦猜拳數(shù)1剪刀2拳頭3布

/*Math.random()? [0,1)*3---->[0,3)+1------->[1,4) --->1,3*/

? ? var cnum=cnum=parseInt(Math.random()*3+1,0);

var num=5;

var gametimeaa=function(){

if(num>0){

console.log(num)

document.getElementById("game-content").innerHTML="<img class='game-time' src='img/daojishi"+num+".png' >"

? ? num--;

}else{

clearInterval(gametimeinterobj)

}

}

gametimeinterobj=setInterval(gametimeaa,1000);

function check(){

//電腦隨機(jī)


? ? ? ? ? ? console.log("cnum:"+cnum);

? ? ? ? ? ? if(cnum==1){ //剪刀

? ? ? ? ? ? if(n==1){


? ? ? ? ? ? console.log("平");

? ? ? ? ? ? return 1;

? ? ? ? ? ? }else if(n==2){

? ? ? ? ? ? console.log("贏");

? ? ? ? ? ? return 2;

? ? ? ? ? ? }else{

? ? ? ? ? ? console.log("輸");

? ? ? ? ? ? return 3;

? ? ? ? ? ? }

? ? ? ? ? ? }else if(cnum==2){//石頭

? ? ? ? ? ? if(n==1){

? ? ? ? ? ? console.log("輸");

? ? ? ? ? ? return 3;

? ? ? ? ? ? }else if(n==2){

? ? ? ? ? ? console.log("平");

? ? ? ? ? ? return 1;

? ? ? ? ? ? }else{

? ? ? ? ? ? console.log("贏");

? ? ? ? ? ? return 2;

? ? ? ? ? ? }

? ? ? ? ? ? }else if(cnum==3){//步

? ? ? ? ? ? if(n==1){

? ? ? ? ? ? console.log("贏");

? ? ? ? ? ? return 2;

? ? ? ? ? ? }else if(n==2){

? ? ? ? ? ? console.log("輸");

? ? ? ? ? ? return 3;

? ? ? ? ? ? }else{

? ? ? ? ? ? console.log("平");

? ? ? ? ? ? return 1;

? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? ? ? }

setTimeout(bbb,5000);

? ? ? ? ? ? function bbb(){

? ? ? ? ? document.getElementById("game-content").innerHTML="<img class='game-player' src='img/player"+n+".png'><img class='game-enemy' src='img/enemy"+cnum+".png'><img class='game-result' src='img/result"+check()+".png'>";;

}

}

</script>

</head>

<body>

<div class="wap-main">

<div class="game-content" id="game-content">

--<div class="list1"></div>

<div class="list2"></div>

<div class="list3"></div>

<!--<img class="game-time" src="img/daojishi1.png" />-->

</div>

<div class="game-btn">

<div class="btn1 btn" onclick="aa(1)"></div>

<div class="btn2 btn" onclick="aa(2)"></div>

<div class="btn3 btn" onclick="aa(3)"></div>

</div>

<divclass="game-chong"></div>

</div>

</body>

</html>

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末陆淀,一起剝皮案震驚了整個(gè)濱河市又憨,隨后出現(xiàn)的幾起案子翩蘸,更是在濱河造成了極大的恐慌,老刑警劉巖礁哄,帶你破解...
    沈念sama閱讀 221,888評(píng)論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件饰躲,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡早直,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,677評(píng)論 3 399
  • 文/潘曉璐 我一進(jìn)店門憎夷,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人昧旨,你說(shuō)我怎么就攤上這事拾给。” “怎么了兔沃?”我有些...
    開封第一講書人閱讀 168,386評(píng)論 0 360
  • 文/不壞的土叔 我叫張陵蒋得,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我乒疏,道長(zhǎng)额衙,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 59,726評(píng)論 1 297
  • 正文 為了忘掉前任怕吴,我火速辦了婚禮窍侧,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘转绷。我一直安慰自己伟件,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,729評(píng)論 6 397
  • 文/花漫 我一把揭開白布议经。 她就那樣靜靜地躺著斧账,像睡著了一般谴返。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上咧织,一...
    開封第一講書人閱讀 52,337評(píng)論 1 310
  • 那天嗓袱,我揣著相機(jī)與錄音,去河邊找鬼习绢。 笑死渠抹,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的毯炮。 我是一名探鬼主播逼肯,決...
    沈念sama閱讀 40,902評(píng)論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼桃煎!你這毒婦竟也來(lái)了篮幢?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,807評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤为迈,失蹤者是張志新(化名)和其女友劉穎三椿,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體葫辐,經(jīng)...
    沈念sama閱讀 46,349評(píng)論 1 318
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡搜锰,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,439評(píng)論 3 340
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了耿战。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片蛋叼。...
    茶點(diǎn)故事閱讀 40,567評(píng)論 1 352
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖剂陡,靈堂內(nèi)的尸體忽然破棺而出狈涮,到底是詐尸還是另有隱情,我是刑警寧澤鸭栖,帶...
    沈念sama閱讀 36,242評(píng)論 5 350
  • 正文 年R本政府宣布歌馍,位于F島的核電站,受9級(jí)特大地震影響晕鹊,放射性物質(zhì)發(fā)生泄漏松却。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,933評(píng)論 3 334
  • 文/蒙蒙 一溅话、第九天 我趴在偏房一處隱蔽的房頂上張望晓锻。 院中可真熱鬧,春花似錦飞几、人聲如沸带射。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,420評(píng)論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)窟社。三九已至券勺,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間灿里,已是汗流浹背关炼。 一陣腳步聲響...
    開封第一講書人閱讀 33,531評(píng)論 1 272
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留匣吊,地道東北人儒拂。 一個(gè)月前我還...
    沈念sama閱讀 48,995評(píng)論 3 377
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像色鸳,于是被迫代替她去往敵國(guó)和親社痛。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,585評(píng)論 2 359

推薦閱讀更多精彩內(nèi)容

  • 選擇qi:是表達(dá)式 標(biāo)簽選擇器 類選擇器 屬性選擇器 繼承屬性: color命雀,font蒜哀,text-align,li...
    love2013閱讀 2,316評(píng)論 0 11
  • 一吏砂、html5新特性 1.增加了一個(gè)專門用于繪畫的元素canvas 2.增加了用于媒體播放的音頻和視頻元素 3.增...
    空谷悠閱讀 602評(píng)論 0 2
  • 上海游: 車票+機(jī)票=2266 迪士尼門票=1000 airbnb=500 阿里云服務(wù)器=200 午飯=50
    張大戈OMG閱讀 235評(píng)論 0 0
  • 我們很難找到其他的生靈像它們一樣撵儿,雖看似卑微,卻在世界歷史的進(jìn)程中起到了如此重要的作用狐血。達(dá)爾文曾經(jīng)給予蚯蚓這樣高的...
    如魜好儚閱讀 506評(píng)論 0 0
  • 那天去參加閨蜜的婚禮匈织,當(dāng)司儀問(wèn)她你愿意嫁給他不管貧窮富有生老病死時(shí)浪默,她終于忍不住開始大哭。臺(tái)下的親友們很感動(dòng)缀匕,他們...
    梟的蘇麻拉姑閱讀 269評(píng)論 0 1