Advertisement
Alfoli

Jogo - classe baralho

Mar 13th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.List;
  3. import java.util.Collections;
  4.  
  5. public class Baralho {
  6.     private List<Carta> baralho = new ArrayList<Carta>();
  7.    
  8.     public Baralho(){
  9.        
  10.         baralho = new ArrayList<Carta>();
  11.     }
  12.    
  13.     public Baralho(int qtNaipe, char naipe) {
  14.         String nome;
  15.         Carta c;
  16.         if (qtNaipe == 1) {
  17.             for (int numcarta = 1; numcarta <14; numcarta++) {
  18.                 nome = String.format("%d", numcarta) + "-" + naipe + ".png";
  19.                 c = new Carta(nome, naipe, numcarta, false);
  20.                 baralho.add(c);
  21.             }
  22.         }
  23.        
  24.         if (qtNaipe == 4) {
  25.             for (int i =1; i<4; i++) {
  26.                 switch(i) {
  27.                     case 1:{
  28.                         naipe = 'o';
  29.                         break;
  30.                     }
  31.                    
  32.                     case 2:{
  33.                         naipe = 'c';
  34.                         break;
  35.                     }
  36.                    
  37.                     case 3:{
  38.                         naipe = 'e';
  39.                         break;
  40.                     }
  41.                    
  42.                     case 4:{
  43.                         naipe = 'p';
  44.                         break;
  45.                     }
  46.                 }
  47.                 for (int nc = 1; nc <14; nc++) {
  48.                     nome = String.format("%d", nc) + "-" + naipe + ".png";
  49.                     c = new Carta(nome, naipe, nc, false);
  50.                     baralho.add(c);
  51.                 }
  52.             }
  53.         }
  54.        
  55.        
  56.     }
  57.    
  58.     public int qtdade() {
  59.         return baralho.size();
  60.     }
  61.    
  62.     public void embaralha() {
  63.         Collections.shuffle(baralho);
  64.     }
  65.    
  66.     public Carta getcarta(int pos) {
  67.         Carta c = baralho.get(pos);
  68.         baralho.remove(pos);
  69.         return c;
  70.     }
  71.    
  72.     public String toString() {
  73.         String saida = ">>>>> Baralho <<<<<";
  74.         for (Carta c: baralho) {
  75.             saida = saida + c.toString() + "\n";
  76.         }
  77.         return saida;
  78.     }
  79.    
  80.    
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement