Question

Your group is required to develop a simple Android BlackJack card game. Part B (35 Marks)...

Your group is required to develop a simple Android BlackJack card game.
Part B – Group Submission (Do it on android studio)

i need the full working code in android studio

The program shall fulfil the following requirements:

1) There are total of 4 main features : User authentication/login, game setting, playing game and view history.

User Login

2) Allow the player to register new user account or login using the existing account to play the game. Each user account shall attached with password. Only authorize user can play the game.

Game Setting

3) Allow user to configure the following:

Maximum Cards: Maximum number of card the player and dealer can have.

Note: Minimum value for this setting is 3

Record history: Record the play session into the history

Playing games

4) Player can play the game as many round as they wish. For each play session, the total round play and won shall displays on the screen.

5) Below is how the game is played:

 A standard 52-card pack comprises 13 ranks in each of the four suits: clubs (♣), diamonds (♦), hearts (♥) and spades (♠) for each round.

 Face cards (Jack, Queen, King) are worth 10. Aces are worth 1 or 11, whichever makes a better hand (regardless of number of card).

 Assume the game has only 1 player and 1 dealer (computer).

 Start with 2 cards for both the player and the dealer. All the cards shall face up except one of the dealer's cards is hidden (face down) until the end.

 The player can either hit or stand.

 To 'Hit' is to ask for another card. The player can ask to hit as many times as they want until the player has maximum number of cards (configure in Setting module). If the player has reach maximum number of cards and

a) the cards’ total value is below 17, the player wins the round immediately

b) the cards’ total value is above 21, the player lost the round immediately

 To 'Stand' is to indicate that the player does not want any more cards. The player can no longer hit any more cards until this round is over.

 After the player stands, it is the dealer’s turn to hit (automatically done by computer) until his/her cards total value is 17 or higher or he has maximum number of cards (configure in the Setting module). If the dealer has reach maximum number of cards and

a) the cards’ total value is below 17, the dealer wins the round immediately.

b) the card’s total value is above 21, the dealer lost the round immediately

 If any party is dealt 21 from the start (Ace & 10), then the party got a blackjack and wins the game. However, if this happen for both party, then player will win the game.

 Besides the special situation (on the maximum number of cards reach) stated above, the party who has total cards’ values 17-21 and highest will win the game.

View History

6) The system shall also allow user to view the history of the each game session information eg: date and time the game is started, total round is played, total round won and winning % for each game session. The game session shall be recorded into the history page if the “record history” is turn on in the setting.

Homework Answers

Answer #1

import java.util.Scanner;


public class BlackjackGame {
  
private Scanner ki = new Scanner(System.in);
private int users;
private Player[] players;
private Deck deck;
private Dealer dealer = new Dealer();

// Starts game and displays the rules
public void initializeGame(){
String names;
System.out.println("Welcome to Blackjack!");
System.out.println("");
System.out.println(" BLACKJACK RULES: ");
System.out.println(" -Each player is dealt 2 cards. The dealer is dealt 2 cards with one face-up and one face-down.");
System.out.println(" -Cards are equal to their value with face cards being 10 and an Ace being 1 or 11.");
System.out.println(" -The players cards are added up for their total.");
System.out.println(" -Players “Hit” to gain another card from the deck. Players “Stay” to keep their current card total.");
System.out.println(" -Dealer “Hits” until they equal or exceed 17.");
System.out.println(" -The goal is to have a higher card total than the dealer without going over 21.");
System.out.println(" -If the player total equals the dealer total, it is a “Push” and the hand ends.");
System.out.println(" -Players win their bet if they beat the dealer. Players win 1.5x their bet if they get “Blackjack” which is 21.");
System.out.println("");
System.out.println("");
  
// Gets the amount of players and creates them
do {
System.out.print("How many people are playing (1-6)? ");
users = ki.nextInt();
  

} while (users > 6 || users < 0);

players = new Player[users];
deck = new Deck();

// Asks for player names and assigns them
for (int i = 0; i < users; i++) {
System.out.print("What is player " + (i + 1) + "'s name? ");
names = ki.next();
players[i] = new Player();
players[i].setName(names);
}
}
  
// Shuffles the deck
public void shuffle() throws InvalidDeckPositionException, InvalidCardSuitException, InvalidCardValueException {
deck.shuffle();
  
}

// Gets the bets from the players
public void getBets(){
int betValue;
  
for (int i =0; i < users; i++) {   
if (players[i].getBank() > 0) {
do {
System.out.print("How much do you want to bet " + players[i].getName() + (" (1-" + players[i].getBank()) + ")? " );
betValue = ki.nextInt();
players[i].setBet(betValue);
} while (!( betValue > 0 && betValue <= players[i].getBank()));
System.out.println("");
}

}

}
  
// Deals the cards to the players and dealer
public void dealCards(){
for (int j = 0; j < 2; j++) {
for (int i =0; i < users; i++) {
if(players[i].getBank() > 0)
{
players[i].addCard(deck.nextCard());
}
}

dealer.addCard(deck.nextCard());
}
}
  
// Initial check for dealer or player Blackjack
public void checkBlackjack(){
//System.out.println();

if (dealer.isBlackjack() ) {
System.out.println("Dealer has BlackJack!");
for (int i =0; i < users; i++) {
if (players[i].getTotal() == 21 ) {
System.out.println(players[i].getName() + " pushes");
players[i].push();
} else {
System.out.println(players[i].getName() + " loses");
players[i].bust();
}   
}
} else {
if (dealer.peek() ) {
System.out.println("Dealer peeks and does not have a BlackJack");
}

for (int i =0; i < users; i++) {
if (players[i].getTotal() == 21 ) {
System.out.println(players[i].getName() + " has blackjack!");
players[i].blackjack();
}
}
}   
}
  
// This code takes the user commands to hit or stand
public void hitOrStand() {
String command;
char c;
for (int i = 0; i < users; i++) {
if ( players[i].getBet() > 0 ) {
System.out.println();
System.out.println(players[i].getName() + " has " + players[i].getHandString());

do {
do {
System.out.print(players[i].getName() + " (H)it or (S)tand? ");
command = ki.next();
c = command.toUpperCase().charAt(0);
} while ( ! ( c == 'H' || c == 'S' ) );
if ( c == 'H' ) {
players[i].addCard(deck.nextCard());
System.out.println(players[i].getName() + " has " + players[i].getHandString());
}
} while (c != 'S' && players[i].getTotal() <= 21 );
}
}
}
  
// Code for the dealer to play
public void dealerPlays() {
boolean isSomePlayerStillInTheGame = false;
for (int i =0; i < users && isSomePlayerStillInTheGame == false; i++){
if (players[i].getBet() > 0 && players[i].getTotal() <= 21 ) {
isSomePlayerStillInTheGame = true;
}
}
if (isSomePlayerStillInTheGame) {
dealer.dealerPlay(deck);
}
}
  
// This code calculates all possible outcomes and adds or removes the player bets
public void settleBets() {
System.out.println();

for (int i = 0; i < users; i++) {
if (players[i].getBet() > 0 ) {
if( players[i].getTotal() > 21 ) {
System.out.println(players[i].getName() + " has busted");
players[i].bust();
} else if ( players[i].getTotal() == dealer.calculateTotal() ) {
System.out.println(players[i].getName() + " has pushed");
players[i].push();
} else if ( players[i].getTotal() < dealer.calculateTotal() && dealer.calculateTotal() <= 21 ) {
System.out.println(players[i].getName() + " has lost");
players[i].loss();
} else if (players[i].getTotal() == 21) {
System.out.println(players[i].getName() + " has won with blackjack!");
players[i].blackjack();
} else {
System.out.println(players[i].getName() + " has won");
players[i].win();
  
}
}
}

}

// This prints the players hands
public void printStatus() {
for (int i = 0; i < users; i++) {
if(players[i].getBank() > 0)
{
System.out.println(players[i].getName() + " has " + players[i].getHandString());
}
}
System.out.println("Dealer has " + dealer.getHandString(true, true));
}
  
// This prints the players banks and tells the player if s/he is out of the game
public void printMoney() {
for (int i = 0; i < users; i++) {
if(players[i].getBank() > 0)
{
System.out.println(players[i].getName() + " has " + players[i].getBank());
}
if(players[i].getBank() == 0)
{
System.out.println(players[i].getName() + " has " + players[i].getBank() + " and is out of the game.");
players[i].removeFromGame();
}
}
}

// This code resets all hands
public void clearHands() {
for (int i = 0; i < users; i++) {
players[i].clearHand();
}
dealer.clearHand();

}
  
// This decides to force the game to end when all players lose or lets players choose to keep playing or not
public boolean playAgain() {
String command;
char c;
Boolean playState = true;
if(forceEnd()) {
playState = false;
}
else {
do {
System.out.println("");
System.out.print("Do you want to play again (Y)es or (N)o? ");
command = ki.next();
c = command.toUpperCase().charAt(0);
} while ( ! ( c == 'Y' || c == 'N' ) );
if(c == 'N')
{
playState = false;
}
}
return playState;
}
  
// This says true or false to forcing the game to end
public boolean forceEnd() {
boolean end = false;
int endCount = 0;
  
for (int i = 0; i < users; i++) {
if(players[i].getBank() == -1)
{
endCount++;
}
}
if(endCount == users)
{
end = true;
}
if(end)
{
System.out.println("");
System.out.println("All players have lost and the game ends.");
}
  
return end;
}
  
// This is the endgame code for when all players are out of the game or players decide to stop playing
public void endGame() {
int endAmount;
String endState = " no change.";
System.out.println("");
for (int i = 0; i < users; i++) {
if(players[i].getBank() == -1)
{
players[i].resetBank();
}
endAmount = players[i].getBank() - 100;
if(endAmount > 0)
{
endState = " gain of ";
}
else if(endAmount < 0)
{
endState = " loss of ";
}
System.out.println(players[i].getName() + " has ended the game with " + players[i].getBank() + ".");
if(endState != " no change.")
{
System.out.println("A" + endState + Math.abs(endAmount) + ".");
}
else
{
System.out.println("No change from their starting value.");   
}
System.out.println("");
}
System.out.println("");
System.out.println("");
System.out.println("Thank you for playing!");
}


} //End class

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Python Blackjack Game Here are some special cases to consider. If the Dealer goes over 21,...
Python Blackjack Game Here are some special cases to consider. If the Dealer goes over 21, all players who are still standing win. But the players that are not standing have already lost. If the Dealer does not go over 21 but stands on say 19 points then all players having points greater than 19 win. All players having points less than 19 lose. All players having points equal to 19 tie. The program should stop asking to hit if...
Program will allow anywhere between 1 and 6 players (inclusive). Here is what your output will...
Program will allow anywhere between 1 and 6 players (inclusive). Here is what your output will look like: Enter number of players: 2 Player 1: 7S 5D - 12 points Player 2: 4H JC - 14 points Dealer: 10D Player 1, do you want to hit? [y / n]: y Player 1: 7S 5D 8H - 20 points Player 1, do you want to hit? [y / n]: n Player 2, do you want to hit? [y / n]: y...
JAVA: MUST BE DONE IN JAVA Assignment: Write algorithms and programs to play “non-betting” Craps. Craps...
JAVA: MUST BE DONE IN JAVA Assignment: Write algorithms and programs to play “non-betting” Craps. Craps is a game played with a pair of dice. In the game, the shooter (the player with the dice) rolls a pair of dice and the number of spots showing on the two upward faces are added up. If the opening roll (called the “coming out” roll) is a 7 (“natural”) or 11 (“yo-leven”), the shooter immediately wins the game. If the coming out...
Delta airlines case study Global strategy. Describe the current global strategy and provide evidence about how...
Delta airlines case study Global strategy. Describe the current global strategy and provide evidence about how the firms resources incompetencies support the given pressures regarding costs and local responsiveness. Describe entry modes have they usually used, and whether they are appropriate for the given strategy. Any key issues in their global strategy? casestudy: Atlanta, June 17, 2014. Sea of Delta employees and their families swarmed between food trucks, amusement park booths, and entertainment venues that were scattered throughout what would...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT