Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <iomanip>
- #include <string>
- #include <cstdlib>
- #include <ctime>
- #include <windows.h>
- using namespace std;
- void rgs();
- void Menu();
- void Login();
- void monsters();
- void loading();
- int ans1, cLevel, cExp;
- string charname, pw, user, pass;
- bool access;
- int main()
- {
- loading();
- Sleep(3000);
- system("CLS");
- Menu();
- system("CLS");
- if (ans1==1)
- {
- Login();
- }
- else if (ans1==2)
- {
- rgs();
- system("CLS");
- Menu();
- }
- else
- {
- cout<<"You have entered an invalid option"<<endl;
- }
- system ("pause");
- return 0;
- }
- void Login()
- {
- cout<<"Please enter your charater name: ";
- cin>>user;
- cout<<"Please enter your password: ";
- cin>>pass;
- ifstream inFile;
- string username, password;
- inFile.open("users.txt");
- if (inFile.is_open())
- {
- while (!inFile.eof())
- {
- inFile >>username>>password>>cLevel>>cExp;
- if (user==username && pass==password)
- {
- access=true;
- break;
- }
- }
- if (access)
- {
- cout<<"You have login successfully!"<<endl;
- monsters();
- }
- else
- {
- cout<<"You have enter the wrong username/password!"<<endl;
- system("CLS");
- Login();
- }
- }
- else
- {
- cout<<"Error!"<<endl;
- }
- inFile.close();
- }
- void Menu()
- {
- cout<<"Welcome to dungeon hunter!"<<endl;
- cout<<"Choose a choice below."<<endl;
- cout<<"1. Login"<<endl;
- cout<<"2. Register a new account"<<endl;
- cout<<"Please enter your option: ";
- cin>>ans1;
- }
- void rgs()
- {
- ifstream inFile;
- ofstream newuser;
- string username, password, passwordconfirm;
- inFile.open("users.txt", ios::app);
- newuser.open("users.txt", ios::app);
- bool uservalid=false;
- while (!uservalid)
- {
- cout << "Username: ";
- cin >> username;
- cout << "Password: ";
- cin >> password;
- cout << "Confirm password: ";
- cin >> passwordconfirm;
- int m=0;
- int k=0;
- while (inFile>>user>>pass)
- {
- m++;
- if (username!=user)
- k++;
- }
- if (m==k && password==passwordconfirm)
- uservalid=true;
- else if (m!=k)
- cout << "There is already a user with this username." << endl;
- else
- cout << "The passwords given do not match." << endl;
- }
- newuser << username << " " << password << " 1 0" << endl;;
- inFile.close();
- newuser.close();
- }
- void monsters()
- {
- ifstream monstersFile;
- int mLevel, mExpA, mExpB, mExp, hp, a, b;
- srand((unsigned int)time(NULL));//initialize random number generator;
- string monsters[10]={"Sandton","Tentacuno","Porypix","Snorbell","Paradon","Muqueen","Maromander","Nidodash","Hitmonchop","Voltchamp"};
- int r = rand()%10+1; //generate a number between 1-1
- monstersFile.open("monsters.txt");
- if(!monstersFile)
- cout<<"Not able to open text file\n";
- else
- {
- cout<<left<<setw(15)<<"Name"<<setw(15)<<"Level"<<setw(15)<<"HP"<<"EXP"<<endl;
- while(!monstersFile.eof())
- {
- monstersFile>>mLevel>>mExpA>>mExpB>>hp;
- if(monstersFile.fail())
- {
- break;
- }
- else
- {
- if(cLevel==mLevel)
- {
- mExp=rand()%(mExpB-mExpA+1)+mExpA;
- cout<<left<<setw(15)<<monsters[r]<<setw(15)<<mLevel<<setw(15)<<hp<<mExp<<endl;
- }
- }
- }
- }
- monstersFile.close();
- }
- void edit()
- {
- string user,pass,search;
- int lvl, exp, nexp;
- ifstream ifile ("users.txt");
- ofstream ofile ("users2.txt");
- cout<<"You username! ";
- cin>>search;
- cout<<"your exp gained ";
- cin>>nexp;
- while (!ifile.eof())
- {
- ifile>>user>>pass>>lvl>>exp;
- if(user==search)
- {
- ofile<<endl<<user<<" "<<pass<<" "<<lvl<<" "<<nexp;
- }
- else
- {
- ofile<<endl<<user<<" "<<pass<<" "<<lvl<<" "<<exp;
- }
- }
- cout<<"\r";
- ifile.close();
- ofile.close();
- remove("users.txt");
- int result=rename("users2.txt","users.txt");
- if (result==0)
- cout<<"File successfully renamed\n";
- else
- {
- while (result==0)
- {
- cout<<"Error renaming file, Retrying\n";
- result=rename("users2.txt","users.txt");
- }
- }
- }
- void loading()
- {
- 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;
- 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;
- 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;
- 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;
- 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;
- 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;
- 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;
- 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;
- 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;
- 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;
- 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;
- 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;
- 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;
- 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;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement