Commit 22b36884 by Javier Ferreira

Initial commit

parent 8ac6e5e0
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package juegopoker;
import java.util.ArrayList;
/**
*
* @author user
*/
class Cartas {
private static final String[] palos = {"S", "C", "H", "D"};//para los valores de los palos
private static final String[] valores = {"A","2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", };//para los valores de la cartas
private String p;
private String v;
private String n;
private int numericValue;
public Cartas(String palo, String valor, int numericValue) {
this.p = palo;
this.v = valor;
this.numericValue = numericValue;
this.n = valor+palo;
}
public String getPalo() {
return p;
}
public String getValor() {
return v;
}
public static ArrayList<Cartas> crearMazo(){
ArrayList<Cartas> mazo = new ArrayList<>();
for(int i=0;i<palos.length;i++){
for(int j=0;j<valores.length;j++){
mazo.add(new Cartas(palos[i], valores[j], j+2));
}
}
return mazo;
}
public int getNumericValue() {
return numericValue;
}
}
Si se mezclan dos cartas al azar |Cuál es la probabilidad de obtener un trio?
<html lang="en">
<head>
<title>JavaScript Challenges</title>
<style>
#emailpara{
display: none;
}
</style>
</head>
<body>
<form action="">
<fieldset>
<legend>Email subscriptions</legend>
<p id="Ross">
<label>
<input type="checkbox"
name="subscribe" id="subscribe">
Yes! I would like to receive all of your free candy!
</label>
</p>
<p id="emailpara">
<label>
Email Address:
<input type="text" name="email" id="email">
</label>
</p>
</fieldset>
</form>
<script>
const checkVisible = document.querySelector('#subscribe');
const subscribre = document.querySelector('#emailpara');
subscribre.style.backgroundColor = "blue";
const toggleVisible = ()=>{
const div = document.querySelector("#emailpara");
if (div.style.display !== "block") {
div.style.display = "block";
} else {
alert("Campos Ocultos")
div.style.display = "none";
}
}
checkVisible.addEventListener('click', toggleVisible);
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Billing</title>
</head>
<body>
<fieldset>
<legend>Billing Information</legend>
<p>
<label>
Postal Address:<br>
<input name="postaladdress" id="postaladdress"></input>
</label>
</p>
<p id="homeaddressdiv">
Home Address:<br>
<label>
<input type="checkbox" name="homepostalcheck" id="homepostalcheck">
Same as above
</label>
<br>
<input name="homeaddress" id="homeaddress"></input>
</p>
</fieldset>
</body>
<script>
const setHomeAddress = ()=>{
document.querySelector('#postaladdress')
.addEventListener('change', (e)=>{
alert(e.target.value);
});
document.querySelector('#homeaddressdiv')
.addEventListener('click', ()=>{
const addressInput = document.querySelector('#homeaddress');
const checkbox = document.querySelector('#homepostalcheck');
const postalInput = document.querySelector('#postaladdress');
if(checkbox.checked){
addressInput.disabled = true;
addressInput.value = postalInput.value;
}else{
addressInput.disabled = false;
addressInput.value = "";
}
});
}
setHomeAddress();
</script>
</html>
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package juegopoker;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
/**
*
* @author user
*/
public class JuegoPoker {
private Cartas[] mano;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
System.out.println("POKER PLAY\nSe genera la sogiente mano usuario" +
"\n\tObtuviste las siguietnes combinaciones: ");
JuegoPoker pokerJuego = new JuegoPoker();
pokerJuego.cartaAlta();
pokerJuego.doble();
pokerJuego.dobleDoble();
pokerJuego.trio();
pokerJuego.escalera();
pokerJuego.color();
pokerJuego.full();
pokerJuego.poker();
pokerJuego.escaleraColor();
}
public JuegoPoker(){
this.mano = this.repartirCincoCartas();
this.mano = new Cartas[]{
new Cartas("H", "A", 14),
new Cartas("H", "2", 2),
new Cartas("H", "3", 3),
new Cartas("H", "4", 4),
new Cartas("H", "5", 5)};
Arrays.sort(mano, Comparator.comparing(Cartas::getNumericValue).reversed());
if(mano[1].getValor().equals("2") && mano[4].getValor().equals("A")){
Cartas temp = mano[0];
mano[0] = mano[4];
mano[4] = temp;
}
}
public Cartas[] repartirCincoCartas(){
ArrayList<Cartas> mazo = Cartas.crearMazo();
Cartas[] mano = new Cartas[5];
int[] choices = new int[]{-1, -1, -1, -1, -1};
boolean repeatedChoice = false;
Scanner in = new Scanner(System.in);
int i=0;
for(i=0;i<5;i++){
repeatedChoice = false;
int choice = (int)(Math.random()*(52));
for(int temp: choices){
if(temp == choice){
i--;
repeatedChoice = true;
}
}
if(repeatedChoice) continue;
choices[i] = choice;
mano[i] = mazo.get(choice);
}
Arrays.sort(mano, Comparator.comparing(Cartas::getNumericValue).reversed());
if(mano[1].getValor().equals("2") && mano[4].getValor().equals("A")){
Cartas temp;
temp = mano[0];
mano[0] = mano[4];
mano[4] = temp;
}
return mano;
}
public void cartaAlta(){
System.out.print("\nCarta Alta: *");
for(Cartas carta: mano){
System.out.print("|"+carta.getValor()+""+carta.getPalo()+"|-");
}
}
public void dobleDoble(){
String[] act = new String[5];
String firstDoble = null;
boolean exist = false;
int dobleCount = 0;
for(int i=0;i<mano.length-1;i++){
if(mano[i].getValor().equals(mano[i + 1].getValor())){
if(firstDoble==null){
act[i] = "*";
act[i+1] = "*";
firstDoble = mano[i].getValor();
}else if(!mano[i].getValor().equals(firstDoble)){
act[i] = "*";
act[i+1] = "*";
exist = true;
}
}
}
if(exist){
System.out.print("\nDoble Doble: ");
for(int i=0;i<mano.length;i++){
if(act[i]!=null) System.out.print(act[i]);
System.out.print("|"+mano[i].getValor()+""+mano[i].getPalo()+"|-");
}
}
}
public void doble(){
String[] act = new String[5];
boolean exist = false;
for(int i=0;i<mano.length-1;i++){
if(mano[i].getValor().equals(mano[i + 1].getValor())){
act[i] = "*";
act[i+1] = "*";
exist = true;
break;
}
}
if(exist){
System.out.print("\nDoble: ");
for(int i=0;i<mano.length;i++){
if(act[i]!=null) System.out.print(act[i]);
System.out.print("|"+mano[i].getValor()+""+mano[i].getPalo()+"|-");
}
}
}
public void trio(){
String[] act = new String[5];
boolean exist = false;
for(int i=0;i<mano.length-2;i++){
if(mano[i].getValor().equals(mano[i + 1].getValor()) && mano[i].getValor().equals(mano[i+2].getValor())){
act[i] = "*";
act[i+1] = "*";
act[i+2] = "*";
exist = true;
break;
}
}
if(exist){
System.out.print("\nTrio: ");
for(int i=0;i<mano.length;i++){
if(act[i]!=null) System.out.print(act[i]);
System.out.print("|"+mano[i].getValor()+""+mano[i].getPalo()+"|-");
}
}
}
public void escalera(){
String[] act = new String[]{"*","*","*","*","*"};
boolean exist = true;
for(int i=0;i<mano.length-1;i++){
if(mano[i].getValor().equals(mano[i + 1].getValor()) ||
mano[i].getNumericValue() - mano[i+1].getNumericValue() > 1){
exist = false;
break;
}
}
if(exist){
System.out.print("\nEscalera: ");
for(int i=0;i<mano.length;i++){
if(act[i]!=null) System.out.print(act[i]);
System.out.print("|"+mano[i].getValor()+""+mano[i].getPalo()+"|-");
}
}
}
public void color(){
int paloCounterA = 1;
String[] act = new String[5];
int start;
if(mano[0].getPalo().equals(mano[1].getPalo()) ||
mano[1].getPalo().equals(mano[2].getPalo())){
start=0;
}else{
start=1;
}
act[start]="*";
for(int i=start+1;i<mano.length;i++){
if(mano[start].getPalo().equals(mano[i].getPalo())) {
paloCounterA++;
act[i] = "*";
}
}
if(paloCounterA == 4){
System.out.print("\nColor: ");
for(int i=0;i<mano.length;i++){
if(act[i]!=null) System.out.print(act[i]);
System.out.print("|"+mano[i].getValor()+""+mano[i].getPalo()+"|-");
}
}
}
public void full(){
String[] act = new String[]{"*","*","*","*","*"};
boolean exist = false;
if(mano[0].getValor().equals(mano[1].getValor()) &&
mano[0].getValor().equals(mano[2].getValor()) &&
mano[3].getValor().equals(mano[4].getValor())){
exist = true;
}else if(mano[2].getValor().equals(mano[3].getValor()) &&
mano[2].getValor().equals(mano[4].getValor()) &&
mano[0].getValor().equals(mano[1].getValor())){
exist = true;
}
if(exist){
System.out.print("\nFull House: ");
for(int i=0;i<mano.length;i++){
if(act[i]!=null) System.out.print(act[i]);
System.out.print("|"+mano[i].getValor()+""+mano[i].getPalo()+"|-");
}
}
}
public void poker(){
String[] act;
boolean exist = false;
if(mano[0].getValor().equals(mano[1].getValor()) &&
mano[0].getValor().equals(mano[2].getValor()) &&
mano[0].getValor().equals(mano[3].getValor())){
exist = true;
act = new String[]{"*","*","*","*",null};
}else if(mano[1].getValor().equals(mano[2].getValor()) &&
mano[1].getValor().equals(mano[3].getValor()) &&
mano[1].getValor().equals(mano[4].getValor())){
exist = true;
act = new String[]{null, "*","*","*","*"};
}else{
act = new String[5];
}
if(exist){
System.out.print("\nPoker: ");
for(int i=0;i<mano.length;i++){
if(act[i]!=null) System.out.print(act[i]);
System.out.print("|"+mano[i].getValor()+""+mano[i].getPalo()+"|-");
}
}
}
public void escaleraColor(){
String[] act = new String[]{"*","*","*","*","*"};
boolean exist = true;
for(int i=0;i<mano.length-1;i++){
if(mano[i].getValor().equals(mano[i + 1].getValor()) ||
mano[i].getNumericValue() - mano[i+1].getNumericValue() > 1 ||
!(mano[0].getPalo().equals(mano[i + 1].getPalo()))){
exist = false;
break;
}
}
if(exist){
System.out.print("\nEscalera Color: ");
for(int i=0;i<mano.length;i++){
if(act[i]!=null) System.out.print(act[i]);
System.out.print("|"+mano[i].getValor()+""+mano[i].getPalo()+"|-");
}
}
}
public Cartas[] getMano() {
return mano;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment