Skip to content

Commit 1e149f7

Browse files
committed
adicionando arquivos do projeto ao repositorio
1 parent 2ebe15d commit 1e149f7

File tree

8 files changed

+275
-75
lines changed

8 files changed

+275
-75
lines changed

src/App.vue

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,37 @@
11
<template>
22
<div id="app">
3-
<img alt="Vue logo" src="./assets/logo.png">
4-
<HelloWorld msg="Welcome to Your Vue.js App"/>
3+
<a href="https://github.com/jprando/vuejv">projeto no github</a>
4+
<jv></jv>
5+
<span> v0.082.72045 </span>
56
</div>
67
</template>
78

89
<script>
9-
import HelloWorld from './components/HelloWorld.vue'
10-
10+
import jv from '@/views/jv'
1111
export default {
12-
name: 'App',
13-
components: {
14-
HelloWorld
15-
}
12+
name: 'app',
13+
components: { jv }
1614
}
1715
</script>
1816

1917
<style>
18+
a {
19+
text-decoration: none;
20+
color: gray;
21+
position: relative;
22+
top: -25px;
23+
}
2024
#app {
21-
font-family: Avenir, Helvetica, Arial, sans-serif;
22-
-webkit-font-smoothing: antialiased;
23-
-moz-osx-font-smoothing: grayscale;
24-
text-align: center;
25-
color: #2c3e50;
26-
margin-top: 60px;
25+
font-family: Courier New, Courier, monospace;
26+
float: left;
27+
margin: 20px;
28+
padding: 50px;
29+
height: 480px;
30+
width: 370px;
31+
max-width: 370px;
32+
max-height: 480px;
33+
min-width: 370px;
34+
min-height: 540px;
35+
background-color: #eef;
2736
}
28-
</style>
37+
</style>

src/components/HelloWorld.vue

Lines changed: 0 additions & 58 deletions
This file was deleted.

src/components/jvBoard.vue

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<template>
2+
<div class="board">
3+
<div class="row">
4+
<jv-cell v-model="value.A1" @jogar="jogarPartida"></jv-cell>
5+
<jv-cell v-model="value.B1" @jogar="jogarPartida"></jv-cell>
6+
<jv-cell v-model="value.C1" @jogar="jogarPartida"></jv-cell>
7+
</div>
8+
<div class="row">
9+
<jv-cell v-model="value.A2" @jogar="jogarPartida"></jv-cell>
10+
<jv-cell v-model="value.B2" @jogar="jogarPartida"></jv-cell>
11+
<jv-cell v-model="value.C2" @jogar="jogarPartida"></jv-cell>
12+
</div>
13+
<div class="row">
14+
<jv-cell v-model="value.A3" @jogar="jogarPartida"></jv-cell>
15+
<jv-cell v-model="value.B3" @jogar="jogarPartida"></jv-cell>
16+
<jv-cell v-model="value.C3" @jogar="jogarPartida"></jv-cell>
17+
</div>
18+
</div>
19+
</template>
20+
21+
<script>
22+
import jvCell from './jvCell'
23+
export default {
24+
name: 'jvBoard',
25+
components: { jvCell },
26+
props: ['value'],
27+
methods: {
28+
jogarPartida(pos) {
29+
this.$emit('jogar', pos)
30+
}
31+
}
32+
}
33+
</script>
34+
35+
<style>
36+
.row {
37+
clear: left;
38+
}
39+
</style>

src/components/jvCell.vue

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<template>
2+
<button class="cell"
3+
:class="{ganhou:value.ganhou}"
4+
:disabled="value.exibir"
5+
@click="jogar" > {{ value.exibir }}
6+
</button>
7+
</template>
8+
9+
<script>
10+
export default {
11+
name: 'jvCell',
12+
props: ['value'],
13+
methods: {
14+
jogar() {
15+
this.$emit('jogar', this.value)
16+
}
17+
}
18+
}
19+
</script>
20+
21+
<style>
22+
.cell {
23+
cursor: pointer;
24+
float: left;
25+
border: solid 1px black;
26+
width: 100px;
27+
height: 100px;
28+
text-align: center;
29+
line-height: 100px;
30+
font-size: 60px;
31+
}
32+
.cell:hover {
33+
background-color: #fee;
34+
}
35+
.ganhou {
36+
background-color: #aaffaa;
37+
}
38+
.ganhou:hover {
39+
background-color: #aaffaa;
40+
}
41+
</style>

src/main.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import Vue from 'vue'
2-
import App from './App.vue'
2+
import App from './App'
33

44
Vue.config.productionTip = false
55

66
new Vue({
7-
render: h => h(App),
7+
name: 'WebApp',
8+
render: h => h(App)
89
}).$mount('#app')
10+
11+
// teste git commit -S

src/services/ganhador.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const vitorias = [448, 56, 7, 292, 146, 73, 273, 84]
2+
const convertLetra = letra => value => (value == letra ? 1 : 0)
3+
const toBinario = (arr, verificaLetra) => arr.map(verificaLetra).join``
4+
const haGanhador = valor => element => (element & valor) == element
5+
6+
import posicaoGanhador from './posicaoGanhador'
7+
8+
const verificaSe = letra => {
9+
const nessa = partida => parseInt(toBinario(partida, convertLetra(letra)), 2)
10+
return {
11+
ganhou: partida => ({
12+
ganhou: vitorias.some(haGanhador(nessa(partida))) && letra,
13+
posicaoVitoria: vitorias.filter(haGanhador(nessa(partida))).map(i => posicaoGanhador[i])
14+
})
15+
16+
}
17+
}
18+
19+
const ganhador = partida => {
20+
const xResult = verificaSe`X`.ganhou(partida)
21+
if(xResult.ganhou) {
22+
return xResult
23+
} else {
24+
const oResult = verificaSe`O`.ganhou(partida)
25+
if(oResult) {
26+
return oResult
27+
}
28+
}
29+
}
30+
31+
export default ganhador

src/services/posicaoGanhador.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default {
2+
448: ['A1', 'A2', 'A3'],
3+
56: ['B1', 'B2', 'B3'],
4+
7:['C1', 'C2', 'C3'],
5+
292:['A1','B1','C1'],
6+
146:['A2','B2','C2'],
7+
73:['A3', 'B3', 'C3'],
8+
273:['A1','B2','C3'],
9+
84:['A3','B2','C1']
10+
}

src/views/jv.vue

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
<template>
2+
<div>
3+
<jv-board v-model="posicoes" @jogar="jogarPartida"></jv-board>
4+
<div class="options">
5+
<button class="reset" @click="reiniciar">reiniciar</button>
6+
<div style="margin-bottom: 10px">
7+
<h1>
8+
JOGADOR
9+
{{ vezDe }}
10+
<h1 v-show="alguemGanhou">GANHOU</h1>
11+
</h1>
12+
</div>
13+
</div>
14+
</div>
15+
</template>
16+
17+
<script>
18+
import jvBoard from '@/components/jvBoard'
19+
import ganhador from '@/services/ganhador'
20+
export default {
21+
name: 'jv',
22+
components: { jvBoard },
23+
data () {
24+
return {
25+
vezDe: 'X',
26+
alguemGanhou: false,
27+
posicoes: {
28+
A1: {
29+
exibir: null,
30+
ganhou: false
31+
},
32+
A2: {
33+
exibir: null,
34+
ganhou: false
35+
},
36+
A3: {
37+
exibir: null,
38+
ganhou: false
39+
},
40+
B1: {
41+
exibir: null,
42+
ganhou: false
43+
},
44+
B2: {
45+
exibir: null,
46+
ganhou: false
47+
},
48+
B3: {
49+
exibir: null,
50+
ganhou: false
51+
},
52+
C1: {
53+
exibir: null,
54+
ganhou: false
55+
},
56+
C2: {
57+
exibir: null,
58+
ganhou: false
59+
},
60+
C3: {
61+
exibir: null,
62+
ganhou: false
63+
}
64+
}
65+
}
66+
},
67+
computed: {
68+
jogada () {
69+
const getExibir = i => i.exibir
70+
const getValues = value => Object.values(value).map(getExibir)
71+
return getValues(this.posicoes)
72+
},
73+
},
74+
methods: {
75+
jogarPartida (pos) {
76+
let vezDeJogar = this.vezDe
77+
let ninguemGanhou = !this.alguemGanhou
78+
if (ninguemGanhou) {
79+
let self = this
80+
pos.exibir = vezDeJogar
81+
const result = ganhador(self.jogada)
82+
self.alguemGanhou = result.ganhou == vezDeJogar
83+
if(self.alguemGanhou) {
84+
if(result.ganhou){
85+
result.posicaoVitoria.forEach(a => {
86+
a.forEach(i => self.posicoes[i].ganhou = true)
87+
})
88+
}
89+
}
90+
ninguemGanhou = !self.alguemGanhou
91+
if (ninguemGanhou) {
92+
self.vezDe = vezDeJogar === 'X' ? 'O' : 'X'
93+
}
94+
}
95+
},
96+
reiniciar () {
97+
const self = this
98+
for (const item in self.posicoes) {
99+
let posicao = self.posicoes[item]
100+
posicao.exibir = null
101+
posicao.ganhou = false
102+
}
103+
self.alguemGanhou = false
104+
}
105+
}
106+
}
107+
</script>
108+
109+
<style>
110+
h1 {
111+
margin-bottom: 0px;
112+
margin-top: 0px;
113+
}
114+
.reset {
115+
margin-bottom: 20px;
116+
padding: 20px;
117+
font-size: 15px;
118+
font-family: monospace;
119+
}
120+
.options {
121+
clear: left;
122+
padding-top: 30px;
123+
padding-bottom: 30px;
124+
}
125+
</style>

0 commit comments

Comments
 (0)