Results 1 to 2 of 2
Thread: pontoon game
- 12-07-2011, 11:17 AM #1
Member
- Join Date
- Sep 2011
- Posts
- 69
- Rep Power
- 0
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!"); } } } }
- 12-07-2011, 03:07 PM #2
Member
- Join Date
- Nov 2011
- Posts
- 24
- Rep Power
- 0
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
-
Pontoon Error
By Dave013 in forum New To JavaReplies: 1Last Post: 11-08-2011, 03:25 PM -
Complete Game Engine for beginner and intermediate game programmers
By rdjava in forum Java GamingReplies: 1Last Post: 06-02-2011, 09:29 AM -
Implementing "Game Over" in Minesweeper game based on Gridworld framework.
By JFlash in forum New To JavaReplies: 2Last Post: 08-05-2010, 04:49 AM -
game code for any game
By deathnote202 in forum Java GamingReplies: 4Last Post: 06-10-2010, 08:06 AM -
2D strategy game or 2D war game
By led1433 in forum Java 2DReplies: 5Last Post: 02-10-2009, 06:00 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks