I'm having trouble with a couple of things in my program.
I want to create 3 different players and then record their scores to a file called highScores.txt
I need to also come up with another game that features an array in it (i would put this in the place that says //ARRAY GAME WITH point values here)...this game should just like the other two games have point values.
Also, I tried creating one of the players and I get a compiling error that says:
project2.cpp:131: error: ‘x’ was not declared in this scope
project2.cpp:169: error: ‘x’ was not declared in this scope
project2.cpp:238: error: ‘x’ was not declared in this scope
project2.cpp:276: error: ‘x’ was not declared in this scope
project2.cpp:344: error: ‘x’ was not declared in this scope
project2.cpp:382: error: ‘x’ was not declared in this scope
project2.cpp:448: error: ‘x’ was not declared in this scope
project2.cpp:484: error: ‘x’ was not declared in this scope
project2.cpp:552: error: ‘x’ was not declared in this scope
project2.cpp:590: error: ‘x’ was not declared in this scope
project2.cpp:655: error: ‘x’ was not declared in this scope
project2.cpp:693: error: ‘x’ was not declared in this scope
project2.cpp: In function ‘void getPlayerInfo(Player&)’:
project2.cpp:869: error: invalid conversion from ‘void’ to ‘char’
project2.cpp:869: error: cannot convert ‘double’ to ‘size_t*’ for argument ‘2’ to ‘__ssize_t getline(char, size_t, FILE*)’
I'm not sure how to do this and I'm very new to c++.
If anyone could help me I would appreciate it.
(sorry for the lengthyness)
This is my code:
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <string>
#include <ctime>
#include <iomanip>
using namespace std;
struct Player{
string name;
double score;
};
void displayMenu();
void getChoice(int & );
void displayRules();
void displayPlaceMenu();
void getPlace(int &);
void displayCharacterMenu();
void getCharacter(int & );
void displayWeaponMenu();
void getWeapon(int &);
void getPlayerInfo( Player & );
void displayPlayerInfo( Player );
void writePlayerInfoToFile();
int main()
{
int choice, place, person, weapon, random;
string name;
double score;
char PLAY;
Player aPlayer;
getPlayerInfo(aPlayer);
displayPlayerInfo(aPlayer);
do
{
displayMenu();
getChoice(choice);
switch (choice)
{
case 1:
displayRules();
break;
case 2:
displayPlaceMenu();
getPlace(place);
displayCharacterMenu();
getCharacter(person);
displayWeaponMenu();
getWeapon(weapon);
cout <<"*_*_**_*_**_*_**_*_**_*_**_*_**_*_*"<< endl;
cout <<"Processing your choices..." << endl;
cout <<"You're adventure is now created..." << endl;
cout <<" _( )_ "<<endl;
cout <<" (_ O _) "<<endl;
cout <<" (_) "<<endl;
cout <<"*_*_**_*_**_*_**_*_**_*_**_*_**_*_*"<< endl;
//GAME WITH HUMAN AT ATLANTIS
if (place==1) {
if (person==1) {
if (weapon==1 || weapon ==2) {
cout << "Now traveling to Atlantis..." << endl;
cout << "You can now breathe underwater." << endl;
cout << " o " << endl;
cout << " o " << endl;
cout << " O " << endl;
cout << " ~|~ " << endl;
cout << " }{ " << endl;
//ARRAY GAME HERE with POINT VALUES
cout << " o " <<endl;
cout << " ___.. , " <<endl;
cout << " __..--''__ ( .'; " <<endl;
cout << " o __.-------.-' `--..__ .' ; " <<endl;
cout << " _.--' 0) .--._ ``--...____.' .' " <<endl;
cout << " ( _. )). .__.-'' < " <<endl;
cout << " `````---....._____.....- -..___ _____...--'-.'. " <<endl;
cout << " `-.___.' ``````` `.; " <<endl;
cout << " ` " <<endl;
cout << "--------------------------------------" << endl;
cout << "You swim to the underwater castle and find an" <<endl;
cout << "angry shark coming towards you." <<endl;
cout << "It's time for you to use your weapon and find out your skill... "<<endl;
cout << "~~***~~***~~***~~~***~~~***~~~***~~~***~~~~****~~~~~~***~~~~***~~"<<endl;
cout << "Now generating random fate with weapon..."<<endl;
cout << "Processing..." << endl;
//HUMAN WITH BOW AND ARROW OR SPEAR GAME
srand(time(NULL));
random = rand() % 4 + 1;
cout << "Your number is " << random << endl;
cout << "That means that...\n" << endl;
switch(random) {
case 1: random = 100;
cout << "Good job! The shark is hit in the tail and swam away...\n" << endl;
break;
case 2: random = 200;
cout << "Good job! The shark is hit in the fin and swims away...\n" << endl;
break;
case 3: random = 300;
cout << "Good job! The shark is hit in the nose and swam away...\n" << endl;
break;
default: random = 0;
cout << "Too bad. No target is hit...\n" << endl;
cout << "Since you didn't defeat the shark, the shark eats you...\n" << endl;
}
score=random+100;
cout << "Congrats! Your score is: \n" << getline(cin, x.score) << endl;
cout << "Please enter your name: " << endl;
getline(cin, x.name);
getPlayerInfo(aPlayer);
displayPlayerInfo(aPlayer);
writePlayerInfoToFile();
}
else{
//HUMAN WITH MAGIC GAME
cout << "Now traveling to Atlantis..." << endl;
cout << "You can now breathe underwater." << endl;
cout << " o " << endl;
cout << " o " << endl;
cout << " O " << endl;
cout << " ~|~ " << endl;
cout << " }{ " << endl;
srand(time(NULL));
random = rand() % 2 + 1;
cout << ".::**::..::**::..::**::..::**::..::**::...::**::...::**::...::**::...::**::...::**::." << endl;
cout << "A sea witch lures you into her lair and teaches you" << endl;
cout << "how to make potions. If you are succesful you will return to a normal human." << endl;
cout << "If not you will remain a mermaid and be trapped underwater forever."<<endl;
cout << "It's time to test your potion making skills! \n" << endl;
cout << "Now we will determine whether or not your potion is a success or failure...:"<<endl;
cout << ".::**::..::**::..::**::..::**::..::**::...::**::...::**::...::**::...::**::...::**::.\n" << endl;
cout << "Processing....."<<endl;
switch(random) {
case 1: random = -100;
cout << "Sorry, your potion is a failure...\n" << endl;
break;
default: random = 200;
cout << "Your potion is a success! \n" << endl;
}
score = random + 100;
cout << "Congrats! Your score is: \n" << getline(cin, x.score) << endl;
cout << "Please enter your name: " << endl;
getline(cin, x.name);
getPlayerInfo(aPlayer);
displayPlayerInfo(aPlayer);
writePlayerInfoToFile();
}
}
}
//GAME WITH ORC AT ATLANTIS
//ARRAY GAME HERE with POINT VALUES
if (place==1) {
if (person==2) {
if (weapon==1 || weapon ==2) {
cout << "Now traveling to Atlantis..." << endl;
cout << "You can now breathe underwater." << endl;
cout << " o " << endl;
cout << " o " << endl;
cout << " O " << endl;
cout << " ~|~ " << endl;
cout << " }{ " << endl;
//ARRAY GAME HERE with POINT VALUES
cout << " o " <<endl;
cout << " ___.. , " <<endl;
cout << " __..--''__ ( .'; " <<endl;
cout << " o __.-------.-' `--..__ .' ; " <<endl;
cout << " _.--' 0) .--._ ``--...____.' .' " <<endl;
cout << " ( _. )). .__.-'' < " <<endl;
cout << " `````---....._____.....- -..___ _____...--'-.'. " <<endl;
cout << " `-.___.' ``````` `.; " <<endl;
cout << " ` " <<endl;
cout << "--------------------------------------" << endl;
cout << "You swim to the underwater castle and find an" <<endl;
cout << "angry shark coming towards you." <<endl;
cout << "It's time for you to use your weapon and find out your skill... "<<endl;
cout << "~~***~~***~~***~~~***~~~***~~~***~~~***~~~~****~~~~~~***~~~~***~~"<<endl;
cout << "Now generating random fate with weapon..."<<endl;
cout << "Processing..." << endl;
srand(time(NULL));
random = rand() % 4 + 1;
cout << "Your number is " << random << endl;
cout << "That means that...\n" << endl;
switch(random) {
case 1: random = 100;
cout << "Good job! The shark is hit in the tail and swam away...\n" << endl;
break;
case 2: random = 200;
cout << "Good job! The shark is hit in the fin and swims away...\n" << endl;
break;
case 3: random = 300;
cout << "Good job! The shark is hit in the nose and swam away...\n" << endl;
break;
default: random = 0;
cout << "Too bad. No target is hit...\n" << endl;
cout << "Since you didn't defeat the shark, the shark eats you...\n" << endl;
}
score=random+100;
cout << "Congrats! Your score is: \n" << getline(cin, x.score) << endl;
cout << "Please enter your name: " << endl;
getline(cin, x.name);
getPlayerInfo(aPlayer);
displayPlayerInfo(aPlayer);
writePlayerInfoToFile();
}
else{
cout << "Now traveling to Atlantis..." << endl;
cout << "You can now breathe underwater." << endl;
cout << " o " << endl;
cout << " o " << endl;
cout << " O " << endl;
cout << " ~|~ " << endl;
cout << " }{ " << endl;
srand(time(NULL));
random = rand() % 2 + 1;
cout << ".::**::..::**::..::**::..::**::..::**::...::**::...::**::...::**::...::**::...::**::." << endl;
cout << "A sea witch lures you into her lair and teaches you" << endl;
cout << "how to make potions. If you are succesful you will return to a normal human." << endl;
cout << "If not you will remain a mermaid and be trapped underwater forever."<<endl;
cout << "It's time to test your potion making skills! \n" << endl;
cout << "Now we will determine whether or not your potion is a success or failure...:"<<endl;
cout << ".::**::..::**::..::**::..::**::..::**::...::**::...::**::...::**::...::**::...::**::.\n" << endl;
cout << "Processing....."<<endl;
switch(random) {
case 1: random = -100;
cout << "Sorry, your potion is a failure...\n" << endl;
break;
default: random = 200;
cout << "Your potion is a success! \n" << endl;
}
score = random + 100;
cout << "Congrats! Your score is: \n" << getline(cin, x.score) << endl;
cout << "Please enter your name: " << endl;
getline(cin, x.name);
getPlayerInfo(aPlayer);
displayPlayerInfo(aPlayer);
writePlayerInfoToFile();
}
}
}
//GAME WITH ELF AT ATLANTIS WITH BOW ARROW OR SPEAR
//ARRAY GAME HERE with POINT VALUES
if (place==1) {
if (person==3) {
if (weapon==1 || weapon ==2) {
cout << "Now traveling to Atlantis..." << endl;
cout << "You can now breathe underwater." << endl;
cout << " o " << endl;
cout << " o " << endl;
cout << " O " << endl;
cout << " ~|~ " << endl;
cout << " }{ " << endl;
//ARRAY GAME HERE with POINT VALUES
cout << " o " <<endl;
cout << " ___.. , " <<endl;
cout << " __..--''__ ( .'; " <<endl;
cout << " o __.-------.-' `--..__ .' ; " <<endl;
cout << " _.--' 0) .--._ ``--...____.' .' " <<endl;
cout << " ( _. )). .__.-'' < " <<endl;
cout << " `````---....._____.....- -..___ _____...--'-.'. " <<endl;
cout << " `-.___.' ``````` `.; " <<endl;
cout << " ` " <<endl;
cout << "--------------------------------------" << endl;
cout << "You swim to the underwater castle and find an" <<endl;
cout << "angry shark coming towards you." <<endl;
cout << "It's time for you to use your weapon and find out your skill... "<<endl;
cout << "~~***~~***~~***~~~***~~~***~~~***~~~***~~~~****~~~~~~***~~~~***~~"<<endl;
cout << "Now generating random fate with weapon..."<<endl;
cout << "Processing..." << endl;
srand(time(NULL));
random = rand() % 4 + 1;
cout << "Your number is " << random << endl;
cout << "That means that...\n" << endl;
switch(random) {
case 1: random = 100;
cout << "Good job! The shark is hit in the tail and swam away...\n" << endl;
break;
case 2: random = 200;
cout << "Good job! The shark is hit in the fin and swims away...\n" << endl;
break;
case 3: random = 300;
cout << "Good job! The shark is hit in the nose and swam away...\n" << endl;
break;
default: random = 0;
cout << "Too bad. No target is hit...\n" << endl;
cout << "Since you didn't defeat the shark, the shark eats you...\n" << endl;
}
score=random+100;
cout << "Congrats! Your score is: \n" << getline(cin, x.score) << endl;
cout << "Please enter your name: " << endl;
getline(cin, x.name);
getPlayerInfo(aPlayer);
displayPlayerInfo(aPlayer);
writePlayerInfoToFile();
}
else{
cout << "Now traveling to Atlantis..." << endl;
cout << "You can now breathe underwater." << endl;
cout << " o " << endl;
cout << " o " << endl;
cout << " O " << endl;
cout << " ~|~ " << endl;
cout << " }{ " << endl;
srand(time(NULL));
random = rand() % 2 + 1;
cout << ".::**::..::**::..::**::..::**::..::**::...::**::...::**::...::**::...::**::...::**::." << endl;
cout << "A sea witch lures you into her lair and teaches you" << endl;
cout << "how to make potions. If you are succesful you will return to a normal human." << endl;
cout << "If not you will remain a mermaid and be trapped underwater forever."<<endl;
cout << "It's time to test your potion making skills! \n" << endl;
cout << "Now we will determine whether or not your potion is a success or failure...:"<<endl;
cout << ".::**::..::**::..::**::..::**::..::**::...::**::...::**::...::**::...::**::...::**::.\n" << endl;
cout << "Processing....."<<endl;
switch(random) {
case 1: random = -100;
cout << "Sorry, your potion is a failure...\n" << endl;
break;
default: random = 200;
cout << "Your potion is a success! \n" << endl;
}
score = random + 100;
cout << "Congrats! Your score is: \n" << getline(cin, x.score) << endl;
cout << "Please enter your name: " << endl;
getline(cin, x.name);
getPlayerInfo(aPlayer);
displayPlayerInfo(aPlayer);
writePlayerInfoToFile();
}
}
}
//GAME WITH HUMAN AT PARADISE ISLAND
if (place==2) {
if (person==1) {
if (weapon==1 || weapon ==2) {
cout << "Now traveling to Paradise Island..." << endl;
cout << "You arrive to a remote island." << endl;
cout << " _//_ " <<endl;
cout << " /o\\ o/ " <<endl;
cout << " | /| " <<endl;
cout << " _|___ /_|_________ " <<endl;
//ARRAY GAME HERE with POINT VALUES
cout << " _ _ "<< endl;
cout << " _ _ (0)(0)-._ _.-'^^'^^'^^'^^'^^'--. "<< endl;
cout << " (.(.)----'` ^^' /^ ^^-. "<< endl;
cout << " ( ` | | _ ^^-. "<< endl;
cout << " VvvvvvvVv~~`__,-.._> |:|:|:|:|:|:|:| (_..,______^^-. "<< endl;
cout << " `^^^^^^^^`/ / / /`^^^^^^^^^>^^>^`> > _`) ) "<< endl;
cout << " (((` (((` (((` (((` `'--'^ "<< endl;
cout << "--------------------------------------" << endl;
cout << "You walk over to a nearby tree and find an" <<endl;
cout << "angry gator coming towards you." <<endl;
cout << "It's time for you to use your weapon and find out your skill... "<<endl;
cout << "~~***~~***~~***~~~***~~~***~~~***~~~***~~~~****~~~~~~***~~~~***~~"<<endl;
cout << "Now generating random fate with weapon..."<<endl;
cout << "Processing..." << endl;
//HUMAN WITH BOW AND ARROW OR SPEAR GAME
srand(time(NULL));
random = rand() % 4 + 1;
cout << "Your number is " << random << endl;
cout << "That means that...\n" << endl;
switch(random) {
case 1: random = 100;
cout << "Good job! The gator is hit in the tail and runs away...\n" << endl;
break;
case 2: random = 200;
cout << "Good job! The gator is hit in the body and runs away...\n" << endl;
break;
case 3: random = 300;
cout << "Good job! The gator is hit in the head and runs away...\n" << endl;
break;
default: random = 0;
cout << "Too bad. No target is hit...\n" << endl;
cout << "Since you didn't defeat the gator, the gator eats you... \n" << endl;
}
score=random+100;
cout << "Congrats! Your score is: \n" << score << endl;
cout << "Please enter your name: " << endl;
getline(cin, x.name);
getPlayerInfo(aPlayer);
displayPlayerInfo(aPlayer);
writePlayerInfoToFile();
}
else{
//HUMAN WITH MAGIC GAME
cout << "Now traveling to Paradise Island..." << endl;
cout << "You arrive to a remote island." << endl;
cout << " _//_ " <<endl;
cout << " /o\\ o/ " <<endl;
cout << " | /| " <<endl;
cout << " _|___ /_|_________ " <<endl;
srand(time(NULL));
random = rand() % 2 + 1;
cout << ".::**::..::**::..::**::..::**::..::**::...::**::...::**::...::**::...::**::...::**::." << endl;
cout << "An islander lures you into her cave and teaches you" << endl;
cout << "how to make potions. If you are succesful you will return home." << endl;
cout << "If not you will remain on this island forever."<<endl;
cout << "It's time to test your potion making skills! \n" << endl;
cout << "Now we will determine whether or not your potion is a success or failure...:"<<endl;
cout << ".::**::..::**::..::**::..::**::..::**::...::**::...::**::...::**::...::**::...::**::.\n" << endl;
cout << "Processing....."<<endl;
switch(random) {
case 1: random = -100;
cout << "Sorry, your potion is a failure...\n" << endl;
break;
default: random = 200;
cout << "Your potion is a success! \n" << endl;
}
score = random + 100;
cout << "Congrats! Your score is: \n" << getline(cin, x.score) << endl;
cout << "Please enter your name: " << endl;
getline(cin, x.name);
getPlayerInfo(aPlayer);
displayPlayerInfo(aPlayer);
writePlayerInfoToFile();
}
}
}
//GAME WITH ORC AT PARADISE ISLAND
//ARRAY GAME HERE with POINT VALUES
if (place==2) {
if (person==2) {
if (weapon==1 || weapon ==2) {
cout << "Now traveling to Paradise Island..." << endl;
cout << "You arrive to a remote island." << endl;
cout << " _//_ " <<endl;
cout << " /o\\ o/ " <<endl;
cout << " | /| " <<endl;
cout << " _|___ /_|_________ " <<endl;
//ARRAY GAME HERE with POINT VALUES
cout << " _ _ "<< endl;
cout << " _ _ (0)(0)-._ _.-'^^'^^'^^'^^'^^'--. "<< endl;
cout << " (.(.)----'` ^^' /^ ^^-. "<< endl;
cout << " ( ` | | _ ^^-. "<< endl;
cout << " VvvvvvvVv~~`__,-.._> |:|:|:|:|:|:|:| (_..,______^^-. "<< endl;
cout << " `^^^^^^^^`/ / / /`^^^^^^^^^>^^>^`> > _`) ) "<< endl;
cout << " (((` (((` (((` (((` `'--'^ "<< endl;
cout << "--------------------------------------" << endl;
cout << "You walk over to a nearby tree and find an" <<endl;
cout << "angry gator coming towards you." <<endl;
cout << "It's time for you to use your weapon and find out your skill... "<<endl;
cout << "~~***~~***~~***~~~***~~~***~~~***~~~***~~~~****~~~~~~***~~~~***~~"<<endl;
cout << "Now generating random fate with weapon..."<<endl;
cout << "Processing..." << endl;
//ORC WITH BOW AND ARROW OR SPEAR GAME
srand(time(NULL));
random = rand() % 4 + 1;
cout << "Your number is " << random << endl;
cout << "That means that...\n" << endl;
switch(random) {
case 1: random = 100;
cout << "Good job! The gator is hit in the tail and runs away...\n" << endl;
break;
case 2: random = 200;
cout << "Good job! The gator is hit in the body and runs away...\n" << endl;
break;
case 3: random = 300;
cout << "Good job! The gator is hit in the head and runs away...\n" << endl;
break;
default: random = 0;
cout << "Too bad. No target is hit...\n" << endl;
cout << "Since you didn't defeat the gator, the gator eats you... \n" << endl;
}
score=random+100;
cout << "Congrats! Your score is: \n" << getline(cin, x.score) << endl;
cout << "Please enter your name: " << endl;
getline(cin, x.name);
getPlayerInfo(aPlayer);
displayPlayerInfo(aPlayer);
writePlayerInfoToFile();
}
else{
//ORC WITH MAGIC GAME
cout << "Now traveling to Paradise Island..." << endl;
cout << "You arrive to a remote island." << endl;
cout << " _//_ " <<endl;
cout << " /o\\ o/ " <<endl;
cout << " | /| " <<endl;
cout << " _|___ /_|_________ " <<endl;
srand(time(NULL));
random = rand() % 2 + 1;
cout << ".::**::..::**::..::**::..::**::..::**::...::**::...::**::...::**::...::**::...::**::." << endl;
cout << "An islander lures you into her cave and teaches you" << endl;
cout << "how to make potions. If you are succesful you will return home." << endl;
cout << "If not you will remain on this island forever."<<endl;
cout << "It's time to test your potion making skills! \n" << endl;
cout << "Now we will determine whether or not your potion is a success or failure...:"<<endl;
cout << ".::**::..::**::..::**::..::**::..::**::...::**::...::**::...::**::...::**::...::**::.\n" << endl;
cout << "Processing....."<<endl;
switch(random) {
case 1: random = -100;
cout << "Sorry, your potion is a failure...\n" << endl;
break;
default: random = 200;
cout << "Your potion is a success! \n" << endl;
}
score = random + 100;
cout << "Congrats! Your score is: \n" << getline(cin, x.score) << endl;
cout << "Please enter your name: " << endl;
getline(cin, x.name);
getPlayerInfo(aPlayer);
displayPlayerInfo(aPlayer);
writePlayerInfoToFile();
}
}
}
//GAME WITH ELF AT PARADISE ISLAND
if (place==2) {
if (person==3) {
if (weapon==1 || weapon ==2) {
cout << "Now traveling to Paradise Island..." << endl;
cout << "You arrive to a remote island." << endl;
cout << " _//_ " <<endl;
cout << " /o\\ o/ " <<endl;
cout << " | /| " <<endl;
cout << " _|___ /_|_________ " <<endl;
//ARRAY GAME HERE with POINT VALUES
cout << " _ _ "<< endl;
cout << " _ _ (0)(0)-._ _.-'^^'^^'^^'^^'^^'--. "<< endl;
cout << " (.(.)----'` ^^' /^ ^^-. "<< endl;
cout << " ( ` | | _ ^^-. "<< endl;
cout << " VvvvvvvVv~~`__,-.._> |:|:|:|:|:|:|:| (_..,______^^-. "<< endl;
cout << " `^^^^^^^^`/ / / /`^^^^^^^^^>^^>^`> > _`) ) "<< endl;
cout << " (((` (((` (((` (((` `'--'^ "<< endl;
cout << "--------------------------------------" << endl;
cout << "You walk over to a nearby tree and find an" <<endl;
cout << "angry gator coming towards you." <<endl;
cout << "It's time for you to use your weapon and find out your skill... "<<endl;
cout << "~~***~~***~~***~~~***~~~***~~~***~~~***~~~~****~~~~~~***~~~~***~~"<<endl;
cout << "Now generating random fate with weapon..."<<endl;
cout << "Processing..." << endl;
//ELF WITH BOW AND ARROW OR SPEAR GAME
srand(time(NULL));
random = rand() % 4 + 1;
cout << "Your number is " << random << endl;
cout << "That means that...\n" << endl;
switch(random) {
case 1: random = 100;
cout << "Good job! The gator is hit in the tail and runs away...\n" << endl;
break;
case 2: random = 200;
cout << "Good job! The gator is hit in the body and runs away...\n" << endl;
break;
case 3: random = 300;
cout << "Good job! The gator is hit in the head and runs away...\n" << endl;
break;
default: random = 0;
cout << "Too bad. No target is hit...\n" << endl;
cout << "Since you didn't defeat the gator, the gator eats you... \n" << endl;
}
score=random+100;
cout << "Congrats! Your score is: \n" << getline(cin, x.score) << endl;
cout << "Please enter your name: " << endl;
getline(cin, x.name);
getPlayerInfo(aPlayer);
displayPlayerInfo(aPlayer);
writePlayerInfoToFile();
}
else{
//ELF WITH MAGIC GAME
cout << "Now traveling to Paradise Island..." << endl;
cout << "You arrive to a remote island." << endl;
cout << " _//_ " <<endl;
cout << " /o\\ o/ " <<endl;
cout << " | /| " <<endl;
cout << " _|___ /_|_________ " <<endl;
srand(time(NULL));
random = rand() % 2 + 1;
cout << ".::**::..::**::..::**::..::**::..::**::...::**::...::**::...::**::...::**::...::**::." << endl;
cout << "An islander lures you into her cave and teaches you" << endl;
cout << "how to make potions. If you are succesful you will return home." << endl;
cout << "If not you will remain on this island forever."<<endl;
cout << "It's time to test your potion making skills! \n" << endl;
cout << "Now we will determine whether or not your potion is a success or failure...:"<<endl;
cout << ".::**::..::**::..::**::..::**::..::**::...::**::...::**::...::**::...::**::...::**::.\n" << endl;
cout << "Processing....."<<endl;
switch(random) {
case 1: random = -100;
cout << "Sorry, your potion is a failure...\n" << endl;
break;
default: random = 200;
cout << "Your potion is a success! \n" << endl;
}
score = random + 100;
cout << "Congrats! Your score is: \n" << getline(cin, x.score) << endl;
cout << "Please enter your name: " << endl;
getline(cin, x.name);
getPlayerInfo(aPlayer);
displayPlayerInfo(aPlayer);
writePlayerInfoToFile();
}
}
}
break;
case 3:
cout << "Goodbye! Thank you for playing... :D" << endl;
cout << "--------------------------------------" << endl;
exit(EXIT_SUCCESS);
break;
default:
while(choice < 1 || choice > 3) {
cout << "Invalid choice. Choose again...\n" << endl;
cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
cout << "What is your choice?" << endl;
cin >> choice;
break;
}
}
cout << "Would you like to continue playing? (Please say Y for yes N for no): " << endl;
cin >> PLAY;
}
while(PLAY == 'Y' || PLAY == 'y');
return 0;
}
void displayMenu()
{
cout <<" _( )_ "<<endl;
cout <<" _ (_ O _) "<<endl;
cout <<" _( )_ (_) "<<endl;
cout <<" (_ O _) WELCOME TO "<<endl;
cout <<" (_) FANTASY LAND! "<<endl;
cout <<" _( )_ ()__ "<<endl;
cout <<" (_ O _) :=)___)-. "<<endl;
cout <<" (_) () | "<<endl;
cout <<" | "<<endl;
cout <<" | "<<endl;
cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
cout << "Hello Gamer! Please pick your choice from the main menu! \n" << endl;
cout << " ~Main Menu~" << endl;
cout << "-------------------------------" << endl;
cout << "| 1. See Rules |" << endl;
cout << "| 2. Play game |" << endl;
cout << "| 3. Quit |" << endl;
cout << "-------------------------------" << endl;
}
void getChoice(int & choice)
{
cout << "What is your choice?" << endl;
cin >> choice;
while (choice < 1 || choice > 3) {
cout <<"Invalid choice. It must be between 1-3."<<endl;
cout <<"please enter your choice: 1-3"<<endl;
cin >> choice;
}
}
void displayRules()
{
cout << " ~Rules of the Game~ " << endl;
cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
cout << "This game determines your ability to hit a target" << endl;
cout << "depending on your character's ability. Then totals"<< endl;
cout << "your score to see where you place on the high score chart." << endl;
cout << "If your score is higher than then the score recorded in the" <<endl;
cout << "charts you will replace them and become our new champion!"<<endl;
cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
cout <<" _( )_ "<<endl;
cout <<" (_ O _) "<<endl;
cout <<" (_) "<<endl;
}
void displayPlaceMenu()
{
cout << "--------------------------------------" << endl;
cout << "Let's begin..." << endl;
cout << "Where would you like to journey to...\n" << endl;
cout << " ~Destination Menu~" << endl;
cout << "-------------------------------" << endl;
cout << "| 1. Atlantis |" << endl;
cout << "| 2. Paradise Island |" << endl;
cout << "-------------------------------" << endl;
}
void getPlace(int & place)
{
cout << "What is your destination choice?: " << endl;
cin >> place;
while(place < 1 || place > 2) {
cout << "Please enter 1 for Atlantis or 2 for Paradise Island: ";
cin >> place;
}
}
void displayCharacterMenu()
{
cout << "--------------------------------------" << endl;
cout << "Nice choice. Let's continue..." << endl;
cout << "Choose your character...\n" << endl;
cout << " ~Character Menu~" << endl;
cout << "-------------------------------" << endl;
cout << "| 1. Human |" << endl;
cout << "| 2. Orc |" << endl;
cout << "| 3. Elf |" << endl;
cout << "-------------------------------" << endl;
}
void getCharacter(int & person)
{
cout << "What is your character choice?: " << endl;
cin >> person;
while(person < 1 || person > 3) {
cout << "Please enter 1 for human, 2 for orc, or 3 for elf: ";
cin >> person;
}
}
void displayWeaponMenu()
{
cout << "--------------------------------------" << endl;
cout << "Good choice. Now choose your weapon...\n" << endl;
cout << " ~Weapon Menu~" << endl;
cout << "-------------------------------" << endl;
cout << "| 1. Spear |" << endl;
cout << "| 2. Bow and Arrow |" << endl;
cout << "| 3. Magic Staff |" << endl;
cout << "-------------------------------" << endl;
}
void getWeapon(int & weapon)
{
cout << "Which one would you like to choose? : " << endl;
cin >> weapon;
while(weapon < 1 || weapon > 3) {
cout << "Please enter 1 for Spear, 2 for Bow and Arrow, or 3 for Magic Staff: ";
cin >> weapon;
}
}
void getPlayerInfo(Player & x)
{
ifstream input;
input.open("highScores.txt");
if ( ! input ) {
cout <<"error: cannot open file for reading."<<endl;
cout <<"terminating the program ... "<<endl;
exit(EXIT_FAILURE);
}
getline(input, x.name);
getline(input, x.score);
input.ignore(INT_MAX, '\n');
input.close();
}
void writePlayerInfoToFile()
{
// open a file for writing
ofstream output;
output.open("highScores.txt");
if ( ! output ) {
cout <<"cannot open carInfo.txt for writing."<<endl;
cout <<"terminating the program ... "<<endl;
exit(EXIT_FAILURE);
}
string name;
double score;
cout <<"what is your name: "<<endl;
getline(cin, name);
output << name <<endl;
cout << score <<endl;
cin.ignore(INT_MAX, '\n');
output << score <<endl;
output.close();
}
void displayPlayerInfo( Player x )
{
cout << endl;
cout <<"Name: " << x.name << endl;
cout <<"Score: " << x.score << endl;
cout << endl;
}