一个C++的21点(BlackJack)游戏

#ifndef POKER_H_
#define POKER_H_

//suits: Games Any of the four sets of 13 playing cards
//(clubs, diamonds, hearts, and spades) in a standard deck,
//the members of which bear the same marks.
//红桃 : H - Heart 桃心(象形), 代表爱情
//黑桃 : S - Spade 橄榄叶(象形), 代表和平
//方块 : D - Diamond 钻石(形同意合), 代表财富
//梅花 : C - Club 三叶草(象形), 代表幸运

#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
#include <cctype>

using namespace std;

struct Card
{
	string mark;
	string point;
};

class Poker
{
public:
	const string Mark[4] = { "红桃", "黑桃", "方块", "梅花" };
	const string Point[13] = { "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" };

private:
	Card card[52];
	static int num;

public:
	Poker();

	void randomPoker();
	Card& dealPoker();
};

#endif

#include "poker.h"

int Poker::num = 0;

Poker::Poker()
{
	for (int i = 0; i < 52; i++)
	{
		card[i].mark = Mark[i % 4];
		card[i].point = Point[i % 13];
	}
}

void Poker::randomPoker()
{
	srand((unsigned int)time(0));

	for (int i = 0; i < 52; i++)
	{
		Card temp;
		temp = card[i];

		int r = rand() % 52;

		card[i] = card[r];
		card[r] = temp;
	}
}

Card& Poker::dealPoker()
{
	if (num < 52)
		return card[num++];
	else
		cout << "No more cards!\n";
	exit(EXIT_FAILURE);
}

#include "poker.h"

void showBl
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值