⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 caculate.cpp

📁 一个随机抽人的小游戏,可以随即输入无穷多个人名,点击则随机抽出一个
💻 CPP
字号:
#include "stdafx.h"
#include "Caculate.h"

CCaculate::CCaculate()
{
	m_nListSize = 0;
}

CCaculate::CCaculate(const CCaculate& oOther)
{
	if (this == &oOther)
		return;
	else
	{
		m_nListSize = oOther.m_nListSize;
		m_vNameList = oOther.m_vNameList;
	}
}

CCaculate::~CCaculate()
{

}

int CCaculate::LuckClick(CString& strLuck)
{
	int nIdx = 0;
	if (m_nListSize > 0)
	{
		nIdx = rand() % m_nListSize;
		m_nListSize--;
	}
	else
	{
		return 0;
	}
	vector<CString>::iterator iPos;
	iPos = m_vNameList.begin();
	int i = 0;
	while (i < nIdx)
	{
		iPos++;
		i++;
	}
	strLuck = (*iPos);
	iPos = m_vNameList.erase(iPos);
	return nIdx;
}

int CCaculate::AddName(CString strName)
{
	if (!strName.IsEmpty())
	{
		m_vNameList.push_back(strName);
		m_nListSize++;
		return 1;          
	}
	else
	{
		return 0;
	}
}

int CCaculate::GetListSize()
{
	return m_nListSize;
}

void CCaculate::GetNameList(vector<CString>& vNameList) const
{
	vNameList = m_vNameList;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -