1 Replies - 7392 Views - Last Post: 20 March 2007 - 08:14 PM Rate Topic: -----

#1 johnchan8888  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 20-March 07

Write a card game with Visual C++

Posted 20 March 2007 - 09:19 AM

Dear all, i'm a beginner on C++, and upcoming i want to write a program with a card game by visual C++.
But I have some problem on it that i can't solve,

1- How can I compare the cards ?
2-How can I generate the cards randomly?

Would anybody give me some idea on it ?... I just want some suggestion on it, because i always think with a problem on the probability about the random cards .

Thanks!



By using Microsoft Visual Studio 2005, write a C++ object-oriented program to implement the game Get the Cards. At the beginning of the game, a stack of 52 cards is prepared and shuffled randomly. However, your program needs to make a special arrangement that, at 10 randomly chosen locations in the stack, two consecutive cards will have the same number. When the player starts to play the game, the cards in the stack are shown one by one for a short period of time. If the player finds those two consecutive cards having the same number, he/she should click the picture “Pick It” within a short period of time. A successful “Pick It” should be recorded. However, the “Pick It” picture may move from one position to another from time to time. Hence the player should find the picture when he/she wants to click it. The game will end when all cards are shown. For this game, the player can choose different levels of difficulty by adjusting the duration for showing a card. Different levels of difficulty will have different amount of scores. Hence besides the number of cards obtained, the scores of a player obtained should also be recorded.

1. Your program needs to be designed with a graphical user interface.

2. While you are responsible for the final design of the program, it is required that the rules of the game should be implemented with a separated static library and included into the managed C++ codes.

3. Before a user starts to play, he needs to login the system first. A file is then created to store the result of this user when playing the game. If this user has played this game before, his/her record should be retrieved and shown on the screen. After he/she plays the game, his/her record should then be modified and stored.

4. Should you want to get a credit, you should design the game with some advanced features. For instance, the position that the cards are shown at each time can be different. Besides, the player can also pick a card that is one point bigger or smaller in number than its previous card. For this mode, you need to prepare in your stack another 10 randomly chosen locations such that two consecutive cards will have a one-point difference in number.

5. Should you want to get a distinction, you are free to add more rules to the game that will make it to be more interesting. You may seek the opinion of your subject lecturer/tutor before you do so.

Is This A Good Question/Topic? 0
  • +

Replies To: Write a card game with Visual C++

#2 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Write a card game with Visual C++

Posted 20 March 2007 - 08:14 PM

Both of your questions are answered when you decide how you will store the cards in memory. One could assign each one a value between 1 and 13, and then a seperate suit value 1-4, one might just assign each card a value from 1 to 52 and use integer division (by 13) to get the suit and modulus 13 to get the card value. This latter version seems attactive to me since it would make shuffeling the deck easy using the rand() as well as comparisions easy.

Having never written a card game myself I can off no words of wisdom on what is the best way, but whatever way you choose will determine the answers to your questions.

The tutorial and snippet sections have good material on how to generate randome values, and I think one of them even deals with shuffeling.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1