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 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
|
/*
//Crypto Guess is based off of Crypto Logic for the Oddessy 2
//Created Tuesday, June 4th 2013 by Chay Hawk
*/
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <cstdlib>
#include <fstream>
#include <vector>
#include <time.h>
using std::cout;
using std::cin;
using std::endl;
using std::string;
using std::ifstream;
using std::ofstream;
using std::vector;
using std::fstream;
string word_list(string GL)
{
string store_word;
vector<string> words;
srand(time(0));
ifstream fileIn;
fileIn.open(GL.c_str());
if(fileIn.fail())
{
cout << "File failed to open." << endl;
}
while(!fileIn.eof())
{
/*not needed as vectors resize themselves
if(words.size() == words.capacity())
{
words.reserve(words.size() * 3);
}
*/
fileIn >> store_word;
words.push_back(store_word);
}
fileIn.close();
return words[rand() % words.size()];
}
void save_game(int save_rightGuesses,
int save_wrongGuesses,
string save_list_type,
time_t save_hours_playtime,
time_t save_minutes_playtime,
time_t save_seconds_playtime
)
{
time_t current = time(0);
ofstream fileOut;
fileOut.open("Scores.txt", fstream::app);
fileOut << "CRYPTO GUESS SCORES FOR " << ctime(¤t) << endl;
fileOut << "From list: " << save_list_type << endl;
fileOut << "Right Guesses: " << save_rightGuesses << endl;
fileOut << "Wrong Guesses: " << save_wrongGuesses << "\n" << endl;
fileOut << "Your Play Time is " << save_hours_playtime << " Hours " << save_minutes_playtime << " Minutes " << save_seconds_playtime << " Seconds\n" << endl;
fileOut.close();
}
int main()
{
srand(time(0));
string original_word,
shuffled_word,
random_word,
choose_list,
guess,
custom_word,
copy_custom_word,
guess_custom_word;
int guess_number = 1,
right_guesses = 0,
wrong_guesses = 0,
select = 0;
bool game1_loop = true,
game2_loop = true,
choice_loop = true;
cout << "CRYPTO GUESS" << endl;
cout << "Version 2.3\n" << endl;
cout << "Do you want to enter words yourself or have the computer give you words?" << endl;
cout << "1) Enter words myself" << endl;
cout << "2) Have the computer give me words" << endl;
while(cout << "Please make a selection -> " &&
cin >> select && (select<1 || select>2))
{
cin.clear();
cin.ignore(50, '\n');
cout << "That is not a valid selection." << endl;
}
/*
while(choice_loop)
{
cin >> select;
switch(select)
{
case 1:
break;
case 2:
break;
default:
cout << "Not a valid input" << endl;
}
}
*/
cin.ignore(50, '\n');
cout << '\n';
if(select == 1)
{
while(game1_loop)
{
cout << "Enter your word" << endl;
getline(cin, custom_word);
copy_custom_word = custom_word;
random_shuffle(custom_word.begin(), custom_word.end());
cout << string(55, '\n');
cout << "The word is " << custom_word << endl;
cout << "Your guess is: ";
cin >> guess_custom_word;
if(guess_custom_word == copy_custom_word)
{
cout << "Thats correct!" << endl;
guess_custom_word = " ";
break;
}
}
}
if(select == 2)
{
time_t startTime = time(0);
cout << "Select list" << endl;
getline(cin, choose_list);
while(game2_loop)
{
string HWLF = word_list(choose_list);
shuffled_word = HWLF;
random_shuffle(shuffled_word.begin(), shuffled_word.end());//#1
cout << "----------------------------------------------------" << endl;
cout << "|| Guess # " << guess_number << " || Right Guesses: " <<
right_guesses << " || Wrong Guesses: " << wrong_guesses << endl;
cout << "----------------------------------------------------\n" << endl;
cout << "Word: " << shuffled_word << endl;
cout << '\n';
while(guess != HWLF)
{
cout << "Your guess: ";
cin >> guess;
if(guess == HWLF)
{
cout << "Is correct!\n" << endl;
guess = " ";
guess_number++;
right_guesses++;
break;
}
else if(guess == "Quit" || guess == "quit")
{
cout << "Goodbye thanks for playing." << endl;
time_t endTime = time(0),
playTime = endTime - startTime,
hoursTime = playTime / 3600,
minutesTime = (playTime / 60) % 60,
secondsTime = playTime % 60;
save_game(right_guesses,
wrong_guesses,
choose_list,
hoursTime,
minutesTime,
secondsTime);
game2_loop = false;
return 0;
}
if(guess == "Skip" || guess == "skip")
{
cout << "You skipped the word." << endl;
cout << "The correct word was " << HWLF << endl;
cout << '\n';
wrong_guesses++;
break;
}
else
{
wrong_guesses++;
cout << "Is wrong! Try again\n" << endl;
}
}
}//End of game while loop
}//End of if statement
}
|