Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Assignment Write a Java program that simulates a Star Wars variation of the card game, “War”.
- In this game there will be two players, the user and the computer. Each player will be dealt 6 random cards. Each card will have a “strength” value and a corresponding character from the Star Wars saga. In this version of the game, we will assume that there is more than one copy of each card and so a player may receive duplicates of some cards.
- The program should prompt the user to play as the light side or dark side of the Force. Once the game starts, the player and computer will both draw a card. The player who draws the card with the higher number (strength value) wins and receives two points for winning the “battle” (one point for his/her own card and one for the enemy’s).
- If the players draw cards of equal value, this is a “war.” The user will be prompted to draw again. The winner of the war is the one whose second card is higher. If the two cards are still the same value, they draw again until the players run out of cards (in which case the result of this war is a draw) or until one of the players obtains a card of higher value. The player that wins a war receives points for all his/her cards plus all the opponent’s cards. So, for instance, if the player won a war in which 3 cards were drawn, the player receives 6 points (3 for the player’s own cards and 3 for the opponent’s).
- The user also has the option every turn to either continue the game (draw another card) or quit the game (in which case the user surrenders and the computer automatically wins). The winner of the game is the player with the most points after all five cards in the players’ decks have been played. If both players have equal points, the result is a draw.
- In addition to the main method, there should be two methods (one for each side, light and dark) that determine which card was drawn based on a randomly generated number (that has value 0-5). Once the card has been determined, the method should print the character’s name and strength value. It should then return the strength value as an integer. The characters and values for the cards are as follows:
- Light Side: Dark Side:
- Character Strength Character Strength Master Yoda 5 Emperor Palpatine 5 Obi-Wan Kenobi 4 Darth Vader 4
- Luke Skywalker 3 Darth Maul 3 Han Solo 2 Boba Fett 2 R2-D2 1 Jabba the Hutt 1 C-3P0 0 Greedo 0
- Inside each of these methods, you should use a set of two parallel one-dimensional arrays, one to store the characters’ names and one to store the corresponding strength values. These arrays will be used to determine the card drawn. The card drawn should be the one in the position that is equal to the random number generated. So, if the random number happens to be 2, the character chosen should be the one at array[2]. Also, set up the arrays so that a character’s position in one array is the same as the position of the character’s strength value in the other array. In other words, if Master Yoda is located at nameArray[5], for example, then his strength value should be in strengthArray[5]. The prototype for the above methods should look like the following:
- int drawLightSide (int cardNumber) int drawDarkSide (int cardNumber)
- In addition, there should be one other method that determines the winner of a battle (or war). This method should take two values, one for the light side character’s strength and one for the dark side character’s strength. It should compare the values, decide which one is higher, then print the winner of the battle. It should also add the appropriate number of points to the winning player’s total. If the values are the same, however, the method should print a message asking the user to draw again. Note that the method should keep track of the total number of cards drawn during a war so that it can add the correct number of points to the winner’s total at the end of the war. The prototype for the method should look like this:
- void battle (int lightValue, int darkValue)
Advertisement
Add Comment
Please, Sign In to add comment