Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <iomanip>
  4. #include <string>
  5. #include <cstdlib>
  6. #include <ctime>
  7. #include <windows.h>
  8. using namespace std;
  9. void rgs();
  10. void Menu();
  11. void Login();
  12. void monsters();
  13. void loading();
  14.  
  15. int ans1, cLevel, cExp;
  16. string charname, pw, user, pass;
  17. bool access;
  18.  
  19.  
  20. int main()
  21. {
  22. loading();
  23. Sleep(3000);
  24. system("CLS");
  25. Menu();
  26. system("CLS");
  27. if (ans1==1)
  28. {
  29. Login();
  30. }
  31. else if (ans1==2)
  32. {
  33. rgs();
  34. system("CLS");
  35. Menu();
  36. }
  37. else
  38. {
  39. cout<<"You have entered an invalid option"<<endl;
  40. }
  41. system ("pause");
  42. return 0;
  43. }
  44. void Login()
  45. {
  46. cout<<"Please enter your charater name: ";
  47. cin>>user;
  48. cout<<"Please enter your password: ";
  49. cin>>pass;
  50.  
  51.  
  52. ifstream inFile;
  53. string username, password;
  54. inFile.open("users.txt");
  55. if (inFile.is_open())
  56. {
  57. while (!inFile.eof())
  58. {
  59. inFile >>username>>password>>cLevel>>cExp;
  60. if (user==username && pass==password)
  61. {
  62. access=true;
  63. break;
  64. }
  65. }
  66. if (access)
  67. {
  68. cout<<"You have login successfully!"<<endl;
  69.  
  70. monsters();
  71. }
  72. else
  73. {
  74. cout<<"You have enter the wrong username/password!"<<endl;
  75. system("CLS");
  76. Login();
  77. }
  78. }
  79. else
  80. {
  81. cout<<"Error!"<<endl;
  82. }
  83. inFile.close();
  84.  
  85.  
  86. }
  87.  
  88. void Menu()
  89. {
  90. cout<<"Welcome to dungeon hunter!"<<endl;
  91. cout<<"Choose a choice below."<<endl;
  92. cout<<"1. Login"<<endl;
  93. cout<<"2. Register a new account"<<endl;
  94. cout<<"Please enter your option: ";
  95. cin>>ans1;
  96. }
  97.  
  98. void rgs()
  99. {
  100. ifstream inFile;
  101. ofstream newuser;
  102. string username, password, passwordconfirm;
  103. inFile.open("users.txt", ios::app);
  104. newuser.open("users.txt", ios::app);
  105. bool uservalid=false;
  106. while (!uservalid)
  107. {
  108. cout << "Username: ";
  109. cin >> username;
  110. cout << "Password: ";
  111. cin >> password;
  112. cout << "Confirm password: ";
  113. cin >> passwordconfirm;
  114. int m=0;
  115. int k=0;
  116. while (inFile>>user>>pass)
  117. {
  118. m++;
  119. if (username!=user)
  120. k++;
  121. }
  122. if (m==k && password==passwordconfirm)
  123. uservalid=true;
  124. else if (m!=k)
  125. cout << "There is already a user with this username." << endl;
  126. else
  127. cout << "The passwords given do not match." << endl;
  128. }
  129. newuser << username << " " << password << " 1 0" << endl;;
  130. inFile.close();
  131. newuser.close();
  132. }
  133.  
  134. void monsters()
  135. {
  136. ifstream monstersFile;
  137. int mLevel, mExpA, mExpB, mExp, hp, a, b;
  138. srand((unsigned int)time(NULL));//initialize random number generator;
  139. string monsters[10]={"Sandton","Tentacuno","Porypix","Snorbell","Paradon","Muqueen","Maromander","Nidodash","Hitmonchop","Voltchamp"};
  140. int r = rand()%10+1; //generate a number between 1-1
  141.  
  142. monstersFile.open("monsters.txt");
  143. if(!monstersFile)
  144. cout<<"Not able to open text file\n";
  145. else
  146. {
  147. cout<<left<<setw(15)<<"Name"<<setw(15)<<"Level"<<setw(15)<<"HP"<<"EXP"<<endl;
  148. while(!monstersFile.eof())
  149. {
  150. monstersFile>>mLevel>>mExpA>>mExpB>>hp;
  151. if(monstersFile.fail())
  152. {
  153. break;
  154. }
  155. else
  156. {
  157. if(cLevel==mLevel)
  158. {
  159. mExp=rand()%(mExpB-mExpA+1)+mExpA;
  160. cout<<left<<setw(15)<<monsters[r]<<setw(15)<<mLevel<<setw(15)<<hp<<mExp<<endl;
  161. }
  162.  
  163. }
  164.  
  165. }
  166.  
  167. }
  168. monstersFile.close();
  169. }
  170.  
  171. void edit()
  172. {
  173. string user,pass,search;
  174. int lvl, exp, nexp;
  175. ifstream ifile ("users.txt");
  176. ofstream ofile ("users2.txt");
  177. cout<<"You username! ";
  178. cin>>search;
  179. cout<<"your exp gained ";
  180. cin>>nexp;
  181. while (!ifile.eof())
  182. {
  183. ifile>>user>>pass>>lvl>>exp;
  184. if(user==search)
  185. {
  186.  
  187. ofile<<endl<<user<<" "<<pass<<" "<<lvl<<" "<<nexp;
  188. }
  189. else
  190. {
  191. ofile<<endl<<user<<" "<<pass<<" "<<lvl<<" "<<exp;
  192. }
  193. }
  194. cout<<"\r";
  195. ifile.close();
  196. ofile.close();
  197. remove("users.txt");
  198. int result=rename("users2.txt","users.txt");
  199. if (result==0)
  200. cout<<"File successfully renamed\n";
  201. else
  202. {
  203. while (result==0)
  204. {
  205. cout<<"Error renaming file, Retrying\n";
  206. result=rename("users2.txt","users.txt");
  207. }
  208. }
  209. }
  210.  
  211. void loading()
  212. {
  213. cout << (char)178 << (char)178 << (char)178 << (char)178 << (char)178 << (char)255 << (char)255 << (char)255 << (char) 255<< (char)178 << (char)178 << (char)178 << (char)178 << (char)178 << endl;
  214. cout << (char)178 << (char)178 << (char)178 << (char)255 << (char)255 << (char)178 << (char)178 << (char)178 << (char)178 << (char)255 << (char)255 << (char)178 << (char)178 << (char)178 << endl;
  215. cout << (char)178 << (char)178 << (char)255 << (char)178 << (char)178 << (char)178 << (char)178 << (char)178 << (char)178 << (char)178 << (char)178 << (char)255 << (char)178 << (char)178 << endl;
  216. cout << (char)178 << (char)255 << (char)178 << (char)178 << (char)178 << (char)178 << (char)178 << (char)178 << (char)178 << (char)178 << (char)178 << (char)178 << (char)255 << (char)178 << endl;
  217. cout << (char)178 << (char)255 << (char)178 << (char)178 << (char)178 << (char)178 << (char)178 << (char)178 << (char)178 << (char)178 << (char)178 << (char)178 << (char)255 << (char)178 << endl;
  218. cout << (char)255 << (char)178 << (char)178 << (char)178 << (char)178 << (char)178 << (char)255 << (char)255 << (char)178 << (char)178 << (char)178 << (char)178 << (char)178 << (char)255 << endl;
  219. cout << (char)255 << (char)178 << (char)178 << (char)178 << (char)178 << (char)255 << (char)178 << (char)178 << (char)255 << (char)178 << (char)178 << (char)178 << (char)178 << (char)255 << endl;
  220. cout << (char)255 << (char)255 << (char)255 << (char)255 << (char)255 << (char)255 << (char)178 << (char)178 << (char)255 << (char)255 << (char)255 << (char)255 << (char)255 << (char)255 << endl;
  221. cout << (char)255 << (char)178 << (char)178 << (char)178 << (char)178 << (char)178 << (char)255 << (char)255 << (char)178 << (char)178 << (char)178 << (char)178 << (char)178 << (char)255 << endl;
  222. cout << (char)178 << (char)255 << (char)178 << (char)178 << (char)178 << (char)178 << (char)178 << (char)178 << (char)178 << (char)178 << (char)178 << (char)178 << (char)255 << (char)178 << endl;
  223. cout << (char)178 << (char)255 << (char)178 << (char)178 << (char)178 << (char)178 << (char)178 << (char)178 << (char)178 << (char)178 << (char)178 << (char)178 << (char)255 << (char)178 << endl;
  224. cout << (char)178 << (char)178 << (char)255 << (char)178 << (char)178 << (char)178 << (char)178 << (char)178 << (char)178 << (char)178 << (char)178 << (char)255 << (char)178 << (char)178 << endl;
  225. cout << (char)178 << (char)178 << (char)178 << (char)255 << (char)255 << (char)178 << (char)178 << (char)178 << (char)178 << (char)255 << (char)255 << (char)178 << (char)178 << (char)178 << endl;
  226. cout << (char)178 << (char)178 << (char)178 << (char)178 << (char)178 << (char)255 << (char)255 << (char)255 << (char)255 << (char)178 << (char)178 << (char)178 << (char)178 << (char)178 << endl;
  227.  
  228. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement