【发布时间】:2015-03-24 11:21:45
【问题描述】:
我正在编写一个 farkle 游戏,即使我的 if 语句除了两个以外的所有语句都是布尔值,我也遇到了这个问题。
另外,我将如何让用户掷特定的骰子? BloodshedDev/其他 IDE 似乎还不能在 Windows 8 中运行,所以我正在使用 Ideone 并且在这方面的运气为零。
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
//global vars
int bubblehold;
int roll[6];
int score;
int bank;
int dicecatch;
int tempscore = 0;
int dicenum = 6;
//function prototype
void bubblesort(int[], int);
bool straightsix();
bool sixkind();
bool fivekind();
bool fourkind();
bool threekind();
int onefive();
int main() {
srand(time(0));
for(int i=0; i=dicenum-1; i++){
roll[i] = rand()%6+1;
}
bubblesort(roll,dicenum);
for(int i=0; i=dicenum-1; i++){
cout<< roll[i] <<", ";
}
if(straightsix == true){
tempscore = 1500;
}
else if(sixkind == true){
tempscore = 3000;
}
else if(fivekind == true){
tempscore = 2000;
}
else if(fourkind == true){
tempscore = 1000;
}
else if(threekind == true){
cout<< tempscore;
}
else if(onefive == 1){
tempscore = dicecatch * tempscore;
cout<< tempscore;
}
else if(onefive == 5){
tempscore = dicecatch * tempscore;
cout<< tempscore;
}
return 0;
}
void bubblesort(int a[], int x){
for (int i = 0; i < x-1; i++){
bubblehold = a[i+1];
a[i+1] = a[i];
a[i] = bubblehold;
}
}
bool straightsix(){
for(int i=0; i<5; i++){
if(roll[i]+1 != roll[i+5]){
return false;
}
}
}
bool sixkind(){
for(int i=0; i=5; i++){
if (roll[i] != roll[i+5]){
return false;
}
}
}
bool fivekind(){
for(int i=0; i=4; i++){
if (roll[i] != roll[i+4]){
return false;
}
}
}
bool fourkind(){
for(int i=0; i=3; i++){
if (roll[i] != roll[i+3]){
return false;
}
}
}
bool threekind(){
for(int i=0; i=2; i++){
if (roll[i] != roll[i+2]){
return false;
}
else if(i=1){
dicecatch = 3;
tempscore = dicecatch * 100;
return true;
}
else{
dicecatch = i;
tempscore = dicecatch * 100;
return true;
};
}
}
int onefive(){
for(int i=0; i=dicenum; i++){
if(roll[i] == 1){
dicecatch = dicecatch + 1;
tempscore = tempscore + 100;
return 1;
}
else if(roll[i] == 5){
dicecatch = dicecatch + 1;
tempscore = tempscore + 50;
return 5;
}
}
}
【问题讨论】:
-
我想你的意思是
if(straightsix() == true)等等等等。 -
“我遇到了这个问题” 什么问题?在哪里?
-
你不应该在没有测试的情况下编写这么多代码。
-
@user657267:或者,好多更好,
if (straightsix())。它已经是一个布尔值;为什么要添加无用的比较? -
您可能已经注意到您的很多代码都受到了负面关注。由于您是 C++ 新手,我认为 @Beta 在这里给出了最好的建议。编写一个小得多的程序,然后看看它是否有效。然后加一点代码,看看能不能用。