Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- public class Game {
- // Variables
- Player bot;
- Player user;
- CardsPack trapoula;
- // Constructors
- Game(){
- bot = new Player();
- user = new Player();
- trapoula = new CardsPack();
- }
- Game(Player user, CardsPack trapoula){
- this.bot = new Player("Bot");
- this.user= user;
- this.trapoula = trapoula;
- }
- // THE MOST USED CONSTRUCTOR WILL BE THE FOLLOWING
- Game(Player user){
- this.bot = new Player("Bot");
- this.user = user;
- this.trapoula = new CardsPack();
- trapoula.shuffle();
- }
- // Methods
- // Auxiliary Functions
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- public static void displayArrayList(ArrayList <Card> myList){
- for(int i=0; i<myList.size(); i++){
- System.out.print(myList.get(i).abbreviation + ", ");
- }
- System.out.println();
- }
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- public static void displayDeck(ArrayList <Card> deck){
- System.out.print("----> ");
- for(int i=0; i<deck.size(); i++){
- System.out.print(deck.get(i).abbreviation + " # ");
- }
- System.out.print(" <----");
- System.out.println();
- }
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- public void showStatus(){
- System.out.println(" ******** Game Status ********");
- System.out.println();
- System.out.println("Player 1 ----> " + bot.name);
- System.out.println("Player 2 ----> " + user.name);
- System.out.println("CardsPack trapoula status: ");
- trapoula.showStatus();
- }
- // ***************************************************************************************
- // **************************************************************************************
- // Function that throws down the 4 first cards of the cardsPack
- public void firstStep(Deck deck){
- // First, I will scan the trapoula in order to find the first 4 cards
- ArrayList first4Cards = trapoula.returnFirstNCards(4);
- trapoula.removeFirstNCards(4);
- deck.addCardsInDeck(first4Cards);
- deck.display();
- showStatus();
- }
- public void give6CardsToPlayer(Player player){
- ArrayList <Card> givenCards = trapoula.returnFirstNCards(6);
- trapoula.removeFirstNCards(6);
- player.addCardsInHand(givenCards);
- }
- public static void startGame(Game game, Deck deck, Player bot, Player user){
- game.firstStep(deck);
- game.give6CardsToPlayer(bot);
- game.give6CardsToPlayer(user);
- // 1. Checking the 1st round statistics
- System.out.println();
- System.out.println("^^^^^^^^ ROUND 1 ^^^^^^^^");
- System.out.println("Bot's first 6 cards: ");
- bot.showCards();
- System.out.println();
- System.out.println("User's first 6 cards: ");
- user.showCards();
- System.out.println();
- System.out.println("Trapoula status (must have been with 36 cards: )");
- game.trapoula.showStatus();
- }
- // ***************************************************************************************
- // ***************************************************************************************
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // MAIN FUNCTION
- public static void main(String[] args) {
- // ***************************************************************************************
- // ***************************************************************************************
- // ***************************************************************************************
- // ***************************************************************************************
- /*
- // I try to create a game
- Player thomas = new Player("Thomas");
- // Create 4 cards
- Card card1 = new Card("1", "heart");
- Card card2 = new Card("2", "club");
- Card card3 = new Card("3", "diamond");
- Card card4 = new Card("4", "spade");
- // Create a cards array
- ArrayList <Card> thomasCards = new ArrayList <Card> ();
- thomasCards.add(card1);
- thomasCards.add(card2);
- thomasCards.add(card3);
- thomasCards.add(card4);
- // ADD CARDS
- thomas.addCardsInHand(thomasCards);
- // Create the game
- Game tryGame = new Game(thomas);
- tryGame.showStatus();
- // Now, I will do this
- // I will remove the first card of the game trapoula
- // And I will add it in thomas' cards array
- CardsPack thomasTrapoula =tryGame.trapoula;
- Card firstCard = thomasTrapoula.cards.get(0);
- thomasTrapoula.cards.remove(firstCard);
- thomas.addCardInHand(firstCard);
- // Check if this is done
- System.out.println();
- System.out.println();
- System.out.println("After removing first card from the deck");
- thomas.showCards();
- tryGame.showStatus();
- // Try the method grabCards
- Card grabbed1 = new Card("6", "heart");
- Card grabbed2 = new Card("6", "club");
- ArrayList <Card> grabbedList = new ArrayList <Card> ();
- grabbedList.add(grabbed1);
- grabbedList.add(grabbed2);
- thomas.grabCards(grabbedList);
- System.out.println();
- System.out.println();
- System.out.println("Trying the grabCards method: ");
- thomas.showStatus();
- */
- // Runs properly
- Player BOT = new Player();
- Player THOMAS = new Player("Thomas");
- Game THOMASgame = new Game(THOMAS);
- Deck THOMASdeck = new Deck();
- startGame(THOMASgame, THOMASdeck, BOT, THOMAS);
- System.out.println("END");
- // ***************************************************************************************
- // ***************************************************************************************
- // ***************************************************************************************
- // ***************************************************************************************
- } // END OF MAIN
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement