Question: Write a Python code to allow a player to play the game war with against the computer. Use Lists to store your decks. Use integers
Write a Python code to allow a player to play the game war with against the computer. Use Lists to store your decks.
Use integers to represent the values of your cards Ace =1, Two = 2, Three = 3, Four = 4, Five = 5. T = 10, J = 11, Q = 12, K = 13
Use a menu with the following options:
1. Play- plays one round of war.
2. Display Scores-Displays the number of cards in each players deck
3. Display Cards-Displays the players cards in ascending order.
4. Win Percentage- Displays the percentage of battles the player has one
5. Quit- Quit the game
Implement the following functions:
1. initializeDeck: Initialize a deck of 52 cards. Use four of each of the value 1-13.
2. shuffleEeck: Take the newly created deck and shuffle it. (One way to shuffle is to swap the value two randomly selected locations-Repeat until the deck is fully shuffled-
3. splitDeck: Pass in the full shuffled deck, remove half of it place it into the new deck.
4. sortDeck-Returned a sorted deck that has been passed in. (Do not sort the actual deck, sort a copy of it and return it).
5. printDeck- Prints the content of the deck in ascending order (You should call sortD in it)
6. distributeCards- Places battle card at the bottom of the winners deck. (loser loses a card to the winner, winner places their played card at the bottom of their deck)
7. Battle- Plays a single round. Compare top cards of each deck, determines the winner, calls distributeCards, and returns who won. Call the war method -when both cards are of equal value- to determin the winner.
8. War repeats as long as there is a tie. Determines the winner, calls distributeCards(), and returns who won. If a player does not have enough cards to play a war, they lose. (do not use System.exit()). ?
9. displayStatistics calculate and display the percentage of player wins.
10. displayScore displays the number of cards in both decks.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
