Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
poker
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
Yovan Martinez
poker
Commits
47a21765
Commit
47a21765
authored
Apr 26, 2022
by
Yovan Martinez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finalizado poker con dos clases
parent
61731270
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
104 additions
and
200 deletions
+104
-200
Carta.java
+3
-127
Poker.java
+101
-73
No files found.
Carta.java
View file @
47a21765
...
...
@@ -5,140 +5,16 @@ import java.util.Arrays;
public
class
Carta
{
public
String
valor
;
public
String
palo
;
public
String
suit
=
""
;
public
String
values
=
""
;
public
Carta
(){
valor
=
""
;
palo
=
""
;
}
//Constructor que puso el profe con intenciones que desconozco
public
Carta
(
String
completo
)
{
this
.
valor
=
valor
+
ordenarCadena
(
String
.
valueOf
(
completo
.
charAt
(
0
)));
this
.
palo
=
palo
+
ordenarCadena
(
String
.
valueOf
(
completo
.
charAt
(
1
)));
}
//Guarda todos los valores de palo de las cartas en un solo string para guardarlos
public
void
armarPalos
(
String
carta
){
suit
=
ordenarCadena
(
suit
+
ordenarCadena
(
String
.
valueOf
(
carta
.
charAt
(
1
))));
}
//Guarda todos los valores de las cartas en un solo string para trabajarlos
public
void
armarValores
(
String
valores
){
values
=
ordenarCadena
(
values
+
String
.
valueOf
(
valores
.
charAt
(
0
)));
}
public
String
getSuit
(){
return
suit
;
}
public
String
getValue
(){
return
values
;
this
.
valor
=
String
.
valueOf
(
completo
.
charAt
(
0
));
this
.
palo
=
String
.
valueOf
(
completo
.
charAt
(
1
));
}
//Segunda cosa que puso el profe con intenciones desconocidas para la mente promedio
String
valorPalo
()
{
return
this
.
valor
+
this
.
palo
;
}
//*************CONTROLA QUE JUGADA SE DA EN LOS PALOS
public
int
controlPalos
(
String
palos
){
int
contador
=
0
;
for
(
int
i
=
0
;
i
<
palos
.
length
();
i
++)
{
for
(
int
j
=
0
;
j
<
palos
.
length
();
j
++)
{
if
(
palos
.
charAt
(
i
)
==
palos
.
charAt
(
j
))
{
contador
++;
}
}
}
return
contador
;
}
//***********CONTROLA QUE JUGADA SE DA EN LOS VALORES
public
String
controlValor
(
String
valores
){
int
contador
=
0
;
int
secuencial
=
0
;
boolean
thereIsLetter
=
false
;
for
(
int
i
=
0
;
i
<
valores
.
length
();
i
++)
{
for
(
int
j
=
0
;
j
<
valores
.
length
();
j
++)
{
if
(
valores
.
charAt
(
i
)
==
valores
.
charAt
(
j
))
{
contador
++;
}
}
}
if
(
contador
<
6
)
{
//controla que existan letras en los valores mandados
for
(
int
i
=
0
;
i
<
valores
.
length
();
i
++)
{
String
l
=
String
.
valueOf
(
valores
.
charAt
(
i
));
if
(
l
==
"T"
||
l
==
"J"
||
l
==
"Q"
||
l
==
"K"
||
l
==
"A"
)
{
thereIsLetter
=
true
;
break
;
}
}
//Una condicional para el caso que existan letras
if
(
thereIsLetter
==
false
){
//Para mejor entendimiento visual lo guardo en una variable de nombre mas corto
String
v
=
getValue
();
if
(
(
v
.
equals
(
"89JQT"
))
||
(
v
.
equals
(
"9JKQT"
))
||
((
v
).
equals
(
"AJKQT"
))
||(
v
.
equals
(
"2345A"
))
||
(
v
.
equals
(
"789JT"
))
||(
v
.
equals
(
"6789T"
))){
return
"ESCALERA"
;
}
}
else
{
for
(
int
i
=
1
;
i
<
valores
.
length
();
i
++)
{
if
(
valores
.
charAt
(
i
)
==
valores
.
charAt
(
i
-
1
)
+
1
)
{
secuencial
++;
}
}
if
(
secuencial
==
4
)
{
return
"ESCALERA"
;
}
}
}
else
if
(
contador
==
17
)
{
return
"POKER"
;
}
else
if
(
contador
==
13
){
return
"FULL"
;
}
else
if
(
contador
==
11
){
return
"TRIO"
;
}
else
if
(
contador
==
9
){
return
"PAR DOBLE"
;
}
else
if
(
contador
==
7
){
return
"PAR"
;
}
return
"NADA"
;
}
//Valora la mano y devuelve un resultado final (depende en su totalidad de otros metodos)
public
String
valoracionMano
(){
if
(
controlPalos
(
getSuit
())
==
25
&&
controlValor
(
getValue
()).
equals
(
"ESCALERA"
)){
return
"ESCALERA COLOR"
;
}
else
if
(
controlPalos
(
getSuit
())
<
25
&&
controlValor
(
getValue
()).
equals
(
"POKER"
)){
return
"POKER"
;
}
else
if
(
controlPalos
(
getSuit
())
<
25
&&
controlValor
(
getValue
()).
equals
(
"FULL"
))
{
return
"FULL"
;
}
else
if
(
controlPalos
(
getSuit
())
==
25
&&
controlValor
(
getValue
()).
equals
(
"NADA"
)
)
{
return
"COLOR"
;
}
else
if
(
controlPalos
(
getSuit
())
<
25
&&
controlValor
(
getValue
()).
equals
(
"ESCALERA"
)
)
{
return
"ESCALERA"
;
}
else
if
(
controlPalos
(
getSuit
())
<
25
&&
controlValor
(
getValue
()).
equals
(
"TRIO"
)
)
{
return
"TRIO"
;
}
else
if
(
controlPalos
(
getSuit
())
<
25
&&
controlValor
(
getValue
()).
equals
(
"PAR"
)
)
{
return
"PAR"
;
}
else
if
(
controlPalos
(
getSuit
())
<
25
&&
controlValor
(
getValue
()).
equals
(
"PAR DOBLE"
)
)
{
return
"PAR DOBLE"
;
}
return
"NADA"
;
}
//Recibe un string y lo ordena segun orden numerico o alfabetico
public
String
ordenarCadena
(
String
original
){
String
numeroAOrdenar
=
original
;
numeroAOrdenar
=
original
;
char
[]
chars
=
numeroAOrdenar
.
toCharArray
();
Arrays
.
sort
(
chars
);
String
cadenaOrdenada
=
new
String
(
chars
);
return
cadenaOrdenada
;
}
public
static
void
main
(
String
[]
args
)
{
Carta
cartas
=
new
Carta
();
String
[]
mano
=
new
String
[]{
"TH"
,
"JH"
,
"QH"
,
"KH"
,
"AH"
};
for
(
int
i
=
0
;
i
<
mano
.
length
;
i
++)
{
cartas
.
armarPalos
(
mano
[
i
]);
cartas
.
armarValores
(
mano
[
i
]);
}
System
.
out
.
println
(
cartas
.
valoracionMano
());
}
}
}
Poker.java
View file @
47a21765
import
javax.sound.sampled.Port
;
import
javax.lang.model.element.Element
;
import
javax.print.DocFlavor.STRING
;
import
java.util.Arrays
;
public
class
Poker
{
public
String
valoracionMano
(){
if
(
controlPalos
(
getSuit
())
==
25
&&
controlValor
(
getValue
()).
equals
(
"ESCALERA"
)){
return
"ESCALERA COLOR"
;
}
else
if
(
controlPalos
(
getSuit
())
<
25
&&
controlValor
(
getValue
()).
equals
(
"POKER"
)){
return
"POKER"
;
}
else
if
(
controlPalos
(
getSuit
())
<
25
&&
controlValor
(
getValue
()).
equals
(
"FULL"
))
{
return
"FULL"
;
}
else
if
(
controlPalos
(
getSuit
())
==
25
&&
controlValor
(
getValue
()).
equals
(
"NADA"
)
)
{
return
"COLOR"
;
}
else
if
(
controlPalos
(
getSuit
())
<
25
&&
controlValor
(
getValue
()).
equals
(
"ESCALERA"
)
)
{
return
"ESCALERA"
;
}
else
if
(
controlPalos
(
getSuit
())
<
25
&&
controlValor
(
getValue
()).
equals
(
"TRIO"
)
)
{
return
"TRIO"
;
}
else
if
(
controlPalos
(
getSuit
())
<
25
&&
controlValor
(
getValue
()).
equals
(
"PAR"
)
)
{
return
"PAR"
;
}
else
if
(
controlPalos
(
getSuit
())
<
25
&&
controlValor
(
getValue
()).
equals
(
"PAR DOBLE"
)
)
{
return
"PAR DOBLE"
;
}
return
"NADA"
;
public
String
suit
=
""
;
public
String
values
=
""
;
public
Poker
(){
values
=
""
;
suit
=
""
;
}
public
String
getSuit
(){
return
suit
;
}
public
String
getValue
(){
return
values
;
}
public
void
setValues
(
String
carta
){
values
=
ordenarCadena
(
values
+
carta
);
}
public
void
setSuits
(
String
carta
){
suit
=
ordenarCadena
(
suit
+
carta
);
}
//Recibe un string y lo ordena segun orden numerico o alfabetico
public
String
ordenarCadena
(
String
original
){
String
numeroAOrdenar
=
original
;
numeroAOrdenar
=
original
;
char
[]
chars
=
numeroAOrdenar
.
toCharArray
();
Arrays
.
sort
(
chars
);
String
cadenaOrdenada
=
new
String
(
chars
);
return
cadenaOrdenada
;
}
//***********CONTROLA LA JUGADA QUE SE DA EN LOS PALOS
public
String
controlPalos
(
String
palos
){
int
contador
=
0
;
for
(
int
i
=
0
;
i
<
palos
.
length
();
i
++)
{
...
...
@@ -34,68 +50,80 @@ public class Poker {
}
else
{
return
""
;
}
return
contador
;
}
//***********CONTROLA QUE JUGADA SE DA EN LOS VALORES
public
String
controlValor
(
String
valores
){
int
contador
=
0
;
int
secuencial
=
0
;
boolean
thereIsLetter
=
false
;
for
(
int
i
=
0
;
i
<
valores
.
length
();
i
++)
{
for
(
int
j
=
0
;
j
<
valores
.
length
();
j
++)
{
if
(
valores
.
charAt
(
i
)
==
valores
.
charAt
(
j
))
{
contador
++;
}
//***********CONTROLA QUE JUGADA SE DA EN LOS VALORES
public
String
controlValor
(
String
valores
){
int
contador
=
0
;
int
secuencial
=
0
;
boolean
thereIsLetter
=
false
;
for
(
int
i
=
0
;
i
<
valores
.
length
();
i
++)
{
for
(
int
j
=
0
;
j
<
valores
.
length
();
j
++)
{
if
(
valores
.
charAt
(
i
)
==
valores
.
charAt
(
j
))
{
contador
++;
}
}
if
(
contador
<
6
)
{
//controla que existan letras en los valores mandados
for
(
int
i
=
0
;
i
<
valores
.
length
();
i
++)
{
String
l
=
String
.
valueOf
(
valores
.
charAt
(
i
));
if
(
l
==
"T"
||
l
==
"J"
||
l
==
"Q"
||
l
==
"K"
||
l
==
"A"
)
{
thereIsLetter
=
true
;
break
;
}
}
if
(
contador
<
6
)
{
//controla que existan letras en los valores mandados
for
(
int
i
=
0
;
i
<
valores
.
length
();
i
++)
{
String
l
=
String
.
valueOf
(
valores
.
charAt
(
i
));
if
(
l
==
"T"
||
l
==
"J"
||
l
==
"Q"
||
l
==
"K"
||
l
==
"A"
)
{
thereIsLetter
=
true
;
break
;
}
//Una condicional para el caso que existan letras
if
(
thereIsLetter
==
false
){
//Para mejor entendimiento visual lo guardo en una variable de nombre mas corto
String
v
=
getValue
();
if
(
(
v
.
equals
(
"89JQT"
))
||
(
v
.
equals
(
"9JKQT"
))
||
((
v
).
equals
(
"AJKQT"
))
||(
v
.
equals
(
"2345A"
))
||
(
v
.
equals
(
"789JT"
))
||(
v
.
equals
(
"6789T"
))){
return
"ESCALERA"
;
}
}
else
{
for
(
int
i
=
1
;
i
<
valores
.
length
();
i
++)
{
if
(
valores
.
charAt
(
i
)
==
valores
.
charAt
(
i
-
1
)
+
1
)
{
secuencial
++;
}
}
if
(
secuencial
==
4
)
{
return
"ESCALERA"
;
}
}
}
else
if
(
contador
==
17
)
{
return
"POKER"
;
}
else
if
(
contador
==
13
){
return
"FULL"
;
}
else
if
(
contador
==
11
){
return
"TRIO"
;
}
else
if
(
contador
==
9
){
return
"PAR DOBLE"
;
}
else
if
(
contador
==
7
){
return
"PAR"
;
}
return
"NADA"
;
//Una condicional para el caso que existan letras
if
(
thereIsLetter
==
true
){
//Para mejor entendimiento visual lo guardo en una variable de nombre mas corto
String
v
=
getValue
();
if
(
(
v
.
equals
(
"89JQT"
))
||
(
v
.
equals
(
"9JKQT"
))
||
((
v
).
equals
(
"AJKQT"
))
||(
v
.
equals
(
"2345A"
))
||
(
v
.
equals
(
"789JT"
))
||(
v
.
equals
(
"6789T"
))){
return
"ESCALERA"
;
}
}
else
{
for
(
int
i
=
1
;
i
<
valores
.
length
();
i
++)
{
if
(
Character
.
getNumericValue
(
valores
.
charAt
(
i
))
==
Character
.
getNumericValue
(
valores
.
charAt
(
i
-
1
))
+
1
)
{
secuencial
++;
}
}
if
(
secuencial
==
4
)
{
return
"ESCALERA"
;
}
}
}
else
if
(
contador
==
17
)
{
return
"POKER"
;
}
else
if
(
contador
==
13
){
return
"FULL"
;
}
else
if
(
contador
==
11
){
return
"TRIO"
;
}
else
if
(
contador
==
9
){
return
"PAR DOBLE"
;
}
else
if
(
contador
==
7
){
return
"PAR"
;
}
return
""
;
}
public
static
void
main
(
String
[]
args
)
{
Carta
cartas
=
new
Carta
();
String
[]
mano
=
new
String
[]{
"TH"
,
"JH"
,
"QH"
,
"KH"
,
"AH"
};
for
(
int
i
=
0
;
i
<
mano
.
length
;
i
++)
{
cartas
.
armarPalos
(
mano
[
i
]);
cartas
.
armarValores
(
mano
[
i
]);
}
System
.
out
.
println
(
cartas
.
valoracionMano
());
Carta
carta1
=
new
Carta
(
"2D"
);
Carta
carta2
=
new
Carta
(
"3S"
);
Carta
carta3
=
new
Carta
(
"4C"
);
Carta
carta4
=
new
Carta
(
"5H"
);
Carta
carta5
=
new
Carta
(
"6H"
);
Poker
partida
=
new
Poker
();
//Le paso los palos con el metodo del profe
partida
.
setSuits
(
carta1
.
palo
);
partida
.
setSuits
(
carta2
.
palo
);
partida
.
setSuits
(
carta3
.
palo
);
partida
.
setSuits
(
carta4
.
palo
);
partida
.
setSuits
(
carta5
.
palo
);
//Le paso los valores con el metodo del profe
partida
.
setValues
(
carta1
.
valor
);
partida
.
setValues
(
carta2
.
valor
);
partida
.
setValues
(
carta3
.
valor
);
partida
.
setValues
(
carta4
.
valor
);
partida
.
setValues
(
carta5
.
valor
);
System
.
out
.
println
(
partida
.
controlValor
(
partida
.
getValue
())
+
" "
+
partida
.
controlPalos
(
partida
.
getSuit
()));
}
}
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