C++出现葺 葺 葺葺 葺 葺

qq_38372518 2017-11-11 11:10:04
要求编写一个简单梭哈游戏。
执行后所有的牌都是葺 葺 葺葺 葺 葺葺 葺 葺葺 葺 葺葺 葺 葺葺 葺 葺;请教错误究竟出在哪里。
#include <iostream>
#include <conio.h>
#include <string>
#include <cstdlib>
using namespace std;
#define random(x)(rand()%x)


class Brand_group
{
private:
int yue;//余额
int chouma;//筹码
string F[4];//花色
string B[13];//点数
int V[13];
public:
Brand_group()
{
int v[13] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
for (int i = 0;i < 13;i++)
{
V[i] = v[i];
}
string temp_arr[4] = {"heart","spade","club","diamond"};
memcpy(F,temp_arr,sizeof(temp_arr));
string temp_arr1[13] = {"A","2","3","4","5","6","7","8","9","1","J","Q","K"};
memcpy(B,temp_arr1,sizeof(temp_arr1));
}
Brand_group(string F[4], char B[13], int yue, int chouma);
int duiju(int yue,int chouma);//对局函数
void menu(int yue);//菜单
void panding(int a[5], int c[5],int t);//判定

};
Brand_group::Brand_group(string F[4], char B[13], int yue, int chouma)
{
this->yue = yue;
this->chouma = chouma;
for (int i = 0; i < 4; i++)
{
this->F[i] = F[i];
}
for (int k = 0; k < 13; k++)
{
this->B[i] = B[i];
}
}

void Brand_group::menu(int yue)
{
cout<<"您的余额:"<<yue<<endl;
cout<<"按1玩"<<endl;
cout<<"按2退"<<endl;
char choose;
choose = getch();
switch(choose)
{
case '1':system("cls");
duiju(yue,0);
break;
case '2':system("cls");
exit(0);
break;
}


}
void Brand_group:: panding(int a[5], int c[5],int t)
{
for(int i=0;i<5;i++)//先将排按大小排列
{
for(int j=i+1;j<5;j++)
{
if(a[j]<a[i])
{

int temp;
temp=a[i];
a[i]=a[j];
a[j]=temp;

int temp1;
temp1=c[i];
c[i]=c[j];
c[j]=temp1;
}
}
}
int k=1,m=1,h=1; //k记录第一组相等牌的个数,m记录第二组相等牌的个数,h记录相等牌的组数,i、j用于循环使用
for(int j=0;j<4;i++)
{
if(k==1)
{
for(int p=i+1;p<5;p++)
{
if(B[i]==B[p])
k=k+1;
}
}
else
{
for(int o=i+1;o<5;o++)
{
if(B[i]==B[o]&&B[i]!=B[i-1])
{h=2;m=m+1;}
}
}
}
int n=1; //标记“对子三条铁支二对葫芦与非以上五种情况”
if (h==1)
{for(i=1;i<k;i++)n=n+1;}
if(h==2)
{
if(m!=3&&k!=3)
n=n+4;
if(m==3||k==3)
n=n+5;
}
switch(n)
{
case 1:break;
case 2:t=2;printf("对子\n");break;
case 3:t=4;printf("三条\n");break;
case 4:t=8;printf("铁支\n");break;
case 5:t=3;printf("二对\n");break;
case 6:t=7;printf("葫芦\n");break;
}
if(n==1)
{
for(i=0;i<4;i++)
{
int j=i+1;
if(V[i]-V[j]==-1&&i==3)
{
if(F[0]==F[1]&&F[1]==F[2]&&F[2]==F[3]&&F[3]==F[4])
{t=9;printf("同花顺\n");break;}
else
{t=5;printf("顺子\n");break;}
}
if(V[i]-V[j]!=-1)
{
if(F[0]==F[1]&&F[1]==F[2]&&F[2]==F[3]&&F[3]==F[4])
{t=6;printf("同花\n");break;}
else
{t=1;printf("散牌\n");break;}
}
else
continue;
}
}

}

int Brand_group::duiju(int yue,int chouma)
{
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int play_a[2];//存玩家手上的两张牌的花色
int play_b[2];//两张牌的点数
int boot1_a[2];//存机器人的
int boot1_b[2];
int boot2_a[2];
int boot2_b[2];
int boot3_a[2];
int boot3_b[2];
int pub_a[3];
int pub_b[3];
play_a[0] = random(3);
play_b[0] = random(12);
boot1_a[0] = random(3);
boot1_b[0] = random(12);
boot2_a[0] = random(3);
boot2_b[0] = random(12);
boot3_a[0] = random(3);
boot3_b[0] = random(12);
play_a[1] = random(3);
play_b[1] = random(12);
boot1_a[1] = random(3);
boot1_b[1] = random(12);
boot2_a[1] = random(3);
boot2_b[1] = random(12);
boot3_a[1] = random(3);
boot3_b[1] = random(12);
cout<<"输入你的筹码:"<<chouma<<endl;
cin>>chouma;
if (yue < chouma)
{
cout<<"您的的余额不足!"<<endl;
system("cls");
return 0;
}
cout<<"你的明牌为:"<<F[play_a[0]]<<B[play_b[0]]<<endl;
cout<<"你的暗牌为:"<<F[play_a[1]]<<B[play_b[1]]<<endl;
cout<<"甲的明牌为:"<<F[boot1_a[0]]<<B[boot1_b[0]]<<endl;
cout<<"乙的明牌为:"<<F[boot2_a[0]]<<B[boot2_b[0]]<<endl;
cout<<"丙的明牌为:"<<F[boot3_a[0]]<<B[boot3_b[0]]<<endl;
cout<<"是否继续?"<<endl;
cout<<"按1继续"<<endl;
cout<<"按2弃牌"<<endl;
char choose;
choose = getch();
switch(choose)
{
case '1':system("cls");
break;
case '2':system("cls");
cout<<"游戏结束!"<<endl;
return 0;
break;
}
pub_a[0] = random(3);
pub_b[0] = random(12);
cout<<"明牌1为:"<<F[pub_a[0]]<<B[pub_b[0]]<<endl;
cout<<"是否继续?"<<endl;
cout<<"按1继续"<<endl;
cout<<"按2弃牌"<<endl;
char choose1;
choose1 = getch();
switch(choose1)
{
case '1':system("cls");
break;
case '2':system("cls");
cout<<"游戏结束!"<<endl;
return 0;
break;
}
pub_a[1] = random(3);
pub_b[1] = random(12);
cout<<"明牌1为:"<<F[pub_a[1]]<<B[pub_b[1]]<<endl;
cout<<"是否继续?"<<endl;
cout<<"按1继续"<<endl;
cout<<"按2弃牌"<<endl;
char choose2;
choose2 = getch();
switch(choose2)
{
case '1':system("cls");
break;
case '2':system("cls");
cout<<"游戏结束!"<<endl;
return 0;
break;
}
pub_a[2] = random(3);
pub_b[2] = random(12);
cout<<"明牌1为:"<<F[pub_a[2]]<<B[pub_b[2]]<<endl;
cout<<"是否继续?"<<endl;
cout<<"按1继续"<<endl;
cout<<"按2弃牌"<<endl;
char choose3;
choose3 = getch();
switch(choose3)
{
case '1':system("cls");
break;
case '2':system("cls");
cout<<"游戏结束!"<<endl;
return 0;
break;
}

cout<<"请大家亮牌!"<<endl;
cout<<"你:"<<F[play_a[0]]<<B[play_b[0]]<<" "<<F[play_a[1]]<<B[play_b[1]]<<" "<<B[pub_a[0]]<<F[pub_b[0]]<<" "<<B[pub_a[1]]<<F[pub_b[1]]<<" "<<B[pub_a[2]]<<F[pub_b[2]]<<endl;
cout<<"甲:"<<F[boot1_a[0]]<<B[boot1_b[0]]<<" "<<F[boot1_a[1]]<<B[boot1_b[1]]<<" "<<B[pub_a[0]]<<F[pub_b[0]]<<" "<<B[pub_a[1]]<<F[pub_b[1]]<<" "<<B[pub_a[2]]<<F[pub_b[2]]<<endl;
cout<<"乙:"<<F[boot2_a[0]]<<B[boot2_b[0]]<<" "<<F[boot2_a[1]]<<B[boot2_b[1]]<<" "<<B[pub_a[0]]<<F[pub_b[0]]<<" "<<B[pub_a[1]]<<F[pub_b[1]]<<" "<<B[pub_a[2]]<<F[pub_b[2]]<<endl;
cout<<"丙:"<<F[boot3_a[0]]<<B[boot3_b[0]]<<" "<<F[boot3_a[1]]<<B[boot3_b[1]]<<" "<<B[pub_a[0]]<<F[pub_b[0]]<<" "<<B[pub_a[1]]<<F[pub_b[1]]<<" "<<B[pub_a[2]]<<F[pub_b[2]]<<endl;


int playA[5] = {play_a[0], play_a[1],pub_a[0],pub_a[1],pub_a[2]};
int playB[5] = {play_b[0], play_b[1],pub_b[0],pub_b[1],pub_b[2]};
int boot1A[5] = {boot1_a[0], boot1_a[1],pub_a[0],pub_a[1],pub_a[2]};
int boot1B[5] = {boot1_b[0], boot1_b[1],pub_b[0],pub_b[1],pub_b[2]};
int boot2A[5] = {boot2_a[0], boot2_a[1],pub_a[0],pub_a[1],pub_a[2]};
int boot2B[5] = {boot2_b[0], boot2_b[1],pub_b[0],pub_b[1],pub_b[2]};
int boot3A[5] = {boot3_a[0], boot3_a[1],pub_a[0],pub_a[1],pub_a[2]};
int boot3B[5] = {boot3_b[0], boot3_b[1],pub_b[0],pub_b[1],pub_b[2]};
panding(playA,playB,a);
panding(boot1A,boot1B,b);
panding(boot2A,boot2B,c);
panding(boot3A,boot3B,d);
if (a > b)
{
if (a > c)
{
if (a > d)
{
cout <<"你赢了!"<<endl;
yue = yue + chouma;
return 0;

}
}
}
else
{
cout<<"你输了!"<<endl;
yue = yue - chouma;


}
return 0;
}



int main()
{
Brand_group b;
b.menu(100);




return 0;
}
...全文
741 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
开心秋水 2017-11-12
  • 打赏
  • 举报
回复
请不要对std::string使用sizeof和 memcpy
Dogfish 2017-11-12
  • 打赏
  • 举报
回复
觉得这是编码问题。
这不是鸭头 2017-11-12
  • 打赏
  • 举报
回复
数组没有初始化,或者溢出
qq_38372518 2017-11-11
  • 打赏
  • 举报
回复
引用 3 楼 destory27 的回复:
for (int k = 0; k < 13; k++) { this->B[k] = B[k]; //// Error 47行 } for(int j=0;j<4;j++) // error 92 { if(k==1) { for(int p=j+1;p<5;p++) // 96 { if(B[j]==B[p]) // 98 k=k+1; } } for(int o=j+1;o<5;o++) // 104 { if(B[j]==B[o]&&B[j]!=B[j-1]) // 106 {h=2;m=m+1;} } if (h==1) {for(int i=1;i<k;i++)n=n+1;} // 113 for(int i=0;i<4;i++) // 132 { int j=i+1;
感谢!!但还是没有解决,这都是判定函数里的错误。。
destory27 2017-11-11
  • 打赏
  • 举报
回复
for (int k = 0; k < 13; k++) { this->B[k] = B[k]; //// Error 47行 } for(int j=0;j<4;j++) // error 92 { if(k==1) { for(int p=j+1;p<5;p++) // 96 { if(B[j]==B[p]) // 98 k=k+1; } } for(int o=j+1;o<5;o++) // 104 { if(B[j]==B[o]&&B[j]!=B[j-1]) // 106 {h=2;m=m+1;} } if (h==1) {for(int i=1;i<k;i++)n=n+1;} // 113 for(int i=0;i<4;i++) // 132 { int j=i+1;
qq_38372518 2017-11-11
  • 打赏
  • 举报
回复
引用 1 楼 iloveyou418 的回复:
贴代码、应该是数组赋值或读值问题
贴了啊
CT8100 2017-11-11
  • 打赏
  • 举报
回复
贴代码、应该是数组赋值或读值问题

33,321

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧