Tom猫小游戏功能实现

摘要:
本文通过css和html的简单操作实现了汤姆猫游戏的功能,并通过简单的js代码实现了动画效果,使图片不断切换。汤姆猫游戏的HTML部分:

  本文章通过简单的css和html的操作,来实现Tom猫小游戏的功能,通过简单的js代码,让图片不断切换来实现动画效果。

Tom猫小游戏的HTML部分:

  

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>TomCat</title>
</head>
<body>
    <section>
        <img id="imgShow" src="http://t.zoukankan.com/tom/img/Animations/angry/angry_00.jpg" alt="">
    </section>
    <div class="cymbal">
        <img src="http://t.zoukankan.com/tom/img/Buttons/cymbal/cymbal.png" alt="">
    </div>
    <div class="drink">
        <img src="http://t.zoukankan.com/tom/img/Buttons/drink/drink.png" alt="">
    </div>
    <div class="eat">
        <img src="http://t.zoukankan.com/tom/img/Buttons/eat/eat.png" alt="">
    </div>
    <div class="fart">
        <img src="http://t.zoukankan.com/tom/img/Buttons/fart/fart.png" alt="">
    </div>
    <div class="pie">
        <img src="http://t.zoukankan.com/tom/img/Buttons/pie/pie.png" alt="">
    </div>
    <div class="scratch">
        <img src="http://t.zoukankan.com/tom/img/Buttons/scratch/scratch.png" alt="">
    </div>
    <div class="angry"></div>
    <div class="angry1"></div>
    <div class="footLeft"></div>
    <div class="footRight"></div>
    <div class="knockout"></div>
    <div class='stomach'></div>
    <div></div>

    <audio src="http://t.zoukankan.com/original-alps-p-13234893.html" id="music"></audio>
</body>
</html>
 
Tom猫的css部分:
    <style>
    *{
        margin:0;
        padding:0;
    }
    img{
        display:block;
    }
    body,html{
        height:100%;
    }
    section{
        100%;
        height:100%;
    }
    #imgShow{
        100%;
        height:100%;
    }
    .cymbal{
        60px;
        height:60px;
        position:absolute;
        left:1%;
        bottom:30%;
    }
    .drink{
        60px;
        height:60px;
        position:absolute;
        left:1%;
        bottom:20%;
    }
    .eat{
        60px;
        height:60px;
        position:absolute;
        left:1%;
        bottom:10%;
    }
    .fart{
        60px;
        height:60px;
        position:absolute;
        right:1%;
        bottom:30%;
    }
    .pie{
        60px;
        height:60px;
        position:absolute;
        right:1%;
        bottom:20%;
    }
    .scratch{
        60px;
        height:60px;
        position:absolute;
        right:1%;
        bottom:10%;
    }
    .angry{
        108px;
        height:92px;
       /*  background:chartreuse; */
        position: absolute;
        left:35%;
        bottom:31%;
    }
    .angry1{
        38px;
        height:63px;
       /*  background:chartreuse; */
        position: absolute;
        right:22%;
        bottom:11%;
    }
    .footLeft{
        42px;
        height:35px;
       /*  background:red; */
        position:absolute;
        left:36%;
        bottom:4%;
    }
    .footRight{
        42px;
        height:35px;
        /* background:blue; */
        position:absolute;
        right:36%;
        bottom:4%;
    }
    .knockout{
        110px;
        height:46px;
       /*  background:blue; */
        position:absolute;
        right:36%;
        bottom:76%;
    }
    .stomach{
        110px;
        height:88px;
        /* background:yellow; */
        position:absolute;
        right:36%;
        bottom:15%;
    }
    </style>
 
Tom猫js部分:
    <script>
    function Tom(){
        this.imgShow = document.getElementById('imgShow');
        this.btn = document.querySelectorAll('div');
        this.music = document.getElementById('music');
        this.init();
    }
    Tom.prototype = {
        init : function(){
            this.eventBind();
        },
        tomPlay : function(name,num){
            var _this = this;
            this.count = 0 ;
            clearInterval(this.timer);
            this.timer = setInterval(function(){
                if(_this.count >= num){
                    clearInterval(_this.timer);
                    _this.count = 0 ;
                }else{
                    _this.count++;
                    _this.imgShow.src = './tom/img/Animations/'+name+'/'+name+'_' + _this.mendZero(_this.count)+'.jpg';

                }
            },80)
        },

        mendZero : function(num){
             if(num < 10){
                 return '0' + num;
             }else{
                 return num;
             }
        },

        eventBind : function(){
            var _this = this;
            for(let i = 0 , k = this.btn.length ; i < k ; i++){
                this.btn[i].onclick = function(){
                    let classN = this.className;
                    switch(classN){
                        case 'cymbal' :
                            _this.tomPlay('cymbal',12);
                            _this.music.src = './tom/mp3/pia.mp3';
                            _this.music.play();
                            break;
                        case 'drink' :
                            _this.tomPlay('drink',80);
                            break;
                        case 'eat' :
                            _this.tomPlay('eat',39);
                            break;
                        case 'fart' :
                            _this.tomPlay('fart',27);
                            break;
                        case 'pie' :
                            _this.tomPlay('pie',23);
                            break;
                        case 'scratch' :
                            _this.tomPlay('scratch',55);
                            break;
                        case 'angry' :
                            _this.tomPlay('angry',25);
                            break;
                        case 'angry1' :
                            _this.tomPlay('angry',25);
                            break;
                        case 'footLeft' :
                            _this.tomPlay('footRight',29);
                            _this.music.src = './tom/mp3/tomaiyou.mp3';
                            _this.music.play();
                            break;
                        case 'footRight' :
                            _this.tomPlay('footLeft',29);
                            _this.music.src = './tom/mp3/tomaiyou.mp3';
                            _this.music.play();
                            break;
                        case 'knockout' :
                            _this.tomPlay('knockout',80);
                            break;
                        case 'stomach' :
                            _this.tomPlay('stomach',33);
                            _this.music.src = './tom/mp3/tomaiyou.mp3';
                            _this.music.play();
                            break;
                    }
                }
            }
        }
    }
    new Tom();
    </script>
内容如有雷同,纯属巧合,侵权请联系本人。

免责声明:文章转载自《Tom猫小游戏功能实现》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇初学安卓开发随笔之 Menu、toast 用法、活动的四种启动模式 以及 一个方便的Base活动类使用方法Fedora 17 无线网卡配置笔记下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

python_14(js)

第1章 图片方法 1.1 设置背景图:1.2 背景图问题:1.3 background-repeat; noa-repe 1.4 background-attachment: fixed1.5 background-position 1.6 background-position-x 1.7 截取局部1.7.1 透明色第2章 定位 2.1 定义形式2.2...

SQL indexOf、lastIndexOf

DECLARE @Name NVARCHAR (50)SET @Name = 'abcd.12345.efght' DECLARE @Position INT --sql first indexofSET @Position = CHARINDEX('.', @Name);SELECT SUBSTRING (@Name, 0,@Position)--abcd...

工作笔记

更改过程让数据不时时更新 let add = JSON.stringify(editMarketChannel);this.editMarketChannel = JSON.parse(add); 这个为函数传入的对象,Obj 提示信息 成功的 this.msgs = [];this.msgs.push({severity:'success', summa...

CSS伪元素before和after

今天发现很多国外的网站和框架设计都用到了before和after,之前使用的比较少,今天试了下觉得还是很有意思的~ 说明 1. :before 和 :after将在内容元素的前后插入额外的元素;:before将会在内容之前“添加”一个元素而:after将会在内容后“添加”一个元素。在它们之中添加内容我们可以使用content属性。 2. :before 和...

使用Unity实现VR中在黑板上写字(升级篇)(一)-----解决画笔穿透画板的问题

一、概述: 在使用Unity实现VR中在黑板上写字(初级篇)中的最后留下了一些有待完善的地方,首先完善画笔穿透画板的问题; 在之前使用画笔会出现这种情况: 可以看到画笔是穿透了画板,这样在VR中会给用户很差的体验,而且因为代码的原因会造成画的过程中中断,所以这个问题必须解决; 解决后的使用情况: 可以看到现在不会穿透了,而且画起来不会有中断,其实我的手...

js 实现向下滑动页面时遇顶固定

达到的页面效果: html: <link href="http://t.zoukankan.com/Scripts/weui/reset.css" rel="stylesheet" /> <link href="http://t.zoukankan.com/Scripts/weui/calendar.css" rel="stylesh...