Vue学习Demo-1

这个博客展示了一个简单的HTML/CSS/JavaScript交互式网页游戏。玩家可以点击按钮进行拳击攻击,减少角色的生命值,生命值归零则游戏结束。游戏包含重启功能,允许玩家重新开始游戏。页面设计简洁,使用Vue.js实现动态效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

效果图

点击Punch蓝条减小 点Restart回满
在这里插入图片描述

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.12/dist/vue.min.js"></script>
    <style>
        #bag {
            width: 200px;
            height: 500px;
            margin: 0 auto;
            background: url(./static/bag.jpg) center no-repeat;
            background-size: 80%;
        }
        #bag-healthy {
            width: 200px;
            border: 2px #000 solid;
            margin: 0 auto 20px auto;           
        }
        #bag-healthy div {
            height: 20px;
            background-color: cornflowerblue;
        }
        #controls {
            width: 120px;
            margin: 0 auto;
        }
    </style>
</head>
<body>
    <div id="app"> 
          <!-- bag image -->
          <div id="bag" :class="{burst: ended}"></div>
          <!-- bag health -->
          <div id="bag-healthy">
              <div :style="{width: health + '%'}"></div>
          </div>
          <!-- game control -->
          <div id="controls">
              <button @click="punch" v-show="!ended">Punch</button>
              <button @click="restart">Restart</button>
          </div>
    </div>
    <script>
        var app = new Vue({
            el: '#app',
            data:{
                health: 100,
                ended: false
            },
            methods: {
                punch() {
                    this.health --
                    if (this.health <=0) {
                        this.ended = true
                    }
                },
                restart() {
                    this.health = 100
                }
            },
        })
    </script>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值