Advertisement
makispaiktis

CardsGame - Game.java

Mar 17th, 2020 (edited)
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.17 KB | None | 0 0
  1. import java.util.ArrayList;
  2.  
  3. public class Game {
  4.    
  5.     // Variables
  6.     Player bot;
  7.     Player user;
  8.     CardsPack trapoula;
  9.    
  10.     // Constructors
  11.     Game(){
  12.         bot = new Player();
  13.         user = new Player();
  14.         trapoula = new CardsPack();
  15.     }
  16.     Game(Player user, CardsPack trapoula){
  17.         this.bot = new Player("Bot");
  18.         this.user= user;
  19.         this.trapoula = trapoula;
  20.     }
  21.     // THE MOST USED CONSTRUCTOR WILL BE THE FOLLOWING
  22.     Game(Player user){
  23.         this.bot = new Player("Bot");
  24.         this.user = user;
  25.         this.trapoula = new CardsPack();
  26.         trapoula.shuffle();
  27.     }
  28.    
  29.    
  30.     // Methods
  31.    
  32.     // Auxiliary Functions
  33.     // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  34.     public static void displayArrayList(ArrayList <Card> myList){
  35.         for(int i=0; i<myList.size(); i++){
  36.             System.out.print(myList.get(i).abbreviation + ", ");
  37.         }
  38.         System.out.println();
  39.     }
  40.     // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  41.     // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  42.     public static void displayDeck(ArrayList <Card> deck){
  43.         System.out.print("---->    ");
  44.         for(int i=0; i<deck.size(); i++){
  45.             System.out.print(deck.get(i).abbreviation + " # ");
  46.         }
  47.         System.out.print("   <----");
  48.         System.out.println();
  49.     }
  50.     // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  51.    
  52.    
  53.     public void showStatus(){
  54.         System.out.println("    ******** Game Status ********");
  55.         System.out.println();
  56.         System.out.println("Player 1 ----> " + bot.name);
  57.         System.out.println("Player 2 ----> " + user.name);
  58.         System.out.println("CardsPack trapoula status: ");
  59.         trapoula.showStatus();
  60.     }
  61.    
  62.    
  63.     // ***************************************************************************************
  64.     // **************************************************************************************
  65.    
  66.     // Function that throws down the 4 first cards of the cardsPack
  67.     public void firstStep(Deck deck){
  68.         // First, I will scan the trapoula in order to find the first 4 cards
  69.         ArrayList first4Cards = trapoula.returnFirstNCards(4);
  70.         trapoula.removeFirstNCards(4);
  71.         deck.addCardsInDeck(first4Cards);
  72.         deck.display();
  73.         showStatus();
  74.     }
  75.    
  76.    
  77.     public void give6CardsToPlayer(Player player){
  78.         ArrayList <Card> givenCards = trapoula.returnFirstNCards(6);
  79.         trapoula.removeFirstNCards(6);
  80.         player.addCardsInHand(givenCards);
  81.     }
  82.    
  83.    
  84.    
  85.     public static void startGame(Game game, Deck deck, Player bot, Player user){
  86.         game.firstStep(deck);
  87.         game.give6CardsToPlayer(bot);
  88.         game.give6CardsToPlayer(user);
  89.         // 1. Checking the 1st round statistics
  90.         System.out.println();
  91.         System.out.println("^^^^^^^^ ROUND 1 ^^^^^^^^");
  92.         System.out.println("Bot's first 6 cards: ");
  93.         bot.showCards();
  94.         System.out.println();
  95.         System.out.println("User's first 6 cards: ");
  96.         user.showCards();
  97.         System.out.println();
  98.         System.out.println("Trapoula status (must have been with 36 cards: )");
  99.         game.trapoula.showStatus();
  100.     }
  101.    
  102.     // ***************************************************************************************
  103.     // ***************************************************************************************
  104.    
  105.    
  106.    
  107.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  108.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  109.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  110.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  111.    
  112.     // MAIN FUNCTION
  113.     public static void main(String[] args) {
  114.        
  115.        
  116.        
  117.         // ***************************************************************************************
  118.         // ***************************************************************************************
  119.         // ***************************************************************************************
  120.         // ***************************************************************************************
  121.         /*
  122.         // I try to create a game
  123.         Player thomas = new Player("Thomas");
  124.         // Create 4 cards
  125.         Card card1 = new Card("1", "heart");
  126.         Card card2 = new Card("2", "club");
  127.         Card card3 = new Card("3", "diamond");
  128.         Card card4 = new Card("4", "spade");
  129.         // Create a cards array
  130.         ArrayList <Card> thomasCards = new ArrayList <Card> ();
  131.         thomasCards.add(card1);
  132.         thomasCards.add(card2);
  133.         thomasCards.add(card3);
  134.         thomasCards.add(card4);
  135.         // ADD CARDS
  136.         thomas.addCardsInHand(thomasCards);
  137.         // Create the game
  138.         Game tryGame = new Game(thomas);
  139.         tryGame.showStatus();
  140.         // Now, I will do this
  141.         // I will remove the first card of the game trapoula
  142.         // And I will add it in thomas' cards array
  143.         CardsPack thomasTrapoula =tryGame.trapoula;
  144.         Card firstCard = thomasTrapoula.cards.get(0);
  145.         thomasTrapoula.cards.remove(firstCard);
  146.         thomas.addCardInHand(firstCard);
  147.         // Check if this is done
  148.         System.out.println();
  149.         System.out.println();
  150.         System.out.println("After removing first card from the deck");
  151.         thomas.showCards();
  152.         tryGame.showStatus();
  153.         // Try the method grabCards
  154.         Card grabbed1 = new Card("6", "heart");
  155.         Card grabbed2 = new Card("6", "club");
  156.         ArrayList <Card> grabbedList = new ArrayList <Card> ();
  157.         grabbedList.add(grabbed1);
  158.         grabbedList.add(grabbed2);
  159.         thomas.grabCards(grabbedList);
  160.         System.out.println();
  161.         System.out.println();
  162.         System.out.println("Trying the grabCards method: ");
  163.         thomas.showStatus();
  164.         */
  165.         // Runs properly
  166.        
  167.         Player BOT = new Player();
  168.         Player THOMAS = new Player("Thomas");
  169.         Game THOMASgame = new Game(THOMAS);
  170.         Deck THOMASdeck = new Deck();
  171.         startGame(THOMASgame, THOMASdeck, BOT, THOMAS);
  172.         System.out.println("END");
  173.        
  174.        
  175.         // ***************************************************************************************
  176.         // ***************************************************************************************
  177.         // ***************************************************************************************
  178.         // ***************************************************************************************
  179.        
  180.     }   // END OF MAIN
  181.  
  182. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement