首先定义一个 BasicCard类用于存放单张扑克牌,扑克牌中有三个属性,“花色”,“数字”,“是否被选为手牌”;考虑到“是否手牌”这个选项会在其他类里面判断,所以,暂时讲其设置为public属性。
这是BasicCard.h文件
#pragma once
#include <string>
using namespace std;
/*
定义单张卡牌
*/
class BasicCard
{
private:
//花色
string decors = "";
//数字
string number = "";
//此卡牌是否手牌
public:
bool isChoosen = false;
//存入卡牌
bool set_card(string decors, string number);
//将卡牌改为手牌
bool get_card();
//展示(打印)卡牌
void view_card();
BasicCard(string decors, string number);
~BasicCard();
};
这是对BasicCard.h的具体实现,BasicCard.cpp
#include "BasicCard.h"
#include <iostream>
using namespace std;
//存入卡牌
bool BasicCard::set_card(string decors, string number)
{
try
{
this->decors = decors;
this->number = number;
}
catch (exception& e)
{
cout << "Standard exception: " << e.what() << endl;
}
return true;
}
//将卡牌改为手牌
bool BasicCard::get_card()
{
try
{
this->isChoosen = true;
}
catch (exception& e)
{
cout << "Standard exception: " << e.what() << endl;
}
return true;
}
//展示(打印)卡牌
void BasicCard::view_card()
{
cout << this->decors << this->number << "\t";
}
BasicCard::BasicCard(string decors, string number)
{
set_card(decors, number);
}
BasicCard::~BasicCard()
{
}