小游戏炒股
include<bits/stdc++.h>
include<windows.h>
include<conio.h>
using namespace std;
const int MAXN=6;
void setc(int a){ SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a); } void freeseed(){ unsigned int seed=time(0); srand(seed); } int random(int left,int right){ return rand()%(right-left+1)+left-1; } void hide(){ CONSOLE_CURSOR_INFO cursor_info = {1, 0}; SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info); } class company{ public: company(string name,int price,bool avai){ _name=name; _price=price; _bprice=10; _avai=avai; _exp=0.0; } string getname(){ return _name; } void setprice(int price){ int a=_price; _price=price; _bprice=a; _exp=(float)(_price-_bprice)/_bprice; test(); } int getprice(){ return _price; } void setexp(float a){//非必要不能用!!!!!!!! _exp=a; } float getexp(){ return _exp; } bool getavai(){ return _avai; } void changeexp(){ _exp=(_price-_bprice)/_bprice; } void test(){ if(_price<=0)_avai=0; } void render(){ setc(8);cout<<_name;setc(15); cout<<" \t"; setc(3);cout<<_price;setc(15); cout<<" \t"; if(_exp<0.0){ setc(4); cout<<fixed<<setprecision(2)<<_exp; } else{ setc(10); cout<<fixed<<setprecision(2)<<_exp; } setc(15);cout<<" \t"; if(_avai==1){ setc(10);cout<<"Yes"; } else{ setc(4);cout<<"No"; }
setc(15);//cout<<"\n\n";
}
private:
string _name;
int _price;
int _bprice;
float _exp;
bool _avai;
};
int main(){
freeseed();
const int MONEY=2500;
const int ROUND=15;
const int PAUSE=350;
const int ST1=random(60,140);
const int ST2=random(60,140);
const int ST3=random(60,140);
const int ST4=random(60,140);
const int ST5=random(60,140);
const int ST6=random(60,140);
const int BL1=1;
const int BL2=1;
const int BL3=1;
const int BL4=1;
const int BL5=1;
const int BL6=1;
//ADVANCED GAME SETTINGS
/const int MONEY=1000;
const int ROUND=10;
const int ST1=42;
const int ST2=78;
const int ST3=39;
const int ST4=50;
const int ST5=20;
const int BL1=1;
const int BL2=1;
const int BL3=1;
const int BL4=1;
const int BL5=1;/
const int EVENT_DOWN=4;
//P=C/50
const int EVENT_UP=47;
//P=(51-C)/50
system("color 0f");
hide();
//公司定义
company list0("成龙洗发水",ST1,BL1);
company list1("南山必胜客",ST2,BL2);
company list2("摆渡广告网",ST3,BL3);
company list3("呕象练习生",ST4,BL4);
company list4("老冯寄痰厂",ST5,BL5);
company list5("阿狸啸粑粑",ST6,BL6);
company list[MAXN]={list0,list1,list2,list3,list4,list5};
//基本变量定义
int money=MONEY;int borrow=0,inround=10;int wallet[MAXN]={0,0,0,0,0,0};
int round=ROUND,count,place;string in,in2;
//前言
cout<<"炒股\tv.1.1.0\n\n";
cout<<"玩法:1.输入buy买入 2.输入sell卖出 3.输入getmoney贷款(噶了i dont care)\n\n";
cout<<"温馨啸提示:股市有风险,开团需谨慎(bushi\n\n";
cout<<"按任意键开始游戏(不准按关机键!!)\n\n";
getch();
while(round){
system("cls");
//制表
if(round<=inround)borrow=0;
money-=borrow;
if(money<0){
goto end;
}
cout<<"还剩 "<<round<<" 回合 金钱 "<<money<<"\n\n";
if(borrow){
cout<<"每期还款 "<<borrow<<" 还剩 "<<round-inround<<" 期\n\n";
}
setc(8);cout<<"名称 \t \t股价 \t涨幅 \t可用 \t持有\n\n";setc(15);
Sleep(PAUSE);
//渲染模块
for(int i=0;i<=MAXN-1;i++){
list[i].render();
if(list[i].getavai()){
cout<<" \t"<<wallet[i]<<"\n\n";
}
else{
cout<<" \t"<<""<<"\n\n";
}
Sleep(PAUSE);
}
//输入初始化
in=" ";
//主模块
while(in!="end"){
loop:;
cin>>in;
//购买
if(in=="buy"){
cout<<"提示:输入票名和数量\n输入\"yes\"继续\n输入\"quit\"退出\n";
cin>>in2;
if(in2=="quit"){
goto loop;
}
if(in2=="yes"){
cin>>place>>count;
int ss=list[place-1].getprice()count;
if(ss<=money&&list[place-1].getavai()){
money-=ss;
cout<<"已购买 "<<list[place-1].getname()<<" "<<count<<"股\n";
cout<<"剩余金钱 "<<money<<"\n";
wallet[place-1]+=count;
}
else{
cout<<"错误\n";
}
}
}
//卖出
if(in=="sell"){
cout<<"提示:输入票名和数量\n输入\"yes\"继续\n输入\"quit\"退出\n";
cin>>in2;
if(in2=="quit"){
goto loop;
}
if(in2=="yes"){
cin>>place>>count;
int tt=list[place-1].getprice()count;
if(wallet[place-1]>=count&&list[place-1].getavai()){
money+=tt;
cout<<"已卖出 "<<list[place-1].getname()<<" "<<count<<"股\n";
cout<<"获得金钱 "<<tt<<'\n';
wallet[place-1]-=count;
}
else{
cout<<"错误\n";
goto loop;
}
}
}
if(in=="getmoney"){
if(borrow){
cout<<"错误:你不能在贷款还清前贷款\n";
}
if(round>=ROUND/2+1&&!borrow){
cout<<"提示:请输入贷款金额\n必须低于当前资产的一半\n";
cout<<"提示:输入\"yes\"继续\n输入\"quit\"退出\n";
cin>>in2;
if(in2=="yes"){
int much;
cin>>much;
if(much<=money/2){
money+=much;
borrow=(much+much/12)/(round/2);
}
else{
cout<<"贷款金额过大\n";
goto loop;
}
inround=round-(ROUND/2+1);
cout<<"贷款成功,金额 "<<much<<" 每期还款 "<<borrow<<"\n";
}
if(in2=="quit"){
goto loop;
}
}
if(round<ROUND/2+1&&!borrow){
cout<<"错误:你不能在 "<<ROUND/2+1<<" 回合后贷款\n";
}
}
//开发者命令
if(in=="cmd_makedis"){
cout<<"警告,你处于开发者模式\n输入\"yes\"启用\n";
cin>>in2;
if(in2=="yes"){
int shit_id;
cin>>shit_id;
list[shit_id-1].setprice(0);
cout<<"似乎有什么重要的事情发生力(喜)\n";
}
else{
goto loop;
}
}
/if(in=="cmd_addmoney"){
cout<<"警告,你处于开发者模式\n输入\"yes\"启用\n";
cin>>in2;
if(in2=="yes"){
int fff;
cin>>fff;
money+=1000;
cout<<"已增加金钱 "<<fff<<" \n";
cout<<"作弊可耻,作弊司马\n";
}
else{
goto loop;
}
}*/
}
//涨幅模块
freeseed();
for(int i=0;i<=MAXN-1;i++){
if(!list[i].getavai()){
list[i].setprice(0);
list[i].setexp(-1.0);
continue;
}
int ft=random(1,19);
ft-=10;
//大型涨跌
int bouns=random(1,50);
if(bouns>=1&&bouns<=EVENT_DOWN)bouns=-40;
if(bouns>=EVENT_UP&&bouns<=50)bouns=40;
if(bouns>=EVENT_DOWN+1&&bouns<=EVENT_UP-1)bouns=0;
list[i].setprice(list[i].getprice()+ft+bouns);
}
round--;
}
//结算
end:;
system("cls");
cout<<"GAME OVER\n\nSCORE "<<money<<endl;
if(money<0){
cout<<"人生格言:\"老子就不还钱,咋地?\"\n";
}
if(money<MONEY&&money>=0){
cout<<"人生格言:\"如果有来世,焯nm的股!\"\n";
}
if(money==MONEY){
cout<<"人生格言:\"炒了个寂寞。。。\"\n";
}
if(money>MONEY){
cout<<"人生格言:\"梭哈!梭哈!!梭哈!!!\"\n";
}
system("pause");
}