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
|
#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>
#include <vector>
using namespace std;
ifstream fIn;
ifstream Gamefile;
ofstream fOut;
int menu();
int Clist ();
int menuOpt;
void game ();
vector<string> fileName;
int main()
{
menu();
}
int menu()
{
char inp;
do
{
cout << "Please chose from the following options" <<endl;
cout << "A: Load Trivia type." <<endl;
cout << "B: Start Game." <<endl;
cout << "C: Exit Game" <<endl;
cin >> inp;
string bt;
switch(inp)
{
case 'A': case 'a':
Clist();
break;
case 'B': case 'b':
game();
break;
case 'C': case 'c':
return 0;
break;
default:
cout << "error that is not an option\n Press enter to continue " << endl;
cin.get();
cin.get();
system("cls");
break;
}}while(inp != 'c');
}
int Clist()
{
vector<string> triviaName;
string input;
int a, b, c, d;
fIn.open("list.csv");
a = 0;
while(!fIn.eof())
{
getline( fIn, input, ',' );
triviaName.push_back(input);
getline( fIn, input);
fileName.push_back(input);
a++;
fileName.resize(a);
triviaName.resize(a);
}
c = 0;
for(b = 1; b < a; b++)
{
cout << "option# "<< c << ": " << triviaName[c] << endl;
c++;
}
cout << "Please Enter your option: ";
cin >> d;
fIn.close();
fIn.clear();
system("cls");
return d;
}
//Problem Should be in this function.
void game()
{ vector<string> PlayerID;
string input;
int PlayerNumber, counter, PlayerCount, GamePlay, vectorSize, vectorCounter, a;
cout << " How many Players will be playing? ";
cin >> counter;
cout << endl;
PlayerCount = 0;
for (PlayerNumber = 1; PlayerNumber <= counter; PlayerNumber++)
{
system("cls");
cout << " Please enter name for player " << PlayerNumber << endl;
cin >> input;
PlayerID.push_back(input);
PlayerCount++;
PlayerID.resize(PlayerCount);
}
GamePlay = Clist();
//decla ration for vectors that will parce the game csv file
vector<string> question;
vector<string> Awns_A;
vector<string> Awns_B;
vector<string> Awns_C;
vector<string> Awns_Correct;
Gamefile.open(fileName[GamePlay].c_str());
vectorSize = 1;
while(!Gamefile.eof())
{
getline( Gamefile, input, ',' );
question.push_back(input);
getline( Gamefile, input, ',' );
Awns_A.push_back(input);
getline( Gamefile, input, ',' );
Awns_B.push_back(input);
getline( Gamefile, input, ',' );
Awns_C.push_back(input);
getline( Gamefile, input);
Awns_Correct.push_back(input);
vectorSize++;
question.resize(vectorSize);
Awns_A.resize(vectorSize);
Awns_B.resize(vectorSize);
Awns_C.resize(vectorSize);
Awns_Correct.resize(vectorSize);
}
Gamefile.close();
Gamefile.clear();
vectorCounter = 0;
/*this will need to be put in a nested loop to give each player a chance respond to the question*/
for (PlayerNumber = 0; PlayerNumber <= PlayerCount; PlayerNumber++)
{
cout << PlayerID[PlayerNumber] << endl
<< question[vectorCounter] << endl
<< " Option A:" << Awns_A[vectorCounter] << endl
<< " Option B:" << Awns_B[vectorCounter] << endl
<< " Option C:" << Awns_C[vectorCounter] << endl;
cin.get();
cin.get();
PlayerCount++;
}
}
|