Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wu-e001
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
Jose Figueredo
wu-e001
Commits
651dfc68
Commit
651dfc68
authored
Sep 01, 2020
by
Jose Figueredo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(Mi primera tarea)
parents
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
251 additions
and
0 deletions
+251
-0
Readme.md
+4
-0
Tateti.java
+247
-0
No files found.
Readme.md
0 → 100644
View file @
651dfc68
Instrucciones:
compilar con javac Tateti.java
ejecutar con java Tateti
\ No newline at end of file
Tateti.java
0 → 100644
View file @
651dfc68
import
java.util.*
;
public
class
Tateti
{
public
char
tabla
[][]=
new
char
[
3
][
3
];
public
static
int
jugador
=
0
;
public
Tateti
(){
for
(
int
i
=
0
;
i
<
3
;
i
++)
{
for
(
int
j
=
0
;
j
<
3
;
j
++)
{
tabla
[
i
][
j
]=
' '
;
}
}
}
public
boolean
JugadaValida
(
String
jugada
)
{
int
bandera
=
0
;
// 0 si es valida, 1 si es fila invalida, 2 si es columna invalida y 3 si es fila y columna
// 5 para ocupado insta
if
(
jugada
.
length
()>
2
||
jugada
.
length
()<
2
)
{
System
.
out
.
println
(
"Jugada Invalida, debe ser una letr mayuscula y un numero"
);
return
false
;
}
int
f
=
Convertir
((
jugada
.
charAt
(
0
)));
int
c
=
(
jugada
.
charAt
(
1
)-
'0'
)-
1
;
if
(
f
<
0
||
f
>
2
)
{
bandera
++;
// bandera vale 1
}
if
(
c
<
0
||
c
>
2
)
{
bandera
+=
2
;
// bandera vale 3 o 2
}
if
(
bandera
==
0
)
// si son validas insta
{
if
(
tabla
[
f
][
c
]==
' '
){
// si esta vacio
if
(
jugador
%
2
==
0
)
tabla
[
f
][
c
]=
'X'
;
else
tabla
[
f
][
c
]=
'O'
;
jugador
++;
return
true
;
}
else
{
bandera
=
5
;
// esta ocupado insta !
}
}
ImprimirError
(
bandera
);
return
false
;
}
public
static
void
ImprimirError
(
int
n
)
{
switch
(
n
){
case
0
:
break
;
case
1
:
System
.
out
.
println
(
"Jugada Invalida - Fila Invalida"
);
break
;
case
2
:
System
.
out
.
println
(
"Jugada Invalida - Columna Invalida"
);
break
;
case
3
:
System
.
out
.
println
(
"Jugada Invalida -Columna y Fila Invalida"
);
break
;
case
5
:
System
.
out
.
println
(
"Jugada Invalida - Casilla Ocupada"
);
}
}
public
boolean
HayGanador
()
{
for
(
int
i
=
0
;
i
<
3
;
i
++)
{
if
(
tabla
[
i
][
0
]==
tabla
[
i
][
1
]
&&
tabla
[
i
][
0
]==
tabla
[
i
][
2
]
&&
(
tabla
[
i
][
0
]==
'X'
||
tabla
[
i
][
0
]==
'O'
))
{
System
.
out
.
println
(
"GANADOR : "
+
tabla
[
i
][
0
]);
return
true
;
}
}
for
(
int
i
=
0
;
i
<
3
;
i
++)
{
if
(
tabla
[
0
][
i
]==
tabla
[
1
][
i
]
&&
tabla
[
0
][
i
]==
tabla
[
2
][
i
]
&&
(
tabla
[
0
][
i
]==
'X'
||
tabla
[
0
][
i
]==
'O'
))
{
System
.
out
.
println
(
"GANADOR : "
+
tabla
[
0
][
i
]);
return
true
;
}
}
if
(
tabla
[
0
][
0
]==
tabla
[
1
][
1
]
&&
tabla
[
0
][
0
]==
tabla
[
2
][
2
]
&&
(
tabla
[
0
][
0
]==
'X'
||
tabla
[
0
][
0
]==
'O'
))
{
System
.
out
.
println
(
"GANADOR : "
+
tabla
[
0
][
0
]);
return
true
;
}
if
(
tabla
[
0
][
2
]==
tabla
[
1
][
1
]
&&
tabla
[
1
][
1
]==
tabla
[
2
][
0
]
&&
(
tabla
[
1
][
1
]==
'X'
||
tabla
[
1
][
1
]==
'O'
))
{
System
.
out
.
println
(
"GANADOR : "
+
tabla
[
0
][
2
]);
return
true
;
}
return
false
;
}
public
void
MostrarTablero
()
{
for
(
int
i
=
0
;
i
<
3
;
i
++)
{
System
.
out
.
println
();
for
(
int
j
=
0
;
j
<
3
;
j
++)
{
System
.
out
.
print
(
"| "
+
tabla
[
i
][
j
]+
" |"
);
}
System
.
out
.
print
(
"\n---------------"
);
}
System
.
out
.
print
(
"\n"
);
}
public
static
int
Convertir
(
char
letra
){
if
(
letra
==
'A'
)
{
return
0
;
}
if
(
letra
==
'B'
)
{
return
1
;
}
if
(
letra
==
'C'
)
{
return
2
;
}
return
-
1
;
}
public
static
void
main
(
String
[]
args
)
{
String
abc
=
"abcdefghijklmnopqrstuvwyz"
;
Scanner
entrada
=
new
Scanner
(
System
.
in
);
Tateti
juego
=
new
Tateti
();
String
j
;
int
conta
=
1
;
while
(!
juego
.
HayGanador
()
&&
juego
.
jugador
<
9
)
{
do
{
System
.
out
.
println
(
abc
.
charAt
(
conta
)+
"-> Ingrese una jugada"
);
j
=
entrada
.
nextLine
();
conta
++;
//entrada.nextLine();//Limpiamos buffer de entrada
if
(
conta
>
abc
.
length
()-
2
)
{
conta
=
0
;
}
}
while
(!
juego
.
JugadaValida
(
j
));
if
(!
juego
.
HayGanador
())
{
System
.
out
.
println
(
"EMPATE"
);
}
juego
.
MostrarTablero
();
}
System
.
out
.
println
(
"FIN DEL JUEGO"
);
//juego.MostrarTablero();
}
}
\ 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