GithubHelp home page GithubHelp logo

sokoban-vue3's Introduction

sokoban-vue3

设置地图大小

有两个 input,一个用来设置地图的宽度,一个用来设置地图的高度。

当设置完宽度和高度后,可以看到对应的地图编辑块

首先在 MapEdit.vue 加两个 input:

<template>
  <div>
    <div class="input-row">
      <span class="input-row-label">row:</span>
      <input type="number" />
    </div>
    <div class="input-col">
      <span class="input-col-label">col:</span>
      <input type="number" />
    </div>
  </div>
</template>

<script setup lang="ts"></script>

<style scoped>
.input-row,
.input-col {
  display: flex;
  margin-bottom: 8px;
}
.input-row-label,
.input-col-label {
  width: 35px;
  text-align: right;
  margin-right: 5px;
}
</style>

样式如下:

然后再添加地图编辑块

<div class="block-row" v-for="row in 5">
  <div class="block-col" v-for="col in 5">
    <div class="block">1</div>
  </div>
</div>
.block-row {
  display: flex;
}
.block {
  width: 32px;
  height: 32px;
  border: 1px solid #ccc;
  margin: 2px;
}

样式如下:

这里我们是先画出静态页面,等调试好以后再换成动态数据

最后在 MapEdit.vue 里给 input 和编辑块绑定数据

<template>
  <div>
    <div class="input-row">
      <span class="input-row-label">row:</span>
      <input type="number" v-model="row" />
    </div>
    <div class="input-col">
      <span class="input-col-label">col:</span>
      <input type="number" v-model="col" />
    </div>
    <div class="block-row" v-for="i in row">
      <div class="block-col" v-for="j in col">
        <div class="block">1</div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'

const row = ref(5)
const col = ref(5)
</script>

这样,当更新地图的宽和高时,地图编辑块也会随之更新。

sokoban-vue3's People

Contributors

henrytsz avatar

Watchers

 avatar

Forkers

adityabantt

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.