• 大小: 11KB
    文件类型: .cpp
    金币: 2
    下载: 0 次
    发布日期: 2024-02-08
  • 语言: C/C++
  • 标签:

资源简介

课程设计小程序,扑克牌游戏,c++实现,简单易懂,适用于初学者

资源截图

代码片段和文件信息

#include 
#include 
#include 
#include 
#include 
#include 

class Playing_Card //扑克牌类,表示一张扑克牌的面值花色和与之相联系的操作   
{
private:
int m_Value; //扑克的实际面值,用整型值表示,从1开始,1~13
char m_Face[3]; //扑克的数字大小,用字符串的形式表示,为A2345678910JQK
char m_Suit ;   //扑克的花色(黑红梅方)
public:
Playing_Card(); //构造函数,初始化扑克牌对象,实际上是将对象清零
void showcard(); //显示扑克牌对象的面值,花色
void Card_Make(int); //为一张扑克牌对象赋予特定的面值及花色
};

class Deck  //一副扑克(54张)类
{
private:
Playing_Card m_cardarray[54]; //一副扑克由54张扑克牌组成
int m_lastdelt; //标记这副扑克牌删除的张数
public:
Deck(); //构造函数,初始化一副扑克牌对象,实际上是将其内的54张牌清零
void MakeDeck() ;//生成一副扑克,即对其内的54张扑克牌赋予正确的面值及花色
void Deal_One();//任意删除一张牌
void ShowDeck();//依次逐张显示这副牌
void DeckShuff(int);//洗牌,其参数是洗牌的次数
void Remove_Card();//将删除的那张牌的内容清零,使这张牌在屏幕上显示不出来
void Senddeck();
};

void Program_Init();//程序初始化,输出初始化信息
int main();
void Center_Text(char []);//将参数(字符串)在屏幕上显示在一行的中间位置
int get_number();//接收用户键入的整型数值,作为函数值返回
char Get_Key(); //接收用户键入的字符,作为函数值返回
void DeckMakeDriver(); //程序的主要算法,内部调用多个函数,包括生成扑克牌,洗牌,删除等主要操作
int getRandInt(int min int max);//取得在两个参数之间的整型随机值     
void prog_close();//暂停程序运行,供用户查看中间运行结果

int main()
{

srand( (unsigned)time( NULL ) );//初始化随机数种子      
int Card_Number = 0;
        Program_Init(); //显示程序初始化提示信息      
DeckMakeDriver();//调用程序的主要算法,包括程序的主要操作过程
prog_close();//暂停程序运行,供用户查看运行结果
return 1;
}

Playing_Card::Playing_Card()//扑克牌对象的构造函数     

{
int i;
for(i=1;i<=3;) //初始化扑克牌的面值,清零
{
m_Face[i] = ‘ ‘;
i++;
}
m_Suit = ‘ ‘;//初始化扑克牌的花色,清零
m_Value = 0;
}

void Program_Init()//程序一开始运行的提示信息
{
Center_Text(“CXSOFT“);
cout << endl;
Center_Text(“扑克牌游戏“);
cout << endl <<“\n“ ; 
Center_Text(“制作:-----周微“);
   cout << endl <<“\n“ ;
Center_Text(“(C) 2005 周微“);
cout << endl <<“\n“ ;
Center_Text(“点击<回车>键继续..“);
cin.get();
}

char Get_Key()//从键盘接收一个字符,将其作为函数值返回
{
char x;
x = cin.get();
cout << endl;
return x;
}

void Playing_Card::showcard()//在屏幕上显示一张扑克牌的面值及花色
{
cout << “   “;
cout << m_Face;//显示面值
cout.width(1);
cout <<  m_Suit;//显示花色
cout << “ “;

}

void Center_Text(char ShellText[80])//将参数(字符串)在屏幕上居中显示
{
int length;
int center;
length= strlen(ShellText);//取得欲显示字符串的大小
center = (80 - length)/2;//整个屏幕的列数为80,取得字符串在该行的起始位置
for(;center!=0;center--)//在字符串前输出空格
{
cputs(“ “);
}
cputs(ShellText);
}
 
int get_number()//从键盘接收一个整型数值,将其作为函数值返回
{
int Input_Integer = 0;
Center_Text(“Please enter an integer between 0 and 53. 54to quit.“);
cout << endl;
cin >> Input_Integer;
return Input_Integer;
}



void Playing_Card::Card_Make(int num)//根据参数num生成一张扑克牌,num不同,生成的面值及花色不同
{

int i = 0;
char j;
if(num==53)
{
strcpy(m_Face“jo“);
m_Suit=‘2‘;
m_Value=15;
}
if(num==52)
{
strcpy(m_Face

评论

共有 条评论

相关资源