Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/131.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
制作马里奥派对游戏,但游戏一开始就宣布获胜 为了提高我的编码技巧,我用C++制作了一个马里奥派对游戏。我希望它是相当基本的。这应该是一个两人游戏,允许每个用户从阵列中选择角色。然后他们会掷骰子,试着得到星星。这很像一个棋盘游戏。在游戏开始时选择获得一定数量星星的人获胜。我的代码的问题是,只要第一个人在那里掷骰子,它就会自动给他们“万岁,你赢了”的演讲,并询问他们是否想再次玩 #include <iostream> #include <cstdlib> #include <time.h> #include <conio.h> #include <windows.h> #include <string> using namespace std; void ChooseAmountofStars(int& Starnumbers) { //Gets the number of stars that will be in the game cout<<"How many stars do you want to search for, (1-3).\n"; cin>>Starnumbers; cout<<"Great choice. The first player to retrieve "<<Starnumbers<<" Stars wins the game"<<endl; } int starplus(int Adder) { return Adder; } int PlaceStars() { //Place the star in a dice roll distance from the origin srand(time(0)); int SpotNumber; SpotNumber=(rand()%50)+1; return SpotNumber; } int Winner(int Adder, int Starnumbers) { return starplus(Adder)==Starnumbers; } void coinplus(int& Adder) { int coin=0; coin+=20; if(coin>=100){ coin=0; Adder+=1; cout<<"You have "<<starplus(Adder)<<" stars"<<endl; } } int WhoGoesFirst(){ srand(time(0)); int chance; chance=(rand()%2)+1; if(chance == 1){ return 1;} else{ return 2;} } class Tools{ public: void MiniGame(){ rematch: string Choices[3]={"Rock","Paper","Scissors"}; string UserChoice; cout<<"Type your choice of either Rock, Paper, or Scissors"<<endl; cin>>UserChoice; int RandomNum=rand()%3; srand(time(0)); string ComputerChoice; ComputerChoice=Choices[RandomNum]; cout<<"Challenger chose: "<<ComputerChoice<<"\n"; if(UserChoice=="rock"){ if(ComputerChoice=="Rock"){ cout<<"It Is a Tie\n\n"; goto rematch;} else if(ComputerChoice=="Paper"){ cout<<"Sorry, You Lose. Better Luck Next Time\n\n";} else{ cout<<"Nice Job. You Win\n\n";} } else if(UserChoice=="paper"){ if(ComputerChoice=="Paper"){ cout<<"It Is a Tie\n\n"; goto rematch;} else if(ComputerChoice=="Scissors"){ cout<<"Sorry, You Lose. Better Luck Next Time\n\n";} else{ cout<<"Nice Job. You Win\n\n";} } else if(UserChoice=="scissors"){ if(ComputerChoice=="Scissors"){ cout<<"It Is a Tie\n\n"; goto rematch;} else if(ComputerChoice=="Rock"){ cout<<"Sorry, You Lose. Better Luck Next Time\n\n";} else{ cout<<"Nice Job. You Win\n\n";} } else{ cout<<"Knock it off with the typos!!!\n\n"; goto rematch; } } void Dice(string player, int Adder) { int face=0; int SpotNumber=PlaceStars(); system("cls"); cout << endl <<"--------------DICE---------------" << endl; srand((unsigned)time(0)); cout << "Rolling..." << endl; Sleep(2000); face = (rand()%6)+1; int spot=0; if (face == 1) { cout << " ___________" << endl; cout << " | |" << endl; cout << " | | " << endl; cout << " | @ |" << endl; cout << " | |" << endl; cout << " |_________|" << endl; spot+=1; if(spot>=50){ spot-=spot; cout<<player<<" landed on "<<spot<<endl; } else if(spot==9||spot==17||spot==32||spot==35||spot==47||spot==42||spot==25||spot==49){ cout<<player<<" landed on "<<spot<<endl; coinplus(Adder); } else if(spot==SpotNumber){ cout<<player<<" landed on "<<spot<<endl; Adder+=1; cout<<"You have "<<starplus(Adder)<<" stars"<<endl; } else{ cout<<player<<" landed on "<<spot<<endl; } } else if (face == 2) { cout << " ___________" << endl; cout << " | |" << endl; cout << " | @ | " << endl; cout << " | |" << endl; cout << " | @ |" << endl; cout << " |_________|" << endl; spot+=2; if(spot>=50){ spot-=spot; cout<<player<<" landed on "<<spot<<endl; } else if(spot==9||spot==17||spot==32||spot==35||spot==47||spot==42||spot==25||spot==49){ cout<<player<<" landed on "<<spot<<endl; coinplus(Adder); } else if(spot==SpotNumber){ cout<<player<<" landed on "<<spot<<endl; Adder+=1; cout<<"You have "<<starplus(Adder)<<" stars"<<endl; } else{ cout<<player<<" landed on "<<spot<<endl; } } else if (face == 3) { cout << " ___________" << endl; cout << " | |" << endl; cout << " | @ | " << endl; cout << " | @ |" << endl; cout << " | @ |" << endl; cout << " |_________|" << endl; spot+=3; if(spot>=50){ spot-=spot; cout<<player<<" landed on "<<spot<<endl; } else if(spot==9||spot==17||spot==32||spot==35||spot==47||spot==42||spot==25||spot==49){ cout<<player<<" landed on "<<spot<<endl; coinplus(Adder); } else if(spot==SpotNumber){ cout<<player<<" landed on "<<spot<<endl; Adder+=1; cout<<"You have "<<starplus(Adder)<<" stars"<<endl; } else{ cout<<player<<" landed on "<<spot<<endl; } } else if (face == 4) { cout << " ___________" << endl; cout << " | |" << endl; cout << " | @ @ |" << endl; cout << " | |" << endl; cout << " | @ @ |" << endl; cout << " |_________|" << endl; spot+=4; if(spot>=50){ spot-=spot; cout<<player<<" landed on "<<spot<<endl; } else if(spot==9||spot==17||spot==32||spot==35||spot==47||spot==42||spot==25||spot==49){ cout<<player<<" landed on "<<spot<<endl; coinplus(Adder); } else if(spot==SpotNumber){ cout<<player<<" landed on "<<spot<<endl; Adder+=1; cout<<"You have "<<starplus(Adder)<<" stars"<<endl; } else{ cout<<player<<" landed on "<<spot<<endl; } } else if (face == 5) { cout << " ___________" << endl; cout << " | |" << endl; cout << " | @ @ | " << endl; cout << " | @ |" << endl; cout << " | @ @ |" << endl; cout << " |_________|" << endl; spot+=5; if(spot>=50){ spot-=spot; cout<<player<<" landed on "<<spot<<endl; } else if(spot==9||spot==17||spot==32||spot==35||spot==47||spot==42||spot==25||spot==49){ cout<<player<<" landed on "<<spot<<endl; coinplus(Adder); } else if(spot==SpotNumber){ cout<<player<<" landed on "<<spot<<endl; Adder+=1; cout<<"You have "<<starplus(Adder)<<" stars"<<endl; } else{ cout<<player<<" landed on "<<spot<<endl; } } else if (face == 6) { cout << " ___________" << endl; cout << " | |" << endl; cout << " | @ @ | " << endl; cout << " | @ @ |" << endl; cout << " | @ @ |" << endl; cout << " |_________|" << endl; spot+=6; if(spot>=50){ spot-=spot; cout<<player<<" landed on "<<spot<<endl; } else if(spot==9||spot==17||spot==32||spot==35||spot==47||spot==42||spot==25||spot==49){ cout<<player<<" landed on "<<spot<<endl; coinplus(Adder); } else if(spot==SpotNumber){ cout<<player<<" landed on "<<spot<<endl; Adder+=1; cout<<"You have "<<starplus(Adder)<<" stars"<<endl; } else{ cout<<player<<" landed on "<<spot<<endl; } } } }; int main() { int Score1=0; //this will be used in parameter of dice for star count of plyr 1 int Score2=0; //this will be used in parameter of dice for star count of plyr 2 Tools ToolsObject; beginning: //If user would like to play again, they will start back at beginning cout<<"Plyr 1: Choose character from character list below\n"; string ChaList[9]={"Mario ", "Luigi ","Peach ","Daisy ","Wario ","Waluigi ","Bowser ","Toad ","Yoshi"}; for(int i=0; i<9; i++){ cout<<ChaList[i]; } cout<<endl; //Displays player options for user1 string Plyr1; cin>>Plyr1; cout<<"You chose "<<Plyr1<<endl; //Allows user to choose character and saves it in variable called Plyr1 cout<<"Plyr 2: Choose character from character list below\n"; for(int i=0; i<9; i++){ cout<<ChaList[i]; } cout<<endl; //Displays player options for user2 string Plyr2; cin>>Plyr2; cout<<"You chose "<<Plyr2<<endl; //Allows user to choose character and saves it in variable called Plyr2 int StarNums=0; int StarNums2=0; ChooseAmountofStars(StarNums); //sets amount of stars to be found in order to win game. Parameter changes values the variable globally. it is set by reference. int position=PlaceStars(); //Puts position of star from PlaceStars function into a variable that is local to main cout<<"The star is placed at spot: "<<position<<endl; int turn; turn = WhoGoesFirst(); //Put the turn from WhoGoesFirst function into a variable that is local to main bool GameIsPlaying=true; while(GameIsPlaying==true){ if(turn==1){ ToolsObject.Dice(Plyr1, Score1); if(Winner(Score1,StarNums)){ cout<<"Hurray you win"<<endl; GameIsPlaying=false; } else{ turn=2; } } else{ ToolsObject.Dice(Plyr2, Score2); if(Winner(Score2,StarNums2)){ cout<<"Hurray you win"<<endl; GameIsPlaying=false;} else{ turn=1; } } } string desision; while(desision!="y" || desision!="n" ){ cout<<"Would you like to play again? (y or n)"<<endl; cin>>desision; if(desision=="y"){ cout<<"Get ready"<<endl; goto beginning; } else if(desision=="n"){ cout<<"Enjoy the rest of the day"<<endl; } else{ cout<<"Not a valid choice"<<endl; } } } #包括 #包括 #包括 #包括 #包括 #包括 使用名称空间std; 无效选择星山(整数和星号) { //获取将出现在游戏中的星星数 库塔数; cout_C++ - Fatal编程技术网

制作马里奥派对游戏,但游戏一开始就宣布获胜 为了提高我的编码技巧,我用C++制作了一个马里奥派对游戏。我希望它是相当基本的。这应该是一个两人游戏,允许每个用户从阵列中选择角色。然后他们会掷骰子,试着得到星星。这很像一个棋盘游戏。在游戏开始时选择获得一定数量星星的人获胜。我的代码的问题是,只要第一个人在那里掷骰子,它就会自动给他们“万岁,你赢了”的演讲,并询问他们是否想再次玩 #include <iostream> #include <cstdlib> #include <time.h> #include <conio.h> #include <windows.h> #include <string> using namespace std; void ChooseAmountofStars(int& Starnumbers) { //Gets the number of stars that will be in the game cout<<"How many stars do you want to search for, (1-3).\n"; cin>>Starnumbers; cout<<"Great choice. The first player to retrieve "<<Starnumbers<<" Stars wins the game"<<endl; } int starplus(int Adder) { return Adder; } int PlaceStars() { //Place the star in a dice roll distance from the origin srand(time(0)); int SpotNumber; SpotNumber=(rand()%50)+1; return SpotNumber; } int Winner(int Adder, int Starnumbers) { return starplus(Adder)==Starnumbers; } void coinplus(int& Adder) { int coin=0; coin+=20; if(coin>=100){ coin=0; Adder+=1; cout<<"You have "<<starplus(Adder)<<" stars"<<endl; } } int WhoGoesFirst(){ srand(time(0)); int chance; chance=(rand()%2)+1; if(chance == 1){ return 1;} else{ return 2;} } class Tools{ public: void MiniGame(){ rematch: string Choices[3]={"Rock","Paper","Scissors"}; string UserChoice; cout<<"Type your choice of either Rock, Paper, or Scissors"<<endl; cin>>UserChoice; int RandomNum=rand()%3; srand(time(0)); string ComputerChoice; ComputerChoice=Choices[RandomNum]; cout<<"Challenger chose: "<<ComputerChoice<<"\n"; if(UserChoice=="rock"){ if(ComputerChoice=="Rock"){ cout<<"It Is a Tie\n\n"; goto rematch;} else if(ComputerChoice=="Paper"){ cout<<"Sorry, You Lose. Better Luck Next Time\n\n";} else{ cout<<"Nice Job. You Win\n\n";} } else if(UserChoice=="paper"){ if(ComputerChoice=="Paper"){ cout<<"It Is a Tie\n\n"; goto rematch;} else if(ComputerChoice=="Scissors"){ cout<<"Sorry, You Lose. Better Luck Next Time\n\n";} else{ cout<<"Nice Job. You Win\n\n";} } else if(UserChoice=="scissors"){ if(ComputerChoice=="Scissors"){ cout<<"It Is a Tie\n\n"; goto rematch;} else if(ComputerChoice=="Rock"){ cout<<"Sorry, You Lose. Better Luck Next Time\n\n";} else{ cout<<"Nice Job. You Win\n\n";} } else{ cout<<"Knock it off with the typos!!!\n\n"; goto rematch; } } void Dice(string player, int Adder) { int face=0; int SpotNumber=PlaceStars(); system("cls"); cout << endl <<"--------------DICE---------------" << endl; srand((unsigned)time(0)); cout << "Rolling..." << endl; Sleep(2000); face = (rand()%6)+1; int spot=0; if (face == 1) { cout << " ___________" << endl; cout << " | |" << endl; cout << " | | " << endl; cout << " | @ |" << endl; cout << " | |" << endl; cout << " |_________|" << endl; spot+=1; if(spot>=50){ spot-=spot; cout<<player<<" landed on "<<spot<<endl; } else if(spot==9||spot==17||spot==32||spot==35||spot==47||spot==42||spot==25||spot==49){ cout<<player<<" landed on "<<spot<<endl; coinplus(Adder); } else if(spot==SpotNumber){ cout<<player<<" landed on "<<spot<<endl; Adder+=1; cout<<"You have "<<starplus(Adder)<<" stars"<<endl; } else{ cout<<player<<" landed on "<<spot<<endl; } } else if (face == 2) { cout << " ___________" << endl; cout << " | |" << endl; cout << " | @ | " << endl; cout << " | |" << endl; cout << " | @ |" << endl; cout << " |_________|" << endl; spot+=2; if(spot>=50){ spot-=spot; cout<<player<<" landed on "<<spot<<endl; } else if(spot==9||spot==17||spot==32||spot==35||spot==47||spot==42||spot==25||spot==49){ cout<<player<<" landed on "<<spot<<endl; coinplus(Adder); } else if(spot==SpotNumber){ cout<<player<<" landed on "<<spot<<endl; Adder+=1; cout<<"You have "<<starplus(Adder)<<" stars"<<endl; } else{ cout<<player<<" landed on "<<spot<<endl; } } else if (face == 3) { cout << " ___________" << endl; cout << " | |" << endl; cout << " | @ | " << endl; cout << " | @ |" << endl; cout << " | @ |" << endl; cout << " |_________|" << endl; spot+=3; if(spot>=50){ spot-=spot; cout<<player<<" landed on "<<spot<<endl; } else if(spot==9||spot==17||spot==32||spot==35||spot==47||spot==42||spot==25||spot==49){ cout<<player<<" landed on "<<spot<<endl; coinplus(Adder); } else if(spot==SpotNumber){ cout<<player<<" landed on "<<spot<<endl; Adder+=1; cout<<"You have "<<starplus(Adder)<<" stars"<<endl; } else{ cout<<player<<" landed on "<<spot<<endl; } } else if (face == 4) { cout << " ___________" << endl; cout << " | |" << endl; cout << " | @ @ |" << endl; cout << " | |" << endl; cout << " | @ @ |" << endl; cout << " |_________|" << endl; spot+=4; if(spot>=50){ spot-=spot; cout<<player<<" landed on "<<spot<<endl; } else if(spot==9||spot==17||spot==32||spot==35||spot==47||spot==42||spot==25||spot==49){ cout<<player<<" landed on "<<spot<<endl; coinplus(Adder); } else if(spot==SpotNumber){ cout<<player<<" landed on "<<spot<<endl; Adder+=1; cout<<"You have "<<starplus(Adder)<<" stars"<<endl; } else{ cout<<player<<" landed on "<<spot<<endl; } } else if (face == 5) { cout << " ___________" << endl; cout << " | |" << endl; cout << " | @ @ | " << endl; cout << " | @ |" << endl; cout << " | @ @ |" << endl; cout << " |_________|" << endl; spot+=5; if(spot>=50){ spot-=spot; cout<<player<<" landed on "<<spot<<endl; } else if(spot==9||spot==17||spot==32||spot==35||spot==47||spot==42||spot==25||spot==49){ cout<<player<<" landed on "<<spot<<endl; coinplus(Adder); } else if(spot==SpotNumber){ cout<<player<<" landed on "<<spot<<endl; Adder+=1; cout<<"You have "<<starplus(Adder)<<" stars"<<endl; } else{ cout<<player<<" landed on "<<spot<<endl; } } else if (face == 6) { cout << " ___________" << endl; cout << " | |" << endl; cout << " | @ @ | " << endl; cout << " | @ @ |" << endl; cout << " | @ @ |" << endl; cout << " |_________|" << endl; spot+=6; if(spot>=50){ spot-=spot; cout<<player<<" landed on "<<spot<<endl; } else if(spot==9||spot==17||spot==32||spot==35||spot==47||spot==42||spot==25||spot==49){ cout<<player<<" landed on "<<spot<<endl; coinplus(Adder); } else if(spot==SpotNumber){ cout<<player<<" landed on "<<spot<<endl; Adder+=1; cout<<"You have "<<starplus(Adder)<<" stars"<<endl; } else{ cout<<player<<" landed on "<<spot<<endl; } } } }; int main() { int Score1=0; //this will be used in parameter of dice for star count of plyr 1 int Score2=0; //this will be used in parameter of dice for star count of plyr 2 Tools ToolsObject; beginning: //If user would like to play again, they will start back at beginning cout<<"Plyr 1: Choose character from character list below\n"; string ChaList[9]={"Mario ", "Luigi ","Peach ","Daisy ","Wario ","Waluigi ","Bowser ","Toad ","Yoshi"}; for(int i=0; i<9; i++){ cout<<ChaList[i]; } cout<<endl; //Displays player options for user1 string Plyr1; cin>>Plyr1; cout<<"You chose "<<Plyr1<<endl; //Allows user to choose character and saves it in variable called Plyr1 cout<<"Plyr 2: Choose character from character list below\n"; for(int i=0; i<9; i++){ cout<<ChaList[i]; } cout<<endl; //Displays player options for user2 string Plyr2; cin>>Plyr2; cout<<"You chose "<<Plyr2<<endl; //Allows user to choose character and saves it in variable called Plyr2 int StarNums=0; int StarNums2=0; ChooseAmountofStars(StarNums); //sets amount of stars to be found in order to win game. Parameter changes values the variable globally. it is set by reference. int position=PlaceStars(); //Puts position of star from PlaceStars function into a variable that is local to main cout<<"The star is placed at spot: "<<position<<endl; int turn; turn = WhoGoesFirst(); //Put the turn from WhoGoesFirst function into a variable that is local to main bool GameIsPlaying=true; while(GameIsPlaying==true){ if(turn==1){ ToolsObject.Dice(Plyr1, Score1); if(Winner(Score1,StarNums)){ cout<<"Hurray you win"<<endl; GameIsPlaying=false; } else{ turn=2; } } else{ ToolsObject.Dice(Plyr2, Score2); if(Winner(Score2,StarNums2)){ cout<<"Hurray you win"<<endl; GameIsPlaying=false;} else{ turn=1; } } } string desision; while(desision!="y" || desision!="n" ){ cout<<"Would you like to play again? (y or n)"<<endl; cin>>desision; if(desision=="y"){ cout<<"Get ready"<<endl; goto beginning; } else if(desision=="n"){ cout<<"Enjoy the rest of the day"<<endl; } else{ cout<<"Not a valid choice"<<endl; } } } #包括 #包括 #包括 #包括 #包括 #包括 使用名称空间std; 无效选择星山(整数和星号) { //获取将出现在游戏中的星星数 库塔数; cout

制作马里奥派对游戏,但游戏一开始就宣布获胜 为了提高我的编码技巧,我用C++制作了一个马里奥派对游戏。我希望它是相当基本的。这应该是一个两人游戏,允许每个用户从阵列中选择角色。然后他们会掷骰子,试着得到星星。这很像一个棋盘游戏。在游戏开始时选择获得一定数量星星的人获胜。我的代码的问题是,只要第一个人在那里掷骰子,它就会自动给他们“万岁,你赢了”的演讲,并询问他们是否想再次玩 #include <iostream> #include <cstdlib> #include <time.h> #include <conio.h> #include <windows.h> #include <string> using namespace std; void ChooseAmountofStars(int& Starnumbers) { //Gets the number of stars that will be in the game cout<<"How many stars do you want to search for, (1-3).\n"; cin>>Starnumbers; cout<<"Great choice. The first player to retrieve "<<Starnumbers<<" Stars wins the game"<<endl; } int starplus(int Adder) { return Adder; } int PlaceStars() { //Place the star in a dice roll distance from the origin srand(time(0)); int SpotNumber; SpotNumber=(rand()%50)+1; return SpotNumber; } int Winner(int Adder, int Starnumbers) { return starplus(Adder)==Starnumbers; } void coinplus(int& Adder) { int coin=0; coin+=20; if(coin>=100){ coin=0; Adder+=1; cout<<"You have "<<starplus(Adder)<<" stars"<<endl; } } int WhoGoesFirst(){ srand(time(0)); int chance; chance=(rand()%2)+1; if(chance == 1){ return 1;} else{ return 2;} } class Tools{ public: void MiniGame(){ rematch: string Choices[3]={"Rock","Paper","Scissors"}; string UserChoice; cout<<"Type your choice of either Rock, Paper, or Scissors"<<endl; cin>>UserChoice; int RandomNum=rand()%3; srand(time(0)); string ComputerChoice; ComputerChoice=Choices[RandomNum]; cout<<"Challenger chose: "<<ComputerChoice<<"\n"; if(UserChoice=="rock"){ if(ComputerChoice=="Rock"){ cout<<"It Is a Tie\n\n"; goto rematch;} else if(ComputerChoice=="Paper"){ cout<<"Sorry, You Lose. Better Luck Next Time\n\n";} else{ cout<<"Nice Job. You Win\n\n";} } else if(UserChoice=="paper"){ if(ComputerChoice=="Paper"){ cout<<"It Is a Tie\n\n"; goto rematch;} else if(ComputerChoice=="Scissors"){ cout<<"Sorry, You Lose. Better Luck Next Time\n\n";} else{ cout<<"Nice Job. You Win\n\n";} } else if(UserChoice=="scissors"){ if(ComputerChoice=="Scissors"){ cout<<"It Is a Tie\n\n"; goto rematch;} else if(ComputerChoice=="Rock"){ cout<<"Sorry, You Lose. Better Luck Next Time\n\n";} else{ cout<<"Nice Job. You Win\n\n";} } else{ cout<<"Knock it off with the typos!!!\n\n"; goto rematch; } } void Dice(string player, int Adder) { int face=0; int SpotNumber=PlaceStars(); system("cls"); cout << endl <<"--------------DICE---------------" << endl; srand((unsigned)time(0)); cout << "Rolling..." << endl; Sleep(2000); face = (rand()%6)+1; int spot=0; if (face == 1) { cout << " ___________" << endl; cout << " | |" << endl; cout << " | | " << endl; cout << " | @ |" << endl; cout << " | |" << endl; cout << " |_________|" << endl; spot+=1; if(spot>=50){ spot-=spot; cout<<player<<" landed on "<<spot<<endl; } else if(spot==9||spot==17||spot==32||spot==35||spot==47||spot==42||spot==25||spot==49){ cout<<player<<" landed on "<<spot<<endl; coinplus(Adder); } else if(spot==SpotNumber){ cout<<player<<" landed on "<<spot<<endl; Adder+=1; cout<<"You have "<<starplus(Adder)<<" stars"<<endl; } else{ cout<<player<<" landed on "<<spot<<endl; } } else if (face == 2) { cout << " ___________" << endl; cout << " | |" << endl; cout << " | @ | " << endl; cout << " | |" << endl; cout << " | @ |" << endl; cout << " |_________|" << endl; spot+=2; if(spot>=50){ spot-=spot; cout<<player<<" landed on "<<spot<<endl; } else if(spot==9||spot==17||spot==32||spot==35||spot==47||spot==42||spot==25||spot==49){ cout<<player<<" landed on "<<spot<<endl; coinplus(Adder); } else if(spot==SpotNumber){ cout<<player<<" landed on "<<spot<<endl; Adder+=1; cout<<"You have "<<starplus(Adder)<<" stars"<<endl; } else{ cout<<player<<" landed on "<<spot<<endl; } } else if (face == 3) { cout << " ___________" << endl; cout << " | |" << endl; cout << " | @ | " << endl; cout << " | @ |" << endl; cout << " | @ |" << endl; cout << " |_________|" << endl; spot+=3; if(spot>=50){ spot-=spot; cout<<player<<" landed on "<<spot<<endl; } else if(spot==9||spot==17||spot==32||spot==35||spot==47||spot==42||spot==25||spot==49){ cout<<player<<" landed on "<<spot<<endl; coinplus(Adder); } else if(spot==SpotNumber){ cout<<player<<" landed on "<<spot<<endl; Adder+=1; cout<<"You have "<<starplus(Adder)<<" stars"<<endl; } else{ cout<<player<<" landed on "<<spot<<endl; } } else if (face == 4) { cout << " ___________" << endl; cout << " | |" << endl; cout << " | @ @ |" << endl; cout << " | |" << endl; cout << " | @ @ |" << endl; cout << " |_________|" << endl; spot+=4; if(spot>=50){ spot-=spot; cout<<player<<" landed on "<<spot<<endl; } else if(spot==9||spot==17||spot==32||spot==35||spot==47||spot==42||spot==25||spot==49){ cout<<player<<" landed on "<<spot<<endl; coinplus(Adder); } else if(spot==SpotNumber){ cout<<player<<" landed on "<<spot<<endl; Adder+=1; cout<<"You have "<<starplus(Adder)<<" stars"<<endl; } else{ cout<<player<<" landed on "<<spot<<endl; } } else if (face == 5) { cout << " ___________" << endl; cout << " | |" << endl; cout << " | @ @ | " << endl; cout << " | @ |" << endl; cout << " | @ @ |" << endl; cout << " |_________|" << endl; spot+=5; if(spot>=50){ spot-=spot; cout<<player<<" landed on "<<spot<<endl; } else if(spot==9||spot==17||spot==32||spot==35||spot==47||spot==42||spot==25||spot==49){ cout<<player<<" landed on "<<spot<<endl; coinplus(Adder); } else if(spot==SpotNumber){ cout<<player<<" landed on "<<spot<<endl; Adder+=1; cout<<"You have "<<starplus(Adder)<<" stars"<<endl; } else{ cout<<player<<" landed on "<<spot<<endl; } } else if (face == 6) { cout << " ___________" << endl; cout << " | |" << endl; cout << " | @ @ | " << endl; cout << " | @ @ |" << endl; cout << " | @ @ |" << endl; cout << " |_________|" << endl; spot+=6; if(spot>=50){ spot-=spot; cout<<player<<" landed on "<<spot<<endl; } else if(spot==9||spot==17||spot==32||spot==35||spot==47||spot==42||spot==25||spot==49){ cout<<player<<" landed on "<<spot<<endl; coinplus(Adder); } else if(spot==SpotNumber){ cout<<player<<" landed on "<<spot<<endl; Adder+=1; cout<<"You have "<<starplus(Adder)<<" stars"<<endl; } else{ cout<<player<<" landed on "<<spot<<endl; } } } }; int main() { int Score1=0; //this will be used in parameter of dice for star count of plyr 1 int Score2=0; //this will be used in parameter of dice for star count of plyr 2 Tools ToolsObject; beginning: //If user would like to play again, they will start back at beginning cout<<"Plyr 1: Choose character from character list below\n"; string ChaList[9]={"Mario ", "Luigi ","Peach ","Daisy ","Wario ","Waluigi ","Bowser ","Toad ","Yoshi"}; for(int i=0; i<9; i++){ cout<<ChaList[i]; } cout<<endl; //Displays player options for user1 string Plyr1; cin>>Plyr1; cout<<"You chose "<<Plyr1<<endl; //Allows user to choose character and saves it in variable called Plyr1 cout<<"Plyr 2: Choose character from character list below\n"; for(int i=0; i<9; i++){ cout<<ChaList[i]; } cout<<endl; //Displays player options for user2 string Plyr2; cin>>Plyr2; cout<<"You chose "<<Plyr2<<endl; //Allows user to choose character and saves it in variable called Plyr2 int StarNums=0; int StarNums2=0; ChooseAmountofStars(StarNums); //sets amount of stars to be found in order to win game. Parameter changes values the variable globally. it is set by reference. int position=PlaceStars(); //Puts position of star from PlaceStars function into a variable that is local to main cout<<"The star is placed at spot: "<<position<<endl; int turn; turn = WhoGoesFirst(); //Put the turn from WhoGoesFirst function into a variable that is local to main bool GameIsPlaying=true; while(GameIsPlaying==true){ if(turn==1){ ToolsObject.Dice(Plyr1, Score1); if(Winner(Score1,StarNums)){ cout<<"Hurray you win"<<endl; GameIsPlaying=false; } else{ turn=2; } } else{ ToolsObject.Dice(Plyr2, Score2); if(Winner(Score2,StarNums2)){ cout<<"Hurray you win"<<endl; GameIsPlaying=false;} else{ turn=1; } } } string desision; while(desision!="y" || desision!="n" ){ cout<<"Would you like to play again? (y or n)"<<endl; cin>>desision; if(desision=="y"){ cout<<"Get ready"<<endl; goto beginning; } else if(desision=="n"){ cout<<"Enjoy the rest of the day"<<endl; } else{ cout<<"Not a valid choice"<<endl; } } } #包括 #包括 #包括 #包括 #包括 #包括 使用名称空间std; 无效选择星山(整数和星号) { //获取将出现在游戏中的星星数 库塔数; cout,c++,C++,这里有很多问题,其中一个问题是您需要这个函数 void Dice(string player, int Adder) 更改此处传递给它的加法器的值 ToolsObject.Dice(Plyr1, Score1); 这不会在传递值时更改Score1。如果希望它更改参数,则应实际返回值或使用引用或指针参数。 因此,当代码到达这一行时 if(Winner(Score1,StarNums)){ cout<<"Hurray you win"<<endl; Gam

这里有很多问题,其中一个问题是您需要这个函数

void Dice(string player, int Adder)
更改此处传递给它的
加法器的值

ToolsObject.Dice(Plyr1, Score1);
这不会在传递值时更改
Score1
。如果希望它更改参数,则应实际返回值或使用引用或指针参数。 因此,当代码到达这一行时

if(Winner(Score1,StarNums)){
    cout<<"Hurray you win"<<endl;
    GameIsPlaying=false;
}
这总是正确的


如果您自学如何正确使用调试器,您将能够比在此处发布问题所需的时间更快地识别此类问题。

此处存在许多问题,其中之一就是您希望使用此函数

void Dice(string player, int Adder)
更改此处传递给它的
加法器的值

ToolsObject.Dice(Plyr1, Score1);
这不会在传递值时更改
Score1
。如果希望它更改参数,则应实际返回值或使用引用或指针参数。 因此,当代码到达这一行时

if(Winner(Score1,StarNums)){
    cout<<"Hurray you win"<<endl;
    GameIsPlaying=false;
}
这总是正确的


如果您自学如何正确使用调试器,您将能够比在此处发布问题所需的时间更快地识别此类问题。

此处存在许多问题,其中之一就是您希望使用此函数

void Dice(string player, int Adder)
更改此处传递给它的
加法器的值

ToolsObject.Dice(Plyr1, Score1);
这不会在传递值时更改
Score1
。如果希望它更改参数,则应实际返回值或使用引用或指针参数。 因此,当代码到达这一行时

if(Winner(Score1,StarNums)){
    cout<<"Hurray you win"<<endl;
    GameIsPlaying=false;
}
这总是正确的


如果您自学如何正确使用调试器,您将能够比在此处发布问题所需的时间更快地识别此类问题。

此处存在许多问题,其中之一就是您希望使用此函数

void Dice(string player, int Adder)
更改此处传递给它的
加法器的值

ToolsObject.Dice(Plyr1, Score1);
这不会在传递值时更改
Score1
。如果希望它更改参数,则应实际返回值或使用引用或指针参数。 因此,当代码到达这一行时

if(Winner(Score1,StarNums)){
    cout<<"Hurray you win"<<endl;
    GameIsPlaying=false;
}
这总是正确的


太长了,读不下去了,太长了,读不下去了。太长了,读不下去了,太长了,读不下去了。让我们看看。