Reversi forrás

<template>
    <div id="app">
    <div id=content>
        <table>
            <tr :key=i v-for="(sor,i) in tabla">
            <td :key=j v-for="(elem,j) in sor" 
                :class=elem
                @click=katt(i,j)> {{elem}}
            </td>
            </tr>
        </table>
    </div>
    <span>
            <table>
                <td>{{ fsz.X }}</td>
                <td class="X">X</td>
                <td> <-> </td>
                <td class="O">O</td>
                <td>{{ fsz.O }}</td>
            </table>
    </span>
    <span v-if="nyert!='-'">
        <h2>Nyert: {{ nyert }}</h2><br>
    </span>
    <br>
    <div class=ujj @click=ujj()>Új játék</div>
    <hr>
    <a href="/~tnemeth/examples/webexamples/Reversi_forras.html">
        Forráskód
    </a>
    </div>
</template>

<script>
let next = "X", xp, yp, maxh, size=10, szin, szt, masik, ba = n =>
    Array(n) .fill(0) .map( () => Array(n).fill(" ") )
export default {
    name: 'amoba',
    data: () => ({ nyert: "-", tabla: ba(size), fsz: { X: 0, O: 0 } }),
    methods: {
        ujj() { this.tabla = ba(size), this.nyert = "-", this.fsz.X=0, this.fsz.O=0 },
        katt(x, y) {
            masik = next
            if (this.tabla[x][y] === " " && this.nyert === "-") {
                this.$set(
                    this.tabla[x],
                    y,
                    next === "X" ? next = "O" : next = "X"
                ),
                [
                    [1,1],[1,0],[0,1],[-1,1],
                    [-1,-1],[-1,0],[0,-1],[1,-1]
                ].forEach( v => {
                    xp=x, yp=y, szt=[]
                    do {
                        xp+=v[0]
                        yp+=v[1]
                        if (this.tabla[xp] && this.tabla[xp][yp]===masik) szt.push({xp,yp})
                    } while ( 
                        xp>=0 && yp>=0 && xp<size && yp<size && 
                        this.tabla[xp][yp]!==next && this.tabla[xp][yp]!==' '
                    )
                    if ( this.tabla[xp] && szt.length && this.tabla[xp][yp]===next ) {
                        szt.forEach( v=> {
                            this.$set( this.tabla[v.xp], v.yp, next)
                            this.fsz[next]++
                            this.fsz[masik]--
                        })
                    }
                })
                this.fsz[next=="X"?"X":"O"]++
            }
            if (this.fsz.O+this.fsz.X===size**2) 
                this.nyert = this.fsz.O===this.fsz.X ? 'Döntetlen' :
                             this.fsz.O > this.fsz.X ? 'O' : 'X'
        }
    }
}
</script>

<style scoped>
@import url('https://fonts.googleapis.com/css?family=Roboto+Slab&display=swap');
#app {
    font-family: 'Roboto Slab', serif;
    user-select: none;
    text-align: center;
    color: #095d6c;
}
h2 {
    text-shadow: 0px 0px 2px #19334d;
}
div#content {
    text-align: center;
}
table {
    border-collapse: inherit;
    display: table;
    margin:0px auto;
    border-spacing: 4px;
}
td {
    text-align: center;
    width: 23px;
    height: 23px;
    background-color: #e6f3ef;
    border-radius: 4px;
    box-shadow: 1px 1px 3px rgb(99, 97, 97);
    cursor: pointer;
    border: solid 1px rgb(29, 43, 75);
    color:rgb(52, 43, 43);
    padding:3px;
    text-shadow: 0 0 2px 
}
td.O {
    color:snow;
    background-color: #437264;
}
td.X {
    color:snow;
    background-color: #af5489;
}
div.ujj {
    margin:0px auto;
    width: 90px;
    cursor:pointer;
    border-radius: 4px;
    box-shadow: 1px 1px 3px rgb(99, 97, 97);
}
div.ujj:hover {
    background-color: #cfded9;
    box-shadow: 1px 1px 3px rgb(34, 33, 33);
}
</style>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133

Összes példa

Utoljára frissítve: 7/2/2019, 5:43:11 PM