Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
dia009
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Joel Florentin
dia009
Commits
a8cc979d
Commit
a8cc979d
authored
Oct 29, 2021
by
Joel Florentin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tateti
parents
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
138 additions
and
0 deletions
+138
-0
tateti.html
+138
-0
No files found.
tateti.html
0 → 100644
View file @
a8cc979d
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<meta
charset=
"UTF-8"
>
<meta
http-equiv=
"X-UA-Compatible"
content=
"IE=edge"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
>
<title>
Ta te ti
</title>
<style>
table
{
width
:
300px
;
height
:
300px
;
margin-top
:
10%
;
margin-left
:
40%
;
table-layout
:
fixed
;
text-align
:
center
;
}
table
,
th
,
td
{
border
:
1px
solid
black
;
}
tr
.fila
{
margin
:
0
;
padding
:
0
;
width
:
30px
;
height
:
30px
;
}
.gano
{
background-color
:
aqua
;
}
</style>
</head>
<body>
Turno del jugador
<p
id=
"jugador"
>
X
</p>
<button
onclick=
"location.reload()"
>
Reset
</button>
<table
id=
"tablero"
>
</table>
<script>
let
tablero
=
document
.
querySelector
(
"#tablero"
);
let
jugador
=
document
.
querySelector
(
"#jugador"
);
let
primero
=
true
;
var
tableroValue
=
[[],[],[]];
var
contador
=
0
;
function
creacionTabla
(){
for
(
let
fila
=
0
;
fila
<
3
;
fila
++
)
{
let
tr
=
document
.
createElement
(
"tr"
)
tr
.
setAttribute
(
'data-fila'
,
fila
)
tr
.
classList
.
add
(
'fila'
)
for
(
let
columna
=
0
;
columna
<
3
;
columna
++
)
{
let
td
=
document
.
createElement
(
"td"
)
td
.
setAttribute
(
'data-columna'
,
columna
)
tr
.
append
(
td
)
}
tablero
.
append
(
tr
)
}
}
function
ganar
(){
if
(
contador
<
5
)
return
false
;
let
match
=
0
;
//control por columna
for
(
let
fila
=
0
;
fila
<
3
;
fila
++
)
{
let
anterior
=
tableroValue
[
fila
][
0
]
match
=
0
;
for
(
let
columna
=
1
;
columna
<
3
;
columna
++
)
{
let
actual
=
tableroValue
[
fila
][
columna
]
if
(
actual
==
anterior
&&
(
actual
==
"X"
||
actual
==
"O"
))
{
match
++
;
}
anterior
=
actual
}
if
(
match
==
2
)
{
tablero
.
children
[
fila
].
classList
.
add
(
'gano'
)
return
true
}
}
//control por fila
for
(
let
columna
=
0
;
columna
<
3
;
columna
++
)
{
let
anterior
=
tableroValue
[
0
][
columna
]
match
=
0
;
for
(
let
fila
=
1
;
fila
<
3
;
fila
++
)
{
let
actual
=
tableroValue
[
fila
][
columna
]
if
(
actual
==
anterior
&&
(
actual
==
"X"
||
actual
==
"O"
))
{
match
++
;
}
anterior
=
actual
}
if
(
match
==
2
)
{
document
.
querySelectorAll
(
`td[data-columna="
${
columna
}
"]`
).
forEach
(
td
=>
td
.
classList
.
add
(
"gano"
)
);
return
true
}
}
//diagonales
if
((
tableroValue
[
0
][
0
]
==
"O"
||
tableroValue
[
0
][
0
]
==
"X"
)
&&
tableroValue
[
0
][
0
]
==
tableroValue
[
1
][
1
]
&&
tableroValue
[
1
][
1
]
==
tableroValue
[
2
][
2
])
{
for
(
let
index
=
0
;
index
<
3
;
index
++
)
{
document
.
querySelector
(
`tr[data-fila="
${
index
}
"] > td[data-columna="
${
index
}
"]`
).
classList
.
add
(
"gano"
)
}
return
true
;
}
if
((
tableroValue
[
0
][
2
]
==
"O"
||
tableroValue
[
0
][
2
]
==
"X"
)
&&
tableroValue
[
0
][
2
]
==
tableroValue
[
1
][
1
]
&&
tableroValue
[
1
][
1
]
==
tableroValue
[
2
][
0
])
{
for
(
let
index
=
0
;
index
<
3
;
index
++
)
{
document
.
querySelector
(
`tr[data-fila="
${
index
}
"] > td[data-columna="
${
2
-
index
}
"]`
).
classList
.
add
(
"gano"
)
}
return
true
;
}
return
false
;
}
function
entrada
(
evt
){
if
(
evt
.
target
.
innerHTML
.
length
!=
0
)
return
;
const
fila
=
evt
.
target
.
parentElement
.
getAttribute
(
'data-fila'
);
const
col
=
evt
.
target
.
getAttribute
(
'data-columna'
);
let
valor
=
primero
?
"X"
:
"O"
;
evt
.
target
.
innerHTML
=
valor
;
primero
=
!
primero
;
if
(
tableroValue
[
fila
]
==
null
)
tableroValue
[
fila
]
=
[]
tableroValue
[
fila
][
col
]
=
valor
;
contador
++
;
if
(
ganar
())
console
.
log
(
"ganooo"
);
jugador
.
innerHTML
=
primero
?
"X"
:
"O"
;;
}
creacionTabla
()
document
.
querySelectorAll
(
'td'
).
forEach
(
td
=>
{
td
.
addEventListener
(
'click'
,
entrada
)
}
)
</script>
</body>
</html>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment