When the Deck object runs out of cards, the play_game method displays a message that the war is over, calls the winning method (passing both p1 and p2), and displays a message with the result – player name who won. The Game class also has a method called winning which takes two player items, looks at the number of tricks they’ve won, and returns the player who has won the most tricks. Then he prints each player’s name and the card he drew, compares the two cards to see which card is the bigger one, increments the wins instance variable for the player with the highest card, and prints a message indicating who won. Two cards are drawn each time in the loop and the play_game method assigns the first card to p1 and the second card to p2. You dont necessarily need to own a 3DS yourself, as you can buy game cartridges and dump them with a friends console. The game continues until the user types “q” or when there are less than two cards left in the deck. On each loop turn, you assign the variable response to user input. As we said, a Game will be a sequence of moves of a single Card from one Pile to another. There is a loop in the method that maintains the game as long as there are two or more cards left in the deck, and as long as the variable response is not equal to q. The play_game method of the Game class starts the game. Then you create a new Deck object, store it in the instance variable deck, and create two Player objects using the names in name1 and name2.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |