Results 1 to 2 of 2

Thread: pontoon game

  1. #1
    andnlou2678 is offline Member
    Join Date
    Sep 2011
    Posts
    69
    Rep Power
    0

    Default pontoon game

    hi guys i have to make a pontoon game i have some code that kind of works but it wont go bust when the score goes over 21 and also i would like to have it output which card is being recived by the computer and the player

    many thanks Andy.

    code

    Java Code:
    import java.util.Scanner;
    
    public class Pontoon
    {
    
         public static void main(String[] args)
    	 {
    		  Scanner input = new Scanner(System.in);
    		  int playerScore = 0, computerScore = 0;
    		  String newCard = "";
    		  playerScore += dealCard();
    		  playerScore += dealCard();
    		  computerScore += dealCard();
    		  computerScore += dealCard();
    
    		  System.out.printf("Your score is %d would you like another card ? y/n ", playerScore);
    		  newCard = input.nextLine();
    		  
            if(newCard.equalsIgnoreCase("Y"))
    		{
            while (newCard.equalsIgnoreCase("Y"))
    		{
                 playerScore += dealCard();
                 System.out.printf("Your score is %d would you like another card ? y/n ", playerScore);
                 newCard = input.nextLine();
                }
            }
            while(computerScore < 15)
    		{
                computerScore += dealCard();
            }
            checkWin(playerScore, computerScore);
        }
        public static int dealCard()
    	{
            int value = (int) (Math.random() * 13) + 1;
            int score = 0;
            if(value == 1)
    		{
                System.out.println("Ace!");
                score = 11;
            }
    		else if (value == 13)
    		{
                System.out.println("King!");
                score = 10;
            }
    		else if (value == 12)
    		{
                System.out.println("Queen!");
                score = 10;
            } 
    		else if (value == 11)
    		{
                System.out.println("Jack!");
                score = 10;
            } else 
    		{
                System.out.println(value);
    			score = value;
            }
    
            return score;
        }
    
        public static void checkWin(int Player, int Computer) {
            int player = Player;
            int computer = Computer;
    
            if (player > 21)
    		{
                System.out.println("Player Bust");
            } 
    		else if (computer > 21)
    		{
                System.out.println("Computer Bust");
            } 
    		else
    		{
            if (player > computer)
    		{
    			System.out.println("Player Wins!");
            } 
    		else
    		{
                System.out.println("Computer Wins!");
                }
            }
        }
    }

  2. #2
    CHLim is offline Member
    Join Date
    Nov 2011
    Posts
    24
    Rep Power
    0

    Default Re: pontoon game

    i've tried you program, and it did go bust after i went past 21. But only after inputting n when ask if i want to continue.

    I'm guessing that you want to do something like, printing out "the player has gone bust" immediately after the player has gone past 21.

    If so than there are 2 ways you can do that. First you can try to add in another condition at line 21. Second you can can add another statement between line 23 & 24 that breaks out of the while loop once the player had gone past 21 points.


    As for your second question, too me the program is printing out the card being received. So I don't see why theres is a problem there.

Similar Threads

  1. Pontoon Error
    By Dave013 in forum New To Java
    Replies: 1
    Last Post: 11-08-2011, 03:25 PM
  2. Replies: 1
    Last Post: 06-02-2011, 09:29 AM
  3. Replies: 2
    Last Post: 08-05-2010, 04:49 AM
  4. game code for any game
    By deathnote202 in forum Java Gaming
    Replies: 4
    Last Post: 06-10-2010, 08:06 AM
  5. 2D strategy game or 2D war game
    By led1433 in forum Java 2D
    Replies: 5
    Last Post: 02-10-2009, 06:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •