What game making program should we use?

Java help! Making Game of War Card game program!?

  • This is my program for a simple game of war card game. Here are the rules of the game: Deal out all the cards, so that each player has 26. Players do not look at their cards, but keep them in a packet face down. The object of the game is to win all the cards. Both players now turn their top card face up and put them on the table. Whoever turned the higher card takes both cards and adds them (face down) to the bottom of their packet. Face cards have these values: Jack = 11 Queen = 12 King = 13 and Ace = 14. Then both players turn up their next card and so on. You will want to output to the screen the number of cards each player has remaining. If the turned up cards are equal there is a war. The tied cards stay on the table and both players play the next card of their pile face down and then another card face-up. Whoever has the higher of the new face-up cards wins the war and adds all six cards face-down to the bottom of their packet. If the new face-up cards are equal as well, the war continues: each player puts another card face-down and one face-up. The war goes on like this as long as the face-up cards continue to be equal. As soon as they are different the player of the higher card wins all the cards in the war.The game continues until one player has all the cards and wins. This can take a long time! What happens if you don’t have enough cards to play war? If you don't have enough cards to complete the war, you lose! Example: Players A and B both play sevens, so there is a war. Each player plays a card face down, but this is player B's last card. Player A wins. Sorry it's long :/ I think what I'm doing wrong is when the two cards equal each other. I don't know what going wrong though there though :/ Any help explaining why it isn't working would be great. Thanks in advance! :) Here's my program: import java.util.Scanner; import java.util.Random; //Importing random class. public class GameOfWarjamalaps{ public static void main(String[] args){ //Initializing the variables. int playerOne = 26; int playerTwo = 26; //Making a while loop so as long as one player has more than the other, //the game still goes on. do{ //Constructing the random class to generate random //numbers. Random random1 = new Random(); //Random # for first player. Random random2 = new Random(); //Random # for second player. //DELETE random1.nextInt(2, 14);?!?!?! //Making an integer that increments everytime the loop is run incase the cards turn up equal. for(;;){ int i = 1; int cardOne = random1.nextInt(14); //Player one's card. int cardTwo = random2.nextInt(14); //Player two's card. System.out.printf("Player one's card is %d. Player two's card is %d.\n", cardOne, cardTwo); //Subtracting the cards the players have used. playerOne = playerOne - 1; playerTwo = playerTwo - 1; //Making if statements to see whether one card is higher than the other. if(cardOne > cardTwo){ playerOne = playerOne + 2 * i; i = 1; } else if(cardTwo > cardOne){ playerTwo = playerTwo + 2 * i; i = 1; } else if(cardOne == cardTwo){ i = i + 2; playerOne = playerOne - 1; playerTwo = playerTwo - 1; System.out.printf("The players have drawn the same card. They have both burned one and their next cards are being played.\n"); } //Displaying the amount of cards each player has. System.out.printf("Player one has %d cards left. Player two has %d cards left.\n", playerOne, playerTwo); Scanner keyboard = new Scanner(System.in); String blah = keyboard.nextLine(); } }while(playerOne == 0 || playerTwo == 0); } }

  • Answer:

    Here are some rules to help you: http://boardgames.about.com/od/cardgames/a/war.htm

chatchater at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

Here are some rules to help you: http://boardgames.about.com/od/cardgames/a/war.htm

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.