1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
|
#include <iomanip>
#include "TrivialGame.h"
void questionAnswers(question i[], int, string, string, string, string);
int main()
{
char response, start;
do
{
question Game[10];
int count = 0;
int player1Choice, player2Choice; // Holds the player's answers.
int player1Points = 0, player2Points = 0; // Holds the player's total points.
// Describe the game to the user.
cout << "Welcome to:" << endl << endl;
cout << "-------------the FANTABULOUS TRIVIA GAME!-------------" << endl << endl;
cout << "This is the TWO PLAYER GAME where you will be challenged by TRIVIA QUESTIONS!" << endl;
cout << "You will be asked a total of 10 questions." << endl;
cout << "First one to get them all right with the most points WINS!" << endl << endl;
// Ask the user if they would like to start the game.
cout << "Ready to start?" << endl;
cout << "Please type 'Y' or 'y' for YES." << endl;
cout << "Alternatively type 'N' or 'n' for NO." << endl;
cin >> start;
// If loop to start the game.
if(start == 'Y' || start == 'y')
{
// First question.
Game[0].setQuestions("What is the capital of New Jersey?");
Game[0].setAnswer1("1. Alaska");
Game[0].setAnswer2("2. Toronto");
Game[0].setAnswer3("3. applesauce");
Game[0].setAnswer4("4. Trenton");
Game[0].setCorrectAnswer(4);
// Second question.
Game[1].setQuestions("What is America's favorite past time?");
Game[1].setAnswer1("1. War");
Game[1].setAnswer2("2. Football");
Game[1].setAnswer3("3. Baseball");
Game[1].setAnswer4("4. Soccer");
Game[1].setCorrectAnswer(3);
// Third question.
Game[2].setQuestions("What makes the grass green?");
Game[2].setAnswer1("1. Green");
Game[2].setAnswer2("2. Chlorophyll");
Game[2].setAnswer3("3. Germs");
Game[2].setAnswer4("4. Yellow");
Game[2].setCorrectAnswer(2);
// Fourth question.
Game[3].setQuestions("What year did Germany invade Poland at the start of WW2?");
Game[3].setAnswer1("1. 1939");
Game[3].setAnswer2("2. 1856");
Game[3].setAnswer3("3. 1400");
Game[3].setAnswer4("4. 1946");
Game[3].setCorrectAnswer(1);
// Fifth question.
Game[4].setQuestions("What is the eight planet of the solar system?");
Game[4].setAnswer1("1. Mars");
Game[4].setAnswer2("2. Jupiter");
Game[4].setAnswer3("3. Poseidon");
Game[4].setAnswer4("4. Neptune");
Game[4].setCorrectAnswer(4);
// Sixth question.
Game[5].setQuestions("Which famous superhero was from the planet Krypton?");
Game[5].setAnswer1("1. Batman");
Game[5].setAnswer2("2. Deadpool");
Game[5].setAnswer3("3. Superman");
Game[5].setAnswer4("4. Wolverine");
Game[5].setCorrectAnswer(3);
// Seventh question.
Game[6].setQuestions("What 2010 film had to do with entering people's dreams?");
Game[6].setAnswer1("1. Shutter Island");
Game[6].setAnswer2("2. Hugo");
Game[6].setAnswer3("3. The Matrix");
Game[6].setAnswer4("4. Inception");
Game[6].setCorrectAnswer(4);
// Eighth question.
Game[7].setQuestions("What is 44 divided by 4");
Game[7].setAnswer1("1. 11");
Game[7].setAnswer2("2. 89");
Game[7].setAnswer3("3. 6");
Game[7].setAnswer4("4. 7");
Game[7].setCorrectAnswer(1);
// Ninth question.
Game[8].setQuestions("When is Independence Day?");
Game[8].setAnswer1("1. February 27");
Game[8].setAnswer2("2. July 4");
Game[8].setAnswer3("3. May 5");
Game[8].setAnswer4("4. July 2");
Game[8].setCorrectAnswer(2);\
// Tenth question.
Game[9].setQuestions("What is the Law of Conservation of Energy?");
Game[9].setAnswer1("1. That energy can be created, but not destroyed.");
Game[9].setAnswer2("2. That energy is simply an illsuion.");
Game[9].setAnswer3("3. That energy cannot be created nor destroyed.");
Game[9].setAnswer4("4. That energy cannot be created, but can be destroyed.");
Game[9].setCorrectAnswer(2);
// While loop for the actual game.
while(count < 9)
{
cout << setw(10) << "Question #" << (count + 1) << "." << endl;
questionAnswers(Game, count, answer1, answer2, answer3, answer4);
cout << "Player 1 Answer: ";
cin >> player1Choice;
cout << "Player 2 Answer: ";
cin >> player2Choice;
// If Player 1 is right, they get a point.
if(Game[count].getCorrectAnswer() == player1Choice)
{
player1Points++;
}
// If Player 2 is right, they get a point.
if(Game[count].getCorrectAnswer() == player2Choice)
{
player2Points++;
}
count++;
}
// If loops to determine who wins.
if (player1Points > player2Points)
{
cout << "Player 1 WINS!" << endl;
cout << "Congratulations Player 1!!" << endl;
}
if (player1Points < player2Points)
{
cout << "Player 2 WINS!" << endl;
cout << "Congratulations Player 2!!" << endl;
}
if (player1Points == player2Points)
{
cout << "Player 1 and Player 2 are now tied!" << endl;
cout << "You both LOST!!" << endl;
}
}
else if(start == 'n' || start == 'N')
{
cout << "Thanks for your participation in the FANTABULUS TRIVIA GAME!" << endl;
}
// Ask the user if they would like to rerun the program.
cout << endl << "\nWould you like to run the program again?" << endl;
cin >> response;
cout << endl;
}
while (response == 'y' || response == 'Y');
return 0;
}
void questionAnswers(question i[], int count, string answer1, string answer2, string answer3, string answer4)
{
cout << i[count].getQuestions() << endl;
cout << i[count].getAnswer1(answer1) << endl;
cout << i[count].getAnswer2(answer2) << endl;
cout << i[count].getAnswer3(answer3) << endl;
cout << i[count].getAnswer4(answer4) << endl << endl;
}
|