Skip to content

Instantly share code, notes, and snippets.

@mrhammadasif
Created April 16, 2024 13:35
Show Gist options
  • Save mrhammadasif/a6156cf50025261612f9a03b449f4c2f to your computer and use it in GitHub Desktop.
Save mrhammadasif/a6156cf50025261612f9a03b449f4c2f to your computer and use it in GitHub Desktop.
Create Word Stok Game for Printing
<template>
<div id="app">
<div class="p-4 g-4 d-flex align-items-center">
<label class="p-0 m-0" for="">Rows</label>
<input v-model.number="rows" :min="2" :max="20" type="range" class="form-control ml-2 mr-4 m-0">
<label class="p-0 m-0" for="">Columns</label>
<input v-model.number="cols" min="2" step="1" max="20" type="range" class="form-control ml-2 m-0">
<button class="btn btn-primary ml-4" @click="regenKey">Regenerate!</button>
</div>
<table class="table-bordered" :key="key">
<tr v-for="row in rows" :key="key + row">
<cell v-for="col in cols" :value="key" :key="key + row + col" />
</tr>
</table>
</div>
</template>
<script>
import Cell from './Cell.vue'
import {randomGuid} from "./utils"
export default {
name: 'App',
data () {
return {
key: '1231232c',
rows: 4,
cols: 4
}
},
methods: {
regenKey () {
this.key = randomGuid()
}
},
components: {
Cell
}
}
</script>
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
display: flex;
flex-direction: column;
justify-items: center;
align-items: center;
text-align: center;
color: #2c3e50;
margin-top: 60px;
row-gap: 40px;
}
.table-bordered {
border-spacing: 0;
border-collapse: collapse;
}
</style>
<template>
<td class="me">{{something.toUpperCase()}}</td>
</template>
<script>
import {getRandomChar} from "./utils"
export default {
props: ['value'],
computed: {
something () {
return getRandomChar()
}
}
}
</script>
<style scoped>
.me {
width: 50px;
height: 50px;
font-weight: bold;
font-size: 26px;
border: 1px solid black;
}
</style>
export function getRandomChar() {
const pool = `${'aeiost'.repeat(3)}bcdfghjklmnpruuwyz`
return pool[Math.floor(Math.random() * pool.length)]
}
export function randomGuid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
const r = (Math.random() * 16) | 0
const v = c === 'x' ? r : (r & 0x3) | 0x8
return v.toString(16)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment