扑克牌游戏01 BasicCard类

首先定义一个 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()
{
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值