首页 > 其他分享 >057 Project Setup & First Methods

057 Project Setup & First Methods

时间:2024-08-26 20:24:51浏览次数:6  
标签:box monsterHealth color border Setup Project playerHealth 057 margin

示例

index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Vue Basics</title>
    <link
      href="https://fonts.googleapis.com/css2?family=Jost:wght@400;700&display=swap"
      rel="stylesheet"
    />
    <link rel="stylesheet" href="styles.css" />
    <script src="https://unpkg.com/vue@3/dist/vue.global.js" defer></script>
    <script src="app.js" defer></script>
  </head>
  <body>
    <header>
      <h1>Monster Slayer</h1>
    </header>
    <div id="game">
      <section id="monster" class="container">
        <h2>Monster Health</h2>
        <div class="healthbar">
          <div class="healthbar__value"></div>
        </div>
      </section>
      <section id="player" class="container">
        <h2>Your Health</h2>
        <div class="healthbar">
          <div class="healthbar__value"></div>
        </div>
      </section>
      <section id="controls">
        <button>ATTACK</button>
        <button>SPECIAL ATTACK</button>
        <button>HEAL</button>
        <button>SURRENDER</button>
      </section>
      <section id="log" class="container">
        <h2>Battle Log</h2>
        <ul></ul>
      </section>
    </div>
  </body>
</html>

app.js

function getRandomValue(min, max) {
    return Math.floor(Math.random() * (max - min)) + min;
}

const math = Math;

const app = Vue.createApp({
    data() {
        return {
            playerHealth: 100,
            monsterHealth: 100,
        };
    },
    methods: {
        attackMonster() {
            const attackValue = getRandomValue(5, 12);
            if (this.monsterHealth > 0) {
                this.monsterHealth -= attackValue;
                this.attackPlayer();
                if (this.monsterHealth < 0) {
                    this.monsterHealth = 0;
                }
            }
        },
        attackPlayer() {
            const attackValue = getRandomValue(8, 15);
            if (this.playerHealth > 0) {
                this.playerHealth -= attackValue;
                if (this.playerHealth < 0) {
                    this.playerHealth = 0;
                }
            }
        },
        specialAttack() {
            this.monsterHealth -= 20;
        },
        heal() {
            if (this.playerHealth < 100) {
                this.playerHealth += 10;
            }
        },

    },
});

app.mount('#game');

styles.css

* {
  box-sizing: border-box;
}

html {
  font-family: 'Jost', sans-serif;
}

body {
  margin: 0;
}

header {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.26);
  padding: 0.5rem;
  background-color: #880017;
  color: white;
  text-align: center;
  margin-bottom: 2rem;
}

section {
  width: 90%;
  max-width: 40rem;
  margin: auto;
}

.healthbar {
  width: 100%;
  height: 40px;
  border: 1px solid #575757;
  margin: 1rem 0;
  background: #fde5e5;
}

.healthbar__value {
  background-color: #00a876;
  width: 100%;
  height: 100%;
}

.container {
  text-align: center;
  padding: 0.5rem;
  margin: 1rem auto;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.26);
  border-radius: 12px;
}

#monster h2,
#player h2 {
  margin: 0.25rem;
}

#controls {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
}

button {
  font: inherit;
  border: 1px solid #88005b;
  background-color: #88005b;
  color: white;
  padding: 1rem 2rem;
  border-radius: 12px;
  margin: 1rem;
  width: 12rem;
  cursor: pointer;
  box-shadow: 1px 1px 4px rgba(0, 0, 0, 0.26);
}

button:focus {
  outline: none;
}

button:hover,
button:active {
  background-color: #af0a78;
  border-color: #af0a78;
  box-shadow: 1px 1px 8px rgba(0, 0, 0, 0.26);
}

button:disabled {
  background-color: #ccc;
  border-color: #ccc;
  box-shadow: none;
  color: #3f3f3f;
  cursor: not-allowed;
}

#log ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

#log li {
  margin: 0.5rem 0;
}

.log--player {
  color: #7700ff;
}

.log--monster {
  color: #da8d00;
}

.log--damage {
  color: red;
}

.log--heal {
  color: green;
}

标签:box,monsterHealth,color,border,Setup,Project,playerHealth,057,margin
From: https://blog.csdn.net/KevinHuang2088/article/details/141571823

相关文章

  • [vue3] vue3 setup函数
    从语法上看,CompositionAPI提供了一个setup启动函数作为逻辑组织的入口,提供了响应式API,提供了生命周期函数以及依赖注入的接口,通过调用函数来声明一个组件。OptionsAPI选项式API在props、data、methods、computed等选项中定义变量;在组件初始化阶段,Vue.js内部处理这......
  • 057、Vue3+TypeScript基础,页面通讯之父页面使用$refs修改子页面暴露的成员
    01、main.js代码如下://引入createApp用于创建Vue实例import{createApp}from'vue'//引入App.vue根组件importAppfrom'./App.vue'//引入emitter用于全局事件总线//importemitterfrom'@/utils/emitter'constapp=createApp(App);//App.vue的根元素id为......
  • lazarus标题栏增加显示当前project的目标CPU及OS
    lazarus编写程序特别是需要交叉编译时,不清楚当前project交叉编译的目标CPU及OS,为方便使用,可以按以下方法(红字部分)修改:打开lazarus\ide\main.pp,找到procedureTMainIDE.UpdateCaption;procedureTMainIDE.UpdateCaption;functionAddToCaption(constCurrentCaption,CaptAdd......
  • vue3 语法糖<script setup>
    在Vue3中,<scriptsetup>是一种新的语法糖,它极大地简化了组件的编写方式。<scriptsetup>是在单文件组件(SFC)中使用组合式API的编译时语法糖。当同时使用SFC与组合式API时该语法是默认推荐。基本概念简洁的语法:<scriptsetup>允许在<script>标签中直接使用组......
  • 详细讲述 Vue3 的 <script setup>
    <scriptsetup>是Vue3引入的一种新的 <script> 标记的用法,其本质是一个语法糖。它极大简化了单文件组件(SFC)的开发体验,目的是让代码更简洁、易读,同时减少模板和逻辑之间的重复。1.基本用法<!--使用<scriptsetup>--><template><div><p>message:{{message......
  • setupres.dll丢失解决方案速递:全面修复流程,从简易排查至高级修复策略
    遇到setupres.dll文件丢失问题,可以按照以下步骤尝试修复:1.系统文件扫描:首先,利用系统自带的文件检查工具来修复潜在的系统文件问题。打开命令提示符(以管理员身份运行),输入sfc/scannow并回车,等待扫描并修复完成。2.Windows更新:确保操作系统是最新版本,因为有时这类问题可通......
  • Vue3父子通信-setup+经典父组件与子组件el-dialog
    一、父组件绑定方法,引入子组件并传递数据和方法<el-buttonsize="small"plaintype="primary"@click="click_add_notice">+添加公告</el-button><AddNoticeDialogv-model="AddNoticeDialogDialogVisible"@addNoticeSucc......
  • vue3中script标签的setup实现原理
    概述当vue3新建组件时,我们有两种选择选项式和组合式,如下所示传统方式<script>import{ref}from"vue";exportdefault{setup(){constcount=ref(0);consthandleClick=()=>{count.value++;};return{count,handleClick......
  • Project: Kill e
    接到上级任务,今天来暗杀\(e\)据说杀死\(e\)的方式就是把他算出来,好吧,现在我们还是来算一下考虑使用如下代数式求解\[e\\text{site:baidu.com}\]虽然我不知道这个代数式的意思是什么,但是我想他应该是某种高级的运算,特别是这个:看起来就像有什么神秘的力量考虑到我完全......
  • Spark MLlib 特征工程系列—特征提取LSH(BucketedRandomProjectionLSH)
    SparkMLlib特征工程系列—特征提取LSH(BucketedRandomProjectionLSH)在这篇文章中,我们将深入探讨Spark中的BucketedRandomProjectionLSH,这是一种用于近似最近邻搜索的技术。文章将覆盖其工作原理、应用场景、Scala代码示例、参数调优以及使用效果分析,确保内容全面、......