Advertisement
Guest User

Untitled

a guest
May 4th, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. public class
  2. TestFrame {
  3.  
  4. //VARIABLES
  5. private static Deck deck;
  6. private static Card card;
  7. private static Scanner scan;
  8. private final static String fileName = "cards.txt";
  9. static ArrayList<Card> cards = new ArrayList<>();
  10.  
  11. private static void Load(){
  12.  
  13. deck = new Deck();
  14. card = new Card();
  15.  
  16. // Load in the card file so that we can work with the data from cards.txt internally rather than from the file constantly.
  17.  
  18. try(FileReader fr = new FileReader(fileName);
  19. BufferedReader br = new BufferedReader(fr);
  20. Scanner infile = new Scanner(br)){
  21.  
  22. int numOfCards = infile.nextInt();
  23. infile.nextLine(); // Do we need this? Yes we do. Illuminati confirmed.
  24. for(int i=0; i < numOfCards; i++){
  25. String value = infile.nextLine();
  26. String suit = infile.nextLine();
  27. Card newCard = new Card(value, suit);
  28. card.addCard(newCard);
  29. System.out.print(newCard.getValue());
  30. System.out.print(newCard.getSuit());
  31. System.out.println(" ");
  32. //Print out the object before cycling through again so we can see if it's working
  33. //We can use this to add then cards to the shuffle array at a later date
  34. }
  35.  
  36. }
  37.  
  38. ah
  39. 2h
  40. 3h
  41. 4h
  42. 5h
  43. 6h
  44. 7h
  45. 8h
  46.  
  47. private static void displayAllCards(){
  48. Card[] cards = Card.getAll();
  49. for(Card c : cards){
  50. System.out.print(Card.getValue());
  51. System.out.print(Card.getSuit());
  52. System.out.println(" ");
  53. }
  54. }
  55.  
  56. public static Card[] getAll(){
  57. Card[] brb = new Card[cards.size()];
  58. int tempCount = -1;
  59. for(Card c : cards){
  60. tempCount++;
  61. brb[tempCount] = c;
  62. }
  63. return brb;
  64. }
  65.  
  66. card.addCard(newCard);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement