Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Can you change this code to a state where the card used from the deck is removed from the deck, the player and the computer
Can you change this code to a state where the card used from the deck is removed from the deck, the player and the computer play in turns, when the user enters 2, the turn goes directly to the computer and nothing is added to the user board? import java.util.Random; import java.util.Scanner; public class Game { public static void main (String[] args) { Deck deck = new Deck(); Player computer = new Player(); Player user= new Player(); Player player= new Player(); deck.creatinggamedeck(); System.out.println("game deck"); deck.showCard(deck.gamedeck); System.out.println("game deck 2"); deck.showCard(deck.gamedeck2); System.out.println("shuffled cards"); shuffle(deck.gamedeck); deck.showCard(deck.gamedeck); int drawindex =0; dealingcards(deck.gamedeck,deck.gamedeck2,computer,user); playinggame(computer,user,deck.gamedeck,drawindex); drawcard(computer,user,deck.gamedeck,drawindex); usersturn(user,computer,deck.gamedeck,drawindex); computerturn(user,computer,deck.gamedeck,drawindex); //winner(computer,user); } private static void shuffle(Cards[] deck) { Random r= new Random(); for (int i= deck.length-1; i>0; i--) { int j = r.nextInt(i+1); Cards temp = deck[i]; deck[i]= deck[j]; deck[j] = temp; } } private static void dealingcards(Cards[] gamedeck,Cards[] gamedeck2,Player computer, Player user) { Random r = new Random(); for (int i=0;i<5;i++) { computer.deck[i]= gamedeck[i]; user.deck[i]=gamedeck[gamedeck.length-1-i]; } for (int i=0;i<5;i++) { computer.deck[i+5]= gamedeck2[r.nextInt(gamedeck2.length)]; user.deck[i+5]=gamedeck2[r.nextInt(gamedeck2.length)]; } for (int i=0; i<4;i++) { int randomindex= r.nextInt(10); computer.hand[i]= computer.deck[randomindex]; user.hand[i]= user.deck[randomindex]; } System.out.print("your hand: "); for (int i = 0; i < 4; i++) { System.out.print(user.hand[i].getName() + " "); } System.out.println(); System.out.println("computers hand: "); for (int i = 0; i < 4; i++) { System.out.print(computer.hand[i].getName() + " "); } System.out.println(); } private static void drawcard(Player computer, Player user, Cards [] gamedeck, int drawindex) { if (drawindex
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started