幸运转盘C

#pragma once
#include "stdafx.h"
#include "json/json.h"
// #include "json\writer.h"
// #include "json\reader.h"
using namespace std;
typedef struct
{
int Id;
int Rmb;
string Name;
string Explain;
}Item;
class Config
{
private:
int mId;
int mRmb;
string mName;
string mExplain;
map<int, Item>m_ItemType;
public:
//单例模式;
void readJson();
void saveItem();
map<int, Item>getItemType();
static Config * getInstance();
/*void update();*/
Config(void);
~Config(void);
};#include "stdafx.h"
#include "Config.h"
#include <fstream>




static Config *game = NULL;

Config::Config(void)
{
readJson();
}


Config::~Config(void)
{
}

Config * Config::getInstance()
{
if (game == NULL)
{
game = new Config();
}
return game;
}

map<int, Item> Config::getItemType()
{
return m_ItemType;
}

void Config::readJson()
{
Json::Value root;
Json::Value itemdatas;
Json::Reader reader;
//读取文件;
ifstream is;
is.open("jiangping.json",ios::binary);
if (reader.parse(is,root))
{
itemdatas = root["datas"];
for (int i=0;i<itemdatas.size();++i)
{
Item item;
int id = itemdatas[i]["id"].asInt();
item.Id = id;
item.Rmb = itemdatas[i]["rmb"].asInt();
item.Name =itemdatas[i]["name"].asString();
item.Explain = itemdatas[i]["explain"].asString();
m_ItemType.insert(map<int,Item>::value_type(id,item));
}
}
is.close();
}
// TheLuckyRoller.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include "Config.h"
#include <map>
int _tmain(int argc, _TCHAR* argv[])
{
map<int,Item>Items=Config::getInstance()->getItemType();
// for (map<int,Item>::iterator it = Items.begin();it !=Items.end();++it)
// {
// it->first;
//
// }
cout<<"1等奖是苹果哦,4等奖是神秘物品祝你好运;"<<endl;
cout<<"摇奖1开始!!!其他结束;"<<endl;
while (1)
{
int index1,cindex;
cin>>cindex;
index1=cindex;
if(index1<=1)
{
srand((int)time(NULL));
int index = rand()%10+1;

map<int,Item>::iterator it = Items.find(index);
if (it !=Items.end())
{
cout<<"恭喜您中奖了奖品为;"<<endl;
cout<<"ID"<<Items[index].Id<<endl;
cout<<"名称;"<<Items[index].Name<<endl;
cout<<"价格;"<<Items[index].Rmb<<endl;
cout<<"说明;"<<Items[index].Explain<<endl;
break;
}
else if(index>=4)
{
cout<<"你没用好中奖;"<<index<<endl;
break;
}
}
}



system("pause");
return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值