Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2341578
  • 博文数量: 816
  • 博客积分: 10000
  • 博客等级: 上将
  • 技术积分: 5010
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-17 17:57
文章分类

全部博文(816)

文章存档

2011年(1)

2008年(815)

分类:

2008-12-17 18:06:11

大概就是21点比大小的游戏,1:开始发两张牌,如果超过21点就输.2:A做11点,头像牌都做10点,别的不变.3:一样大时再各发一张牌比大小,大的赢.4:看下面运行的事例吧

Playing the Ace-High Game
Problem
You have been tasked to develop a computer program that can play Ace-High, a card game similar to, but simpler than, blackjack. The rules and procedures are as follows.

1. Cards have their standard values (a numerical card has its numerical value in the range of two to ten and face cards all have a value of ten), except that aces always have a value of eleven. To make the game simpler, the drawing of a card will be simulated by a function that will return an integer value in the range of 2 through 11, inclusive.

2. The program begins by printing a suitable welcome message (see example).
3. The player always draws first and always draws two cards initially. If the player "busts," that is, if the combined value of the player's two cards exceeds 21, then the player loses, the dealer does not draw, and the game is over.

4. The dealer draws second. The dealer draws two cards initially. If the total of the two cards is less than 17, the dealer then "hits" (draws another card) until the total of her or his cards is greater than or equal to 17. If the dealer busts at any time (from the first two cards or as a result of drawing more cards), then the player wins and the game is over

5. If at this point the dealer and player are tied, this forces a playoff in which both the dealer and player each draw a single card. If the dealer's card is higher, the dealer wins; if the player's card is higher, the player wins. If the dealer's and player's cards are equal, then the playoff is repeated (i.e., each draws another card) until either the dealer or player wins.

6. The program displays as much of this information as is pertinent to the hand:
o The value of each of the player's initial two cards and their total value;
o The value of each of the dealer's initial two cards and their total value;
o The value of the player's card(s) during a playoff;  
o The value of the dealer's card(s) during a playoff;
o A statement declaring whether the player or dealer is the winner.

7. After the winner has been determined, the program asks if another game should be played. An answer of "y" or "Y" starts another game; any other answer terminates the game.

Example run
WELCOME TO THE ACE-HIGH GAME
Player draws 11 and 11, total 22.
Dealer wins.
Play again (y or n)? y
WELCOME TO THE ACE-HIGH GAME
Player draws 8 and 10, total 18.
Dealer draws 9 and 11, total 20.
Dealer wins.
Play again (y or n)? y
WELCOME TO THE ACE-HIGH GAME
Player draws 7 and 4, total 11.
Dealer draws 5 and 9, total 16.
Dealer draws 2, total 18.
Dealer wins.
Play again (y or n)? y
WELCOME TO THE ACE-HIGH GAME
Player draws 10 and 10, total 20.
Dealer draws 5 and 6, total 11.
Dealer draws 5 and 9, total 25.
Player wins.
Play again (y or n)? y
WELCOME TO THE ACE-HIGH GAME
Player draws 8 and 9, total 17.
Dealer draws 10 and 7, total 17.
Player draws 9.
Dealer draws 7.
Player wins.
Play again (y or n)? y
WELCOME TO THE ACE-HIGH GAME
Player draws 9 and 10, total 19.
Dealer draws 11 and 2, total 13.
Dealer draws 2, total 15.
Dealer draws 4, total 19.
Player draws 5.
Dealer draws 10.
Dealer wins.
Play again (y or n)? x
Game ended at player's request.
Notes
In the program shell, there is a function named get_card() that will return a value in the range of 2 to 11 each time it is called. To use this function, store its value into an integer value like this:
int my_card;
//  my_card will be assigned a value in the range 2 to 11
my_card = get_card();
The program shell shows you where to place your programming with respect to the get_card() function.
Submissions
When your program is finished, name the source PD1(Name&No).cpp


--------------------next---------------------
自己编了,就是运行不出来,有一个错误,哪位高手帮我改下,先谢了!!!

//程序:ace.hpp
//功能:21点游戏类头文件

//类名:ACE_HIGH_GAME
//功能:实现一个21点扑克牌游戏
class ACE_HIGH_GAME{
public:
 int get_card();

private:
 int get_card;
};



//程序:ace.cpp
//功能:21点游戏类实现文件。

#include"ace.hpp"
#include

//随机取得一张扑克牌,并得到其点数。
int ACE_HIGH_GAME::get_card()
{
 get_card=rand(2,11);
 return get_card;
}




#include"ace.hpp"
#include

void main()
{
  int p_card, p_card1, p_card2;
  int d_card, d_card1, d_card2, d_card3;
  char choice;

 do {
   cout<<"WELCOME TO THE ACE-HIGH GAME!\n";

   p_card1=get_card();
   p_card2=get_card();
   p_card=p_card1+p_card2;
   cout<<"Player draws "<     
      if(p_card>21){
    cout<<"Dealer wins.\n";
   }else{
       d_card1=get_card();
       d_card2=get_card();
       d_card=d_card1+d_card2;
       cout<<"Dealer draws "<
          while(d_card<17){
        d_card3=get_card();
        d_card=d_card+d_card3;
              cout<<"Dealer draws "<    }
       
       if(d_card>21){
        cout<<"Player wins.\n";
    }else{
           while(d_card=p_card){
            p_card=get_card();
            d_card=get_card();
            cout<<"Player draws "<            cout<<"Dealer draws "<     }

           if(d_card            cout<<"Player wins.\n";
     }else{
            cout<<"Dealer wins.\n";
     }
          }

   }

       cout<<"Do you want to play again (y or n)?\n";
       cin>>choice;

 
  } while(choice='y'||'Y');

   cout<<"Game over! It is player's request.\n";
}




错误如下:

--------------------Configuration: ace - Win32 Debug--------------------
Compiling...
ace001.cpp
e:\作业\c++程序课程设计题目\新建文件夹\ace.hpp(11) : error C2373: 'get_card' : redefinition; different type modifiers
        e:\作业\c++程序课程设计题目\新建文件夹\ace.hpp(8) : see declaration of 'get_card'
e:\作业\c++程序课程设计题目\新建文件夹\ace001.cpp(16) : error C2065: 'get_card' : undeclared identifier
执行 cl.exe 时出错.

ace001.obj - 1 error(s), 0 warning(s)



--------------------next---------------------

阅读(1192) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~