Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Assumptions:
- a returning user only wants 5 tries to enter valid user name
- a returning user only wants 5 tries to enter a valid password
- the user MUST be 18 years or older to play
- */
- #include <iostream> //cin >> cout << endl
- #include <fstream> //ifstream, ofstream
- #include <string> //string
- #include "account.h" //Class Account
- using namespace std;
- int main()
- {
- //Data Abstractions
- string username; //the username entered by user
- string password; //the password inputed by user
- string passwordFile; //the password from the users file
- string passwordCheck; //used for re-entered password
- ifstream in; //used for input file name
- ofstream out; //used for output file name
- int invalidTries = 0; //number of tries to enter a valid password
- int tries = 0; //number of tries to enter a valid username
- int oldOrNew; //used for returning or new player
- Account user;
- int choice; //used for avatar creation
- cout <<"Are You a Returning User?\n 1. Yes\n 2. No\n";
- cin >> oldOrNew;
- if (oldOrNew == 1)
- {
- do
- {
- //Prompt for UserName
- cout << "Please Enter Username: \n";
- cin >> username;
- //Test for Returning User (Open Input File)
- in.open (username.c_str());
- if (in.is_open())
- {
- do
- {
- in.clear();
- //Prompt the User for Password
- cout << "Are You Really " << username;
- cout << "? Please Enter Your Password: \n";
- cin >> password;
- //Read in Password from File
- in >> passwordFile;
- //Increment Tries
- invalidTries++;
- }
- while (password != passwordFile && invalidTries < 5);
- if (invalidTries < 5)
- cout << "WELCOME BACK " << username << "!\n";
- else
- cout << "You Are NOT Who You Say You Are. Goodbye.\n";
- }
- else
- cout << "Not a Known Username. Try Again.\n";
- //Increment Tries
- tries ++;
- }
- while (!in.is_open() && tries < 5);
- if (!in.is_open() && tries == 5)
- cout << "You Are NOT a Returning User. Goodbye." << endl;
- }
- //Create New User File
- else if( oldOrNew == 2 )
- {
- do
- {
- in.clear();
- //Create Username
- cout << "Please Enter a Username:\n";
- cin >> username;
- //Test to See if User Name already exists
- in.open(username.c_str());
- if (in.is_open())
- cout << "Username is taken. Try Again.\n\n";
- }
- while (in.is_open());
- //Create New User File (Open Output File)
- out.open(username.c_str());
- do
- {
- //Create Password
- cout << "Please Enter a Password:\n";
- cin >> password;
- cout << "Please Re-Enter Your Password:\n";
- cin >> passwordCheck;
- //Test for Same Password
- if (password == passwordCheck)
- {
- out << password;
- }
- else
- cout << "Your Passwords Do NOT Match. Try Again\n\n";
- }
- while (password != passwordCheck);
- cout << "Please enter your birthday (MM DD YYYY): " << endl;
- int day, month, year;
- bool old = false;
- cin >> month >> day >> year;
- user.setMonth( month );
- user.setDay( day );
- user.setYear( year );
- old = user.isOldEnough();
- if( old )
- cout << "You're all good to go buddy. : / " << endl;
- else
- cout << "You're a bit young buddy. : / " << endl;
- //Avatar Creation
- //Hair
- if (old)
- {
- cout << "Pick a Hair Color:\n1. Red\n2.Brown\n3.Blonde\n";
- cin >> choice;
- user.setHairColor(choice);
- cout << "You chose" << user.getHairColor() << endl;
- //Eye Color
- cout << "Pick an Eye Color:\n1.Brown\n2.Blue\n";
- cin >> choice;
- user.setEyeColor(choice);
- //Skin Color
- cout << "Pick a Skin Color for Your Avatar:\n1.Light\n2.Medium\n3.Dark\n";
- cin >> choice;
- user.setSkin(choice);
- //Outfit
- cout << "The Outfit is Jeans and a Jacket. What color would you like";
- cout << " your jacket?\n1.Blue\n2.Green\n3.Black\n";
- cin >> choice;
- user.setOutfit(choice);
- //Gender
- cout << "What is Your Avatar's Gender?\n1.Male\n2.Female\n";
- cin >> choice;
- user.setGender(choice);
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment