Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
Warming_Up_Tarea_001
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
Cristhian Ortellado
Warming_Up_Tarea_001
Commits
b291c432
Commit
b291c432
authored
Sep 04, 2020
by
Cristhian Ortellado
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Se mejoro el codigo
parent
a0db584a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
19 deletions
+34
-19
Tateti.class
+0
-0
Tateti.java
+32
-19
url.txt
+2
-0
No files found.
Tateti.class
0 → 100644
View file @
b291c432
File added
Tateti.java
View file @
b291c432
...
...
@@ -4,7 +4,7 @@ public class Tateti {
private
String
matriz
[][]
=
new
String
[
3
][
3
];
//tabla principal
private
char
turno
[]
=
{
'X'
,
'O'
};
//el turno 0 == primer jugador(X) 1 == Segundo Jugador (O)
private
char
numeroJugada
[]={
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
,
'g'
,
'h'
,
'i'
};
//indica la jugada actual
private
String
jugadaGanadora
[][]
=
{{
""
,
""
,
""
},{
""
,
""
,
""
}}
;
private
String
jugadaGanadora
=
""
;
//colores que agregaremos a la salida de consola
private
static
final
String
ANSI_RED
=
"\u001B[31m"
;
//error
private
static
final
String
ANSI_RESET
=
"\u001B[0m"
;
//color entrada
...
...
@@ -36,16 +36,13 @@ public class Tateti {
int
columna
=
(
int
)
casillaActual
(
movimiento
.
charAt
(
1
));
matriz
[
fila
][
columna
]
=
turno
[
nroJugada
%
2
]+
""
;
//guardamos la jugada
jugadaGanadora
[
nroJugada
%
2
][
nroJugada
/
2
]=
movimiento
;
imprimirMatriz
();
if
(
ganador
())
{
System
.
out
.
printf
(
"%s%s%s%s"
,
ANSI_GREEN
,
" GANADOR "
,
turno
[
nroJugada
%
2
],
" :"
);
if
(
jugadaGanadora
[
1
][
2
].
length
()==
0
)
System
.
out
.
printf
(
"%s"
,
jugadaGanadora
[
0
][
0
]+
"-"
+
jugadaGanadora
[
0
][
1
]+
"-"
+
jugadaGanadora
[
0
][
2
]+
"\n"
);
else
System
.
out
.
printf
(
"%s"
,
jugadaGanadora
[
1
][
0
]+
"-"
+
jugadaGanadora
[
1
][
1
]+
"-"
+
jugadaGanadora
[
1
][
2
]+
"\n"
);
System
.
out
.
printf
(
"%s%s%s%s"
,
ANSI_GREEN
,
" GANADOR "
,
turno
[
nroJugada
%
2
],
" :"
);
System
.
out
.
printf
(
"%s"
,
jugadaGanadora
+
"\n"
);
System
.
out
.
println
(
ANSI_GREEN
+
" JUEGO FINALIZADO"
);
return
;
}
...
...
@@ -65,34 +62,50 @@ public class Tateti {
private
boolean
ganador
(){
//comprueba si alguien gano
//diagonales
if
(
matriz
[
0
][
0
].
equals
(
matriz
[
1
][
1
])
&&
matriz
[
0
][
0
].
equals
(
matriz
[
2
][
2
])
&&
matriz
[
0
][
0
].
length
()>
0
)
if
(
matriz
[
0
][
0
].
equals
(
matriz
[
1
][
1
])
&&
matriz
[
0
][
0
].
equals
(
matriz
[
2
][
2
])
&&
matriz
[
0
][
0
].
length
()>
0
){
jugadaGanadora
=
"A1-B2-C3"
;
return
true
;
if
(
matriz
[
0
][
2
].
equals
(
matriz
[
1
][
1
])
&&
matriz
[
0
][
2
].
equals
(
matriz
[
2
][
0
])
&&
matriz
[
0
][
2
].
length
()>
0
)
}
if
(
matriz
[
0
][
2
].
equals
(
matriz
[
1
][
1
])
&&
matriz
[
0
][
2
].
equals
(
matriz
[
2
][
0
])
&&
matriz
[
0
][
2
].
length
()>
0
)
{
jugadaGanadora
=
"A3-B2-C1"
;
return
true
;
}
//columnas
if
(
matriz
[
0
][
0
].
equals
(
matriz
[
1
][
0
])
&&
matriz
[
0
][
0
].
equals
(
matriz
[
2
][
0
])
&&
matriz
[
0
][
0
].
length
()>
0
)
if
(
matriz
[
0
][
0
].
equals
(
matriz
[
1
][
0
])
&&
matriz
[
0
][
0
].
equals
(
matriz
[
2
][
0
])
&&
matriz
[
0
][
0
].
length
()>
0
)
{
jugadaGanadora
=
"A1-B1-C1"
;
return
true
;
}
if
(
matriz
[
0
][
1
].
equals
(
matriz
[
1
][
1
])
&&
matriz
[
0
][
1
].
equals
(
matriz
[
2
][
1
])
&&
matriz
[
0
][
1
].
length
()>
0
)
return
true
;
if
(
matriz
[
0
][
1
].
equals
(
matriz
[
1
][
1
])
&&
matriz
[
0
][
1
].
equals
(
matriz
[
2
][
1
])
&&
matriz
[
0
][
1
].
length
()>
0
){
jugadaGanadora
=
"A2-B2-C2"
;
return
true
;
}
if
(
matriz
[
0
][
2
].
equals
(
matriz
[
1
][
2
])
&&
matriz
[
0
][
2
].
equals
(
matriz
[
2
][
2
])
&&
matriz
[
0
][
2
].
length
()>
0
)
return
true
;
if
(
matriz
[
0
][
2
].
equals
(
matriz
[
1
][
2
])
&&
matriz
[
0
][
2
].
equals
(
matriz
[
2
][
2
])
&&
matriz
[
0
][
2
].
length
()>
0
){
jugadaGanadora
=
"A3-B3-C3"
;
return
true
;
}
//filas
if
(
matriz
[
0
][
0
].
equals
(
matriz
[
0
][
1
])
&&
matriz
[
0
][
0
].
equals
(
matriz
[
0
][
2
])
&&
matriz
[
0
][
0
].
length
()>
0
)
return
true
;
if
(
matriz
[
0
][
0
].
equals
(
matriz
[
0
][
1
])
&&
matriz
[
0
][
0
].
equals
(
matriz
[
0
][
2
])
&&
matriz
[
0
][
0
].
length
()>
0
){
jugadaGanadora
=
"A1-A2-A3"
;
return
true
;
}
if
(
matriz
[
1
][
0
].
equals
(
matriz
[
1
][
1
])
&&
matriz
[
1
][
0
].
equals
(
matriz
[
1
][
2
])
&&
matriz
[
1
][
0
].
length
()>
0
)
if
(
matriz
[
1
][
0
].
equals
(
matriz
[
1
][
1
])
&&
matriz
[
1
][
0
].
equals
(
matriz
[
1
][
2
])
&&
matriz
[
1
][
0
].
length
()>
0
){
jugadaGanadora
=
"B1-B2-C3"
;
return
true
;
}
if
(
matriz
[
2
][
0
].
equals
(
matriz
[
2
][
1
])
&&
matriz
[
2
][
0
].
equals
(
matriz
[
2
][
2
])
&&
matriz
[
2
][
0
].
length
()>
0
)
if
(
matriz
[
2
][
0
].
equals
(
matriz
[
2
][
1
])
&&
matriz
[
2
][
0
].
equals
(
matriz
[
2
][
2
])
&&
matriz
[
2
][
0
].
length
()>
0
){
jugadaGanadora
=
"C1-C2-C3"
;
return
true
;
}
return
false
;
}
private
void
imprimirMatriz
(){
...
...
url.txt
0 → 100644
View file @
b291c432
https://phoebe.roshka.com/gitlab/cortellado/Warming_Up_Tarea_001
\ 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