Skip to content

Instantly share code, notes, and snippets.

@pxpc2
Created September 4, 2018 01:25
Show Gist options
  • Select an option

  • Save pxpc2/1fb763bfb77e82e871f750020552d165 to your computer and use it in GitHub Desktop.

Select an option

Save pxpc2/1fb763bfb77e82e871f750020552d165 to your computer and use it in GitHub Desktop.
sdadasdsa
package br.unb;
import java.util.ArrayList;
import java.util.Collections;
public class Gabs
{
private static final int TNAIPES = 4, TTIPOS = 13;
private static ArrayList<Carta> cartas = new ArrayList<>();
private static String[] naipes =
{
"Paus", "Copas", "Espadas", "Ouro"
};
private static char[] tipos =
{
'A', '2', '3', '4', '5',
'6', '7', '8', '9', '1', 'J', 'Q', 'K'
};
public static void main(final String... args)
{
for (int i = 0; i < TNAIPES; i++)
{
for (int j = 0; j < TTIPOS; j++)
{
Carta c = new Carta(naipes[i], tipos[j]);
cartas.add(c);
}
}
Collections.shuffle(cartas); // ESSE MÉTODO EMBARALHA AS CARTAS
for (final Carta c : cartas)
{
System.out.println(c.toString());
}
}
static class Carta
{
String naipe; // 4 naipes
char tipo; // 13 tipos
int valor;
Carta(final String naipe, final char tipo)
{
this.naipe = naipe;
this.tipo = tipo;
setValor();
}
void setValor()
{
if (this.tipo == 'A') valor = 11;
else if (this.tipo == 'J' || this.tipo == 'Q' || this.tipo == 'K'
|| this.tipo == '1')
valor = 10;
else valor = Integer.parseInt(String.valueOf(this.tipo));
}
@Override
public String toString()
{
String t = Character.toString(this.tipo);
if (t.equals("1")) t += "0";
return t + " de " + naipe + ", valor: " + valor + " pontos.";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment