zoukankan      html  css  js  c++  java
  • [h5棋牌项目]-13-红包扫雷随机红包金额算法

    .h部分代码

    //红包结构体
    struct tagRedPacket {
    	tagRedPacket() { ReSet(); }
    	void ReSet() { ZeroMemory(this, sizeof(tagRedPacket)); }
    	LONGLONG		 lTime;									//发红包的时间
    	WORD			 wId;									//红包id
    	DWORD			 dwUserId;								//发红包的用户id
    	DWORD			 dwCellScore;							//红包金额
    	BYTE			 cbRay;									//雷
    	DWORD			 dwRayCompensation;						//中雷赔偿金额
    	BYTE			 cbRayCount;							//中雷次数
    	BYTE			 cbTimeOut;								//过期标识 
    	BYTE			 cbCount;								//红包数量
    	CMD_S_PlayerInfo PlayerInfo;							//玩家信息
    	tagOpenRedPacket wRedPacketUser[MAX_STATISTICAL_RED_PACKET];//开红包数组 
    }; 
    
    class RedPacketMgr
    {
    	tagRedPacket * GetRedPacket(WORD wId);
    	void RandRedPacket(int count);
    	float  GetRandRedPacket(int index);
    	
    	float m_RedPacketUser[MAX_STATISTICAL_RED_PACKET];			//红包比例
    	std::map<WORD, tagRedPacket*> m_RedPacketMgr;
    }

    .cpp部分代码

    tagRedPacket * RedPacketMgr::GetRedPacket(WORD wId)
    {
    	if(m_RedPacketMgr.find(wId) == m_RedPacketMgr.end())
    		return NULL;
    	if(m_RedPacketMgr[wId]->cbTimeOut){
    		return NULL;
    	}
    	return m_RedPacketMgr[wId];
    }
    
    void RedPacketMgr::RandRedPacket(int count)
    {	
    	if (count < 1 ||MAX_STATISTICAL_RED_PACKET < count)
    		return;
    	float nAll = 0.0f;
    	int max = 50;
    	for (int i = 0; i < count; i++) {
    		m_RedPacketUser[i] = rand() % max + 10;
    		nAll += m_RedPacketUser[i];
    	}
    	for (int i = 0; i < count; i++) {
    		m_RedPacketUser[i] = m_RedPacketUser[i] / nAll;
    	}
    }
    
    float  RedPacketMgr::GetRandRedPacket(int index)
    {
    	if (index < 0 || MAX_STATISTICAL_RED_PACKET <= index)
    		return 0.1;
    	return m_RedPacketUser[index];
    }

    应用

    RedPacketMgr	m_RedPacketMgr;							//红包管理
    tagRedPacket* pRedPacket = m_RedPacketMgr.GetRedPacket(wId);
    wRedPacket = pRedPacket->dwCellScore * m_RedPacketMgr.GetRandRedPacket(bCount);
  • 相关阅读:
    Merge Intervals
    Jump Game
    微信小程序----button组件
    微信小程序----日期时间选择器(自定义精确到分秒或时段)(MUI日期时间)
    禁止搜索引擎抓取robots.txt文件设置方法
    [转载]【转】代码的版权声明怎么写
    微信小程序----picker选择器(picker、省市区选择器)(MUI选择器)
    微信小程序----模板(template)
    nginx安全配置
    微信小程序----icon组件
  • 原文地址:https://www.cnblogs.com/byfei/p/14104141.html
Copyright © 2011-2022 走看看