如何解决为Flash Card游戏添加的数字有误吗? Cpp
我正在尝试编写创建Flash游戏的代码。三名玩家三次抓3张牌。纸牌分数是抽出的纸牌总数。但是,卡分数被错误地添加。控制台示例:
玩家2赢得卡牌得分:85 抽牌: 11 2 11 11 3 5 11 13 13
如果有人可以帮助我或解释一种更好的方法,将不胜感激。
void FlashCard::drawCards(FlashCard f[3])
{
for (int i =0; i<4;++i)
{
int a = rand() % 13 + 1;
int b = rand() % 13 + 1;
int c = rand() % 13 + 1;
f[0].firstDraw[i] = a;
f[1].firstDraw[i] = b;
f[2].firstDraw[i] = c;
}
for (int i =0; i<4;++i)
{
int a = rand() % 13 + 1;
int b = rand() % 13 + 1;
int c = rand() % 13 + 1;
f[0].secondDraw[i] = a;
f[1].secondDraw[i] = b;
f[2].secondDraw[i] = c;
}
for (int i =0; i<4;++i)
{
int a = rand() % 13 + 1;
int b = rand() % 13 + 1;
int c = rand() % 13 + 1;
f[0].thirdDraw[i] = a;
f[1].thirdDraw[i] = b;
f[2].thirdDraw[i] = c;
}
for (int j = 0;j<3;++j)
{
for(int i = 0;i<3;++i)
{
f[j].cardscore += f[j].firstDraw[i];
}
for(int i = 0;i<3;++i)
{
f[j].cardscore += f[j].secondDraw[i];
}
for(int i = 0;i<3;++i)
{
f[j].cardscore += f[j].thirdDraw[i];
}
}
}
这就是我输出获胜者的方式。
void FlashCard::printWinner(FlashCard f[3])
{
if (f[0].cardscore > f[1].cardscore && f[0].cardscore > f[2].cardscore)
{
std::cout << "Player 1 wins with a card score of:" << f[0].cardscore<<std::endl;
std::cout << "Cards drawn: " << std::endl;
for(int i = 0;i<3;++i)
{
std::cout << f[0].firstDraw[i] << " ";
}
std::cout<<std::endl;
for(int i = 0;i<3;++i)
{
std::cout << f[0].secondDraw[i] << " ";
}
std::cout<<std::endl;
for(int i = 0;i<3;++i)
{
std::cout << f[0].thirdDraw[i] << " ";
}
std::cout<<std::endl;
}
if (f[1].cardscore > f[0].cardscore && f[1].cardscore > f[2].cardscore)
{
std::cout << "Player 2 wins with a card score of:" << f[1].cardscore << std::endl;
std::cout << "Cards drawn: " << std::endl;
for(int i = 0;i<3;++i)
{
std::cout << f[1].firstDraw[i] << " ";
}
std::cout<<std::endl;
for(int i = 0;i<3;++i)
{
std::cout << f[1].secondDraw[i] << " ";
}
std::cout<<std::endl;
for(int i = 0;i<3;++i)
{
std::cout << f[1].thirdDraw[i] << " ";
}
std::cout<<std::endl;
}
if (f[2].cardscore > f[0].cardscore && f[2].cardscore > f[1].cardscore)
{
std::cout << "Player 3 wins with a card score of:" << f[2].cardscore << std::endl;
std::cout << "Cards drawn: " << std::endl;
for(int i = 0;i<3;++i)
{
std::cout << f[2].firstDraw[i] << " ";
}
std::cout<<std::endl;
for(int i = 0;i<3;++i)
{
std::cout << f[2].secondDraw[i] << " ";
}
std::cout<<std::endl;
for(int i = 0;i<3;++i)
{
std::cout << f[2].thirdDraw[i] << " ";
}
std::cout<<std::endl;
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。