源代码
# include <bits/stdc++.h>
# include <stdlib.h>
# include <cstring>
# include <conio.h>
# include <time.h>
# include <random>
using namespace std;
int main()
{
default_random_engine e;
e.seed(time(0));
int c,w1_h=0,w1_b=0,w2_h=0,w2_b=0,h=50,bai=50;
char a,b;
label1:
system("cls");
cout<<"stardusts工作室";
cout<<"人猪游戏"<<endl;
cout<<"<0>介绍规则"<<endl
<<"<1>开始游戏";
a=getch();
if (a=='1')
{
while (h||bai)
{
system("cls");
cout<<"请投入棋子:"<<endl
<<"当前黑子:"<<h<<endl
<<"当前白子:"<<bai<<endl
<<"碗一信息:"<<endl
<<" 黑子:"<<w1_h<<endl
<<" 白子:"<<w1_b<<endl
<<"碗二信息:"<<endl
<<" 黑子:"<<w2_h<<endl
<<" 白子:"<<w2_b<<endl
<<"向哪个碗投子:<1>碗一 <2>碗二"<<endl;
a=getch();
cout<<"投黑子 白子: <1>黑子 <2>白子"<<endl;
b=getch();
cout<<"投子数量: <Enter>结束输入"<<endl;
cin>>c;
if ((b=='1'&&c>h)||(b=='2'&&c>bai))
{
cout<<"投子失败,数量不够"<<endl
<<"<任意键>继续";
a=getch();
continue;
}
if (a=='1')
{
if (b=='1')
{
w1_h+=c;
h-=c;
}
else
{
w1_b+=c;
bai-=c;
}
}
else
{
if (b=='1')
{
w2_h+=c;
h-=c;
}
else
{
w2_b+=c;
bai-=c;
}
}
}
system("cls");
cout<<"投子结束"<<endl
<<"人猪正在交换碗的位置"<<endl;
sleep(1);
system("cls");
cout<<3;
sleep(1);
system("cls");
cout<<2;
sleep(1);
system("cls");
cout<<1;
sleep(1);
system("cls");
cout<<"请选择:<1>左侧 <2>右侧";
a=getch();
int sj=e()%2;
system("cls");
cout<<"你抽到了碗"<<sj+1;
if (!sj)
{
int z=e()%(w1_h+w1_b);
if (z<=w1_h)
cout<<"中的黑子,你赢了";
else
cout<<"中的白子,你输了";
cout<<endl;
double gl=(w1_h*1.0/(w1_h+w1_b))*100;
cout<<"你抽到了碗"<<sj+1<<endl
<<"在这个碗中:"<<endl
<<"黑子:"<<w1_h<<"颗"<<endl
<<"白子:"<<w1_b<<"颗"<<endl
<<"赢的概率为"<<gl<<"%"<<endl;
return 0;
}
else
{
int z=e()%(w2_h+w2_b);
if (z<=w2_h)
cout<<"中的黑子,你赢了";
else
cout<<"中的白子,你输了";
cout<<endl;
double gl=(w2_h*1.0/(w2_h+w2_b))*100;
cout<<"在这个碗中:"<<endl
<<"黑子:"<<w2_h<<"颗"<<endl
<<"白子:"<<w2_b<<"颗"<<endl
<<"赢的概率为"<<gl<<"%"<<endl
<<"<任意键>结束";
choose=getch();
return 0;
}
}
else
{
system("cls");
cout<<"一共有两个碗,50粒黑子棋,50粒白子棋"<<endl
<<"玩家需要选定任意数量的任意颜色的棋子放入任意一个碗中,直至放完"<<endl
<<"前提:选定棋子数量不得超过未放入碗中的同颜色棋子"<<endl
<<"游戏开始后,你将被蒙住眼睛,人猪可调换碗的摆放顺序,但不会改变棋子摆放"<<endl
<<"你将选择一个碗,并拿起碗中的一颗棋子,如果该棋子为黑子,你赢,否则相反"<<endl
<<"<任意键>回到主界面";
a=getch();
goto label1;
}
return 0;
}
Tip
作者原创,严禁抄袭,请勿擅自修改程序!!!转载请声明原作者!!!