联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp2

您当前位置:首页 >> Java编程Java编程

日期:2020-08-01 11:20

Write a program that simulates a card game involving 3 players and a deck of 48 Catalan

cards shown below

Each card in the deck is identified by its suit and value.

The suit of a card maybe any among the following: "Clubs", "Golds", "Cups", "Swords"

The value of the card can be any number from 1 to 12 (Note that there are 12 values per

suit even though the image above only shows 10)

Your program should use an interactive menu to simulate the progress of the game

among 3 players.  


The program begins by displaying the following menu options and prompt the user to

select an option: (10 pts)

s: start new game

p: Pull cards for all players

o: output deck

h: output players’ hand

e: exchange one card

d: declare winner

q: quit

Select an option:

Note the last prompt must end with a newline.

If the user selects option q, the program should end.

If the user selects any other option, the program should take the appropriate action and

display the menu again.

If the user selects options p, o, h, e, d before selecting s, the program should print the

message “Please select option s to start a new game” and it should display the menu

again.

s: start new game (20 pts)

The user selects this option to start a new game. When this option is selected, the

program should do three things:

1. Prompt the user to enter the names of the three players as follows: (5 pts)

Enter player 1’s name:

Alexander the Great

Enter player 2’s name:

Bismarck

Enter player 3’s name:

Charles V of Spain

2. Build a deck of 48 Catalan cards using an appropriate data structure (list/dictionary/

etc) (10 pts)

3. Create an empty hand of cards for each player using an appropriate data structure.

If the players’ hand has cards from a previous game, those cards should be deleted.

(5 pts)

p: Pull cards for all players (10 pts)

If the deck has at least 9 cards, add three cards from the deck to each of the player’s

hand. Do not overwrite the cards that are already in the player’s hand. The cards should

be selected from the deck at random. The deck should be updated so that the cards that

are given to the players are removed from the deck.

Hint: Consider using an appropriate function from the random module: random.randint()

or random.shuffle()

o: output deck (5 pts)

Print the cards remaining in the deck first in the order of their suit: "Clubs", "Golds",

"Cups", "Swords". For each suit print the cards in ascending order of the values. Below is

an example of a deck that has only 12 cards left:

Clubs 1

Clubs 7

Clubs 10

Clubs 12

Golds 2

Golds 9

Golds 11

Golds 12

Cups 2

Cups 9

Cups 11

Swords 2

h: output players’ hand (5 pts)

Print the name of each player followed by the cards in that player’s hand using the same

format as above. An example output is shown below:

Alexander the Great

Golds 8

Cups 3

Cups 10

Bismarck

Clubs 12

Golds 7

Cups 1

Charles V of Spain

Clubs 8

Golds 9

Swords 5

e: exchange one card (20 pts)

Each player gives its minimum value card to the next player (the suit doesn’t matter) in the

following order:

Player 1 gives their minimum value card to player 2,


player 2 gives their minimum value card to player 3. The card selected must be among

the cards player 2 had prior to receiving player 1's min card.

player 3 gives their minimum value card to player 1. The card selected must be among

the cards player 3 had prior to receiving player 2's min card.

For example , suppose each player originally had the cards shown below:

Alexander the Great

Golds 8

Cups 3

Cups 10

Bismarck

Clubs 12

Golds 7

Cups 1

Charles V of Spain

Clubs 8

Golds 9

Swords 5

After selecting option e and option h again (to display the cards), the output of the

program should be the following:

Alexander the Great

Golds 8

Cups 10

Swords 5

Bismarck

Clubs 12

Golds 7

Cups 3

Charles V of Spain

Clubs 8

Golds 9

Cups 1

d: declare winner and quit(10 pts)

Calculate the total value of the cards in each player’s hand and then announce a winner.

Print the score of each player and then print the name of the winner, see example below:

Alexander the Great has 23 points.

Bismarck has 22 points.

Charles V of Spain has 18 points.

The winner is "Alexander the Great" with 23 points!

After printing the winner, quit the game.

q: quit (5 pts)

Quit the game

10 pts for commenting your code

5 pts for passing the autograded test on zylab

You must comment your code appropriately to clearly explain your solution. Include more

extensive comments for the parts that you found harder to code.


版权所有:编程辅导网 2018 All Rights Reserved 联系方式:QQ:99515681 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。