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
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
156 deletions
+60
-156
Carta.java
+2
-126
Poker.java
+58
-30
No files found.
Carta.java
View file @
47a21765
...
@@ -5,140 +5,16 @@ import java.util.Arrays;
...
@@ -5,140 +5,16 @@ import java.util.Arrays;
public
class
Carta
{
public
class
Carta
{
public
String
valor
;
public
String
valor
;
public
String
palo
;
public
String
palo
;
public
String
suit
=
""
;
public
String
values
=
""
;
public
Carta
(){
valor
=
""
;
palo
=
""
;
}
//Constructor que puso el profe con intenciones que desconozco
//Constructor que puso el profe con intenciones que desconozco
public
Carta
(
String
completo
)
public
Carta
(
String
completo
)
{
{
this
.
valor
=
valor
+
ordenarCadena
(
String
.
valueOf
(
completo
.
charAt
(
0
)));
this
.
valor
=
String
.
valueOf
(
completo
.
charAt
(
0
));
this
.
palo
=
palo
+
ordenarCadena
(
String
.
valueOf
(
completo
.
charAt
(
1
)));
this
.
palo
=
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
;
}
}
//Segunda cosa que puso el profe con intenciones desconocidas para la mente promedio
//Segunda cosa que puso el profe con intenciones desconocidas para la mente promedio
String
valorPalo
()
String
valorPalo
()
{
{
return
this
.
valor
+
this
.
palo
;
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
class
Poker
{
public
String
valoracionMano
(){
public
String
suit
=
""
;
if
(
controlPalos
(
getSuit
())
==
25
&&
controlValor
(
getValue
()).
equals
(
"ESCALERA"
)){
public
String
values
=
""
;
return
"ESCALERA COLOR"
;
}
else
if
(
controlPalos
(
getSuit
())
<
25
&&
controlValor
(
getValue
()).
equals
(
"POKER"
)){
public
Poker
(){
return
"POKER"
;
values
=
""
;
}
else
if
(
controlPalos
(
getSuit
())
<
25
&&
controlValor
(
getValue
()).
equals
(
"FULL"
))
{
suit
=
""
;
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
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
){
public
String
controlPalos
(
String
palos
){
int
contador
=
0
;
int
contador
=
0
;
for
(
int
i
=
0
;
i
<
palos
.
length
();
i
++)
{
for
(
int
i
=
0
;
i
<
palos
.
length
();
i
++)
{
...
@@ -34,7 +50,6 @@ public class Poker {
...
@@ -34,7 +50,6 @@ public class Poker {
}
else
{
}
else
{
return
""
;
return
""
;
}
}
return
contador
;
}
}
//***********CONTROLA QUE JUGADA SE DA EN LOS VALORES
//***********CONTROLA QUE JUGADA SE DA EN LOS VALORES
public
String
controlValor
(
String
valores
){
public
String
controlValor
(
String
valores
){
...
@@ -58,7 +73,7 @@ public class Poker {
...
@@ -58,7 +73,7 @@ public class Poker {
}
}
}
}
//Una condicional para el caso que existan letras
//Una condicional para el caso que existan letras
if
(
thereIsLetter
==
fals
e
){
if
(
thereIsLetter
==
tru
e
){
//Para mejor entendimiento visual lo guardo en una variable de nombre mas corto
//Para mejor entendimiento visual lo guardo en una variable de nombre mas corto
String
v
=
getValue
();
String
v
=
getValue
();
if
(
(
v
.
equals
(
"89JQT"
))
||
(
v
.
equals
(
"9JKQT"
))
||
((
v
).
equals
(
"AJKQT"
))
||(
v
.
equals
(
"2345A"
))
||
(
v
.
equals
(
"789JT"
))
||(
v
.
equals
(
"6789T"
))){
if
(
(
v
.
equals
(
"89JQT"
))
||
(
v
.
equals
(
"9JKQT"
))
||
((
v
).
equals
(
"AJKQT"
))
||(
v
.
equals
(
"2345A"
))
||
(
v
.
equals
(
"789JT"
))
||(
v
.
equals
(
"6789T"
))){
...
@@ -66,7 +81,7 @@ public class Poker {
...
@@ -66,7 +81,7 @@ public class Poker {
}
}
}
else
{
}
else
{
for
(
int
i
=
1
;
i
<
valores
.
length
();
i
++)
{
for
(
int
i
=
1
;
i
<
valores
.
length
();
i
++)
{
if
(
valores
.
charAt
(
i
)
==
valores
.
charAt
(
i
-
1
)
+
1
)
{
if
(
Character
.
getNumericValue
(
valores
.
charAt
(
i
))
==
Character
.
getNumericValue
(
valores
.
charAt
(
i
-
1
)
)
+
1
)
{
secuencial
++;
secuencial
++;
}
}
}
}
...
@@ -85,17 +100,30 @@ public class Poker {
...
@@ -85,17 +100,30 @@ public class Poker {
}
else
if
(
contador
==
7
){
}
else
if
(
contador
==
7
){
return
"PAR"
;
return
"PAR"
;
}
}
return
"NADA
"
;
return
"
"
;
}
}
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
Carta
cartas
=
new
Carta
();
Carta
carta1
=
new
Carta
(
"2D"
);
String
[]
mano
=
new
String
[]{
"TH"
,
"JH"
,
"QH"
,
"KH"
,
"AH"
};
Carta
carta2
=
new
Carta
(
"3S"
);
for
(
int
i
=
0
;
i
<
mano
.
length
;
i
++)
{
Carta
carta3
=
new
Carta
(
"4C"
);
cartas
.
armarPalos
(
mano
[
i
]);
Carta
carta4
=
new
Carta
(
"5H"
);
cartas
.
armarValores
(
mano
[
i
]);
Carta
carta5
=
new
Carta
(
"6H"
);
}
Poker
partida
=
new
Poker
();
System
.
out
.
println
(
cartas
.
valoracionMano
());
//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