maddie_dlt

Untitled

Nov 19th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.36 KB | None | 0 0
  1. /*
  2.  
  3. Assumptions:
  4. a returning user only wants 5 tries to enter valid user name
  5. a returning user only wants 5 tries to enter a valid password
  6. the user MUST be 18 years or older to play
  7. */
  8.  
  9.  
  10.  
  11. #include <iostream> //cin >> cout << endl
  12. #include <fstream> //ifstream, ofstream
  13. #include <string> //string
  14. #include "account.h" //Class Account
  15.  
  16.  
  17. using namespace std;
  18.  
  19. int main()
  20. {
  21. //Data Abstractions
  22. string username; //the username entered by user
  23. string password; //the password inputed by user
  24. string passwordFile; //the password from the users file
  25. string passwordCheck; //used for re-entered password
  26. ifstream in; //used for input file name
  27. ofstream out; //used for output file name
  28. int invalidTries = 0; //number of tries to enter a valid password
  29. int tries = 0; //number of tries to enter a valid username
  30. int oldOrNew; //used for returning or new player
  31. Account user;
  32. int choice; //used for avatar creation
  33.  
  34.  
  35. cout <<"Are You a Returning User?\n 1. Yes\n 2. No\n";
  36. cin >> oldOrNew;
  37.  
  38. if (oldOrNew == 1)
  39. {
  40. do
  41. {
  42. //Prompt for UserName
  43. cout << "Please Enter Username: \n";
  44. cin >> username;
  45.  
  46. //Test for Returning User (Open Input File)
  47. in.open (username.c_str());
  48.  
  49. if (in.is_open())
  50. {
  51. do
  52. {
  53. in.clear();
  54.  
  55. //Prompt the User for Password
  56. cout << "Are You Really " << username;
  57. cout << "? Please Enter Your Password: \n";
  58. cin >> password;
  59.  
  60. //Read in Password from File
  61. in >> passwordFile;
  62.  
  63. //Increment Tries
  64. invalidTries++;
  65. }
  66. while (password != passwordFile && invalidTries < 5);
  67.  
  68. if (invalidTries < 5)
  69. cout << "WELCOME BACK " << username << "!\n";
  70. else
  71. cout << "You Are NOT Who You Say You Are. Goodbye.\n";
  72. }
  73. else
  74. cout << "Not a Known Username. Try Again.\n";
  75.  
  76. //Increment Tries
  77. tries ++;
  78. }
  79. while (!in.is_open() && tries < 5);
  80.  
  81. if (!in.is_open() && tries == 5)
  82. cout << "You Are NOT a Returning User. Goodbye." << endl;
  83. }
  84. //Create New User File
  85. else if( oldOrNew == 2 )
  86. {
  87. do
  88. {
  89. in.clear();
  90.  
  91. //Create Username
  92. cout << "Please Enter a Username:\n";
  93. cin >> username;
  94.  
  95. //Test to See if User Name already exists
  96. in.open(username.c_str());
  97.  
  98. if (in.is_open())
  99. cout << "Username is taken. Try Again.\n\n";
  100. }
  101. while (in.is_open());
  102.  
  103. //Create New User File (Open Output File)
  104. out.open(username.c_str());
  105.  
  106. do
  107. {
  108. //Create Password
  109. cout << "Please Enter a Password:\n";
  110. cin >> password;
  111. cout << "Please Re-Enter Your Password:\n";
  112. cin >> passwordCheck;
  113.  
  114. //Test for Same Password
  115. if (password == passwordCheck)
  116. {
  117. out << password;
  118. }
  119. else
  120. cout << "Your Passwords Do NOT Match. Try Again\n\n";
  121. }
  122. while (password != passwordCheck);
  123.  
  124. cout << "Please enter your birthday (MM DD YYYY): " << endl;
  125.  
  126. int day, month, year;
  127. bool old = false;
  128.  
  129. cin >> month >> day >> year;
  130. user.setMonth( month );
  131. user.setDay( day );
  132. user.setYear( year );
  133.  
  134. old = user.isOldEnough();
  135.  
  136. if( old )
  137. cout << "You're all good to go buddy. : / " << endl;
  138. else
  139. cout << "You're a bit young buddy. : / " << endl;
  140.  
  141. //Avatar Creation
  142. //Hair
  143. if (old)
  144. {
  145. cout << "Pick a Hair Color:\n1. Red\n2.Brown\n3.Blonde\n";
  146. cin >> choice;
  147.  
  148. user.setHairColor(choice);
  149. cout << "You chose" << user.getHairColor() << endl;
  150.  
  151. //Eye Color
  152. cout << "Pick an Eye Color:\n1.Brown\n2.Blue\n";
  153. cin >> choice;
  154.  
  155. user.setEyeColor(choice);
  156.  
  157. //Skin Color
  158. cout << "Pick a Skin Color for Your Avatar:\n1.Light\n2.Medium\n3.Dark\n";
  159. cin >> choice;
  160.  
  161. user.setSkin(choice);
  162.  
  163. //Outfit
  164. cout << "The Outfit is Jeans and a Jacket. What color would you like";
  165. cout << " your jacket?\n1.Blue\n2.Green\n3.Black\n";
  166. cin >> choice;
  167.  
  168. user.setOutfit(choice);
  169.  
  170. //Gender
  171. cout << "What is Your Avatar's Gender?\n1.Male\n2.Female\n";
  172. cin >> choice;
  173.  
  174. user.setGender(choice);
  175. }
  176.  
  177. }
  178.  
  179. return 0;
  180. }
Add Comment
Please, Sign In to add comment