前言
我看许多人用小海龟来做博饼,于是,我掏出了C++。
(一股强劲的音乐响起)
C++,启动!
画图
C++不像小海龟能随意地飘来飘去,只能用字符来画骰子。
void S(int ForgC, int BackC) {
WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor);
}
void func(int x){
if(x==1){
cout<<"--------"<<endl;
cout<<"| |"<<endl;
cout<<"| ";
S(12,0);
cout<<"●";
S(15,0);
cout<<" |"<<endl;
cout<<"| |"<<endl;
cout<<"--------"<<endl;
}
if(x==2){
cout<<"--------"<<endl;
cout<<"| ";
S(9,0);
cout<<"●";
S(15,0);
cout<<" |"<<endl;
cout<<"| |"<<endl;
cout<<"| ";
S(9,0);
cout<<"●";
S(15,0);
cout<<" |"<<endl;
cout<<"--------"<<endl;
}
if(x==3){
cout<<"--------"<<endl;
cout<<"|";
S(9,0);
cout<<"●";
S(15,0);
cout<<" |"<<endl;
cout<<"| ";
S(9,0);
cout<<"●";
S(15,0);
cout<<" |"<<endl;
cout<<"| ";
S(9,0);
cout<<"●";
S(15,0);
cout<<"|"<<endl;
cout<<"--------"<<endl;
}
if(x==4){
cout<<"--------"<<endl;
cout<<"|";
S(12,0);
cout<<"● ●";
S(15,0);
cout<<"|"<<endl;
cout<<"| |"<<endl;
cout<<"|";
S(12,0);
cout<<"● ●";
S(15,0);
cout<<"|"<<endl;
cout<<"--------"<<endl;
}
if(x==5){
cout<<"--------"<<endl;
cout<<"|";
S(9,0);
cout<<"● ●";
S(15,0);
cout<<"|"<<endl;
cout<<"| ";
S(9,0);
cout<<"●";
S(15,0);
cout<<" |"<<endl;
cout<<"|";
S(9,0);
cout<<"● ●";
S(15,0);
cout<<"|"<<endl;
cout<<"--------"<<endl;
}
if(x==6){
cout<<"--------"<<endl;
cout<<"|";
S(9,0);
cout<<"● ●";
S(15,0);
cout<<"|"<<endl;
cout<<"|";
S(9,0);
cout<<"● ●";
S(15,0);
cout<<"|"<<endl;
cout<<"|";
S(9,0);
cout<<"● ●";
S(15,0);
cout<<"|"<<endl;
cout<<"--------"<<endl;
}
}
其中,S为颜色函数,负责调整颜色。
main函数
博饼讲究随机,随机数不能少。
srand(time(NULL));
随后每输入一次,就随机出6个骰子(突发恶疾)
再简简单单判断一下是神么
cout<<"输入任何符号抽取"<<endl;
cin>>c;
system("cls");
for(int i=1;i<=6;i++){
a[i]=rand()%6+1;
func(a[i]);
b[i]=0;
Sleep(15);
}
for(int i=1;i<=6;i++)b[a[i]]++;
if(b[4]==4&&b[1]==2){
S(14,0);
cout<<"★插金花★"<<endl;
S(15,0);
Sleep(300);
}else if(b[4]==6){
S(14,0);
cout<<"★红六勃★"<<endl;
S(15,0);
Sleep(300);
}else if(b[1]==6){
S(14,0);
cout<<"★遍地锦★"<<endl;
S(15,0);
Sleep(300);
}else if(b[2]==6||b[3]==6||b[5]==6||b[6]==6){
S(14,0);
cout<<"★黑六勃★"<<endl;
S(15,0);
Sleep(300);
}else if(b[4]==5){
S(14,0);
cout<<" ★五红★"<<endl;
S(15,0);
Sleep(200);
}else if(b[1]==5||b[2]==5||b[3]==5||b[5]==5||b[6]==5){
S(14,0);
cout<<"★五子登科★"<<endl;
S(15,0);
Sleep(300);
}else if(b[4]==4){
S(14,0);
cout<<" ★四红★"<<endl;
S(15,0);
Sleep(300);
}else if(b[1]==1&&b[2]==1&&b[3]==1&&b[4]==1&&b[5]==1&&b[6]==1){
S(14,0);
cout<<"对堂"<<endl;
S(15,0);
Sleep(200);
}else if(b[4]==3){
cout<<"三红"<<endl;
S(15,0);
}else if(b[1]==4||b[2]==4||b[3]==4||b[5]==4||b[6]==4){
cout<<"四进"<<endl;
S(15,0);
}else if(b[4]==2){
cout<<"二举"<<endl;
S(15,0);
}else if(b[4]==1){
cout<<"一秀"<<endl;
S(15,0);
}else{
cout<<"无"<<endl;
S(15,0);
}
总代码
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int a[7],b[7];
char c;
void S(int ForgC, int BackC) {
WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor);
}
void func(int x){
if(x==1){
cout<<"--------"<<endl;
cout<<"| |"<<endl;
cout<<"| ";
S(12,0);
cout<<"●";
S(15,0);
cout<<" |"<<endl;
cout<<"| |"<<endl;
cout<<"--------"<<endl;
}
if(x==2){
cout<<"--------"<<endl;
cout<<"| ";
S(9,0);
cout<<"●";
S(15,0);
cout<<" |"<<endl;
cout<<"| |"<<endl;
cout<<"| ";
S(9,0);
cout<<"●";
S(15,0);
cout<<" |"<<endl;
cout<<"--------"<<endl;
}
if(x==3){
cout<<"--------"<<endl;
cout<<"|";
S(9,0);
cout<<"●";
S(15,0);
cout<<" |"<<endl;
cout<<"| ";
S(9,0);
cout<<"●";
S(15,0);
cout<<" |"<<endl;
cout<<"| ";
S(9,0);
cout<<"●";
S(15,0);
cout<<"|"<<endl;
cout<<"--------"<<endl;
}
if(x==4){
cout<<"--------"<<endl;
cout<<"|";
S(12,0);
cout<<"● ●";
S(15,0);
cout<<"|"<<endl;
cout<<"| |"<<endl;
cout<<"|";
S(12,0);
cout<<"● ●";
S(15,0);
cout<<"|"<<endl;
cout<<"--------"<<endl;
}
if(x==5){
cout<<"--------"<<endl;
cout<<"|";
S(9,0);
cout<<"● ●";
S(15,0);
cout<<"|"<<endl;
cout<<"| ";
S(9,0);
cout<<"●";
S(15,0);
cout<<" |"<<endl;
cout<<"|";
S(9,0);
cout<<"● ●";
S(15,0);
cout<<"|"<<endl;
cout<<"--------"<<endl;
}
if(x==6){
cout<<"--------"<<endl;
cout<<"|";
S(9,0);
cout<<"● ●";
S(15,0);
cout<<"|"<<endl;
cout<<"|";
S(9,0);
cout<<"● ●";
S(15,0);
cout<<"|"<<endl;
cout<<"|";
S(9,0);
cout<<"● ●";
S(15,0);
cout<<"|"<<endl;
cout<<"--------"<<endl;
}
}
int main(){
srand(time(NULL));
cout<<"食用前请开全屏~"<<endl;
Sleep(2500);
system("cls");
while(true){
cout<<"输入任何符号抽取"<<endl;
cin>>c;
system("cls");
for(int i=1;i<=6;i++){
a[i]=rand()%6+1;
func(a[i]);
b[i]=0;
Sleep(15);
}
for(int i=1;i<=6;i++)b[a[i]]++;
if(b[4]==4&&b[1]==2){
S(14,0);
cout<<"★插金花★"<<endl;
S(15,0);
Sleep(300);
}else if(b[4]==6){
S(14,0);
cout<<"★红六勃★"<<endl;
S(15,0);
Sleep(300);
}else if(b[1]==6){
S(14,0);
cout<<"★遍地锦★"<<endl;
S(15,0);
Sleep(300);
}else if(b[2]==6||b[3]==6||b[5]==6||b[6]==6){
S(14,0);
cout<<"★黑六勃★"<<endl;
S(15,0);
Sleep(300);
}else if(b[4]==5){
S(14,0);
cout<<" ★五红★"<<endl;
S(15,0);
Sleep(200);
}else if(b[1]==5||b[2]==5||b[3]==5||b[5]==5||b[6]==5){
S(14,0);
cout<<"★五子登科★"<<endl;
S(15,0);
Sleep(300);
}else if(b[4]==4){
S(14,0);
cout<<" ★四红★"<<endl;
S(15,0);
Sleep(300);
}else if(b[1]==1&&b[2]==1&&b[3]==1&&b[4]==1&&b[5]==1&&b[6]==1){
S(14,0);
cout<<"对堂"<<endl;
S(15,0);
Sleep(200);
}else if(b[4]==3){
cout<<"三红"<<endl;
S(15,0);
}else if(b[1]==4||b[2]==4||b[3]==4||b[5]==4||b[6]==4){
cout<<"四进"<<endl;
S(15,0);
}else if(b[4]==2){
cout<<"二举"<<endl;
S(15,0);
}else if(b[4]==1){
cout<<"一秀"<<endl;
S(15,0);
}else{
cout<<"无"<<endl;
S(15,0);
}
}
return 0;
}
球球点个赞吧!