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 <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <limits>
- #include <cctype>
- #include <cmath>
- #include <Windows.h>
- using namespace std;
- void rgs();
- void Menu();
- string Login();
- int monsters();
- void loading();
- void edit(string user,int obexp);
- void qns1();
- void qns2();
- void qns3();
- void qns4();
- void qns5();
- void qns6();
- void qns7();
- void qns8();
- void qns9();
- void qns10();
- int ErrorCheck();
- 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");
- main();
- }
- else
- {
- cout<<"You have entered an invalid option"<<endl;
- }
- system ("pause");
- return 0;
- }
- string Login()
- {
- cout<<"Please enter your charater name: ";
- cin>>user;
- cout<<"Please enter your password: ";
- cin>>pass;
- int qexp;
- 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;
- Sleep(2000);
- system("CLS");
- cout<<"You are in a fight now. Solve this question to defeat the monster!"<<endl;
- qexp=monsters();
- cout<<endl;
- if (cLevel=1)
- {qns1();
- edit(user,qexp);}
- else if (cLevel=2)
- {qns2();
- edit(user,qexp);}
- else if (cLevel=3)
- {qns3();
- edit(user,qexp);}
- else if (cLevel=4)
- {qns4();
- edit(user,qexp);}
- else if (cLevel=5)
- {qns5();
- edit(user,qexp);}
- else if (cLevel=6)
- {qns6();
- edit(user,qexp);}
- else if (cLevel=7)
- {qns7();
- edit(user,qexp);}
- else if (cLevel=8)
- {qns8();
- edit(user,qexp);}
- else if (cLevel=9)
- {qns9();
- edit(user,qexp);}
- else
- {qns10();
- edit(user,qexp);}
- }
- else
- {
- cout<<"You have enter the wrong username/password!"<<endl;
- cout<<"Please try again!"<<endl;
- Sleep(2000);
- system("CLS");
- Login();
- }
- }
- else
- {
- cout<<"Error!"<<endl;
- }
- inFile.close();
- return user;
- }
- 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;
- cout<<"You have successfully registered an account!"<<endl;
- Sleep(3000);
- inFile.close();
- newuser.close();
- }
- int monsters()
- {
- ifstream monstersFile;
- int mLevel, mExpA, mExpB, mExp;
- 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"<<"EXP"<<endl;
- while(!monstersFile.eof())
- {
- monstersFile>>mLevel>>mExpA>>mExpB;
- 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)<<mExp<<endl;
- }
- }
- }
- }
- monstersFile.close();
- return mExp;
- }
- void loading()
- {
- cout<<"Welcome to dungeon ma(th)ster!"<<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;
- 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;
- }
- void edit(string user,int obexp)
- {
- string username,pass,search;
- int lvl,nlvl, exp, nexp, mExp;
- ifstream ifile ("users.txt");
- ofstream ofile ("users2.txt");
- while (!ifile.eof())
- {
- ifile>>username>>pass>>lvl>>exp;
- nexp=exp+obexp;
- if(user==username)
- {
- if (nexp>0)
- {nlvl=1;}
- else if (nexp<1500)
- {nlvl=2;}
- else if (nexp<2200)
- {nlvl=3;}
- else if (nexp<3300)
- {nlvl=4;}
- else if (nexp<4500)
- {nlvl=5;}
- else if (nexp<6500)
- {nlvl=6;}
- else if (nexp<8700)
- {nlvl=7;}
- else if (nexp<8700)
- {nlvl=8;}
- else if (nexp<11200)
- {nlvl=9;}
- else if (nexp<14200)
- {nlvl=10;}
- else
- {nlvl=lvl;}
- ofile<<endl<<user<<" "<<pass<<" "<<nlvl<<" "<<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 qns1() // plus
- {
- srand (time(NULL));
- int qn1 = rand() % 200 + 1;
- int qn2 = rand() % 100 + 1;
- int input;
- int qnsans;
- cout<<"Here is your question!"<<endl;
- cout<< qn1 <<"+"<< qn2<<endl;
- qnsans=qn1+qn2;
- bool Restart=true;
- while(Restart==true)
- {
- cout<<"Enter your answer : ";
- cin>>input;
- Restart = cin.fail();
- if(cin.fail()==true)
- cout<<"\nError, Invalid Choice, Please Key in a Numerical Value\n";
- else if(qnsans==input)// if no error is present
- {
- cout<<"You Won the round!"<<endl;
- Restart = false; // to allow do loop to end
- }
- else if(qnsans!=input)
- {
- cout<<"try again"<<endl;
- Restart = true;
- }
- else
- {
- cout<<"try again"<<endl;
- Restart = true;
- }
- cin.clear(); //Restart error flag
- }
- }
- //plus
- void qns2() //minus
- {
- srand (time(NULL));
- int qn1 = rand() % 100 + 1;
- int qn2 = rand() % 100 + 1;
- int input;
- int qnsans;
- cout<<"Here is your question!"<<endl;
- cout<< qn1 <<"-"<< qn2<<endl;
- qnsans= qn1-qn2;
- bool Restart=true;
- while(Restart==true)
- {
- cout<<"Enter your answer : ";
- cin>>input;
- Restart = cin.fail();
- if(cin.fail()==true)
- cout<<"\nError, Invalid Choice, Please Key in a Numerical Value\n";
- else if(qnsans==input)// if no error is present
- {
- cout<<"You Won the round!"<<endl;
- Restart = false; // to allow do loop to end
- system("Pause");
- }
- else if(qnsans!=input)
- {
- cout<<"try again"<<endl;
- Restart = true;
- }
- else
- {
- cout<<"try again"<<endl;
- Restart = true;
- }
- cin.clear(); //Restart error flag
- }
- } // minus
- //minus
- void qns3()//times
- {
- srand (time(NULL));
- int qn1 = rand() % 20 + 1;
- int qn2 = rand() % 10 + 1;
- int input;
- int qnsans;
- cout<<"Here is your question!"<<endl;
- cout<< qn1 <<"*"<< qn2<<endl;
- qnsans= qn1*qn2;
- bool Restart=true;
- while(Restart==true)
- {
- cout<<"Enter your answer : ";
- cin>>input;
- Restart = cin.fail();
- if(cin.fail()==true)
- cout<<"\nError, Invalid Choice, Please Key in a Numerical Value\n";
- else if(qnsans==input)// if no error is present
- {
- cout<<"You Won the round!"<<endl;
- Restart = false; // to allow do loop to end
- system("Pause");
- }
- else if(qnsans!=input)
- {
- cout<<"try again"<<endl;
- Restart = true;
- }
- else
- {
- cout<<"try again"<<endl;
- Restart = true;
- }
- cin.clear(); //Restart error flag
- }
- }
- //times
- void qns4()//plusplus
- {
- srand (time(NULL));
- double qn1 = rand() % 200 + 1;
- double qn2 = rand() % 100 + 1;
- double QN3 = rand()%100+1;
- double input;
- double qnsans;
- cout<<"Here is your question!"<<endl;
- cout<< qn1 <<"+"<< qn2<<"+"<<QN3<<endl;
- qnsans= qn1+qn2+QN3;
- bool Restart=true;
- while(Restart==true)
- {
- cout<<"Enter your answer : ";
- cin>>input;
- Restart = cin.fail();
- if(cin.fail()==true)
- cout<<"\nError, Invalid Choice, Please Key in a Numerical Value\n";
- else if(qnsans==input)// if no error is present
- {
- cout<<"You Won the round!"<<endl;
- Restart = false; // to allow do loop to end
- system("Pause");
- }
- else if(qnsans!=input)
- {
- cout<<"try again"<<endl;
- Restart = true;
- }
- else
- {
- cout<<"try again"<<endl;
- Restart = true;
- }
- cin.clear(); //Restart error flag
- }
- }
- //plusplus
- void qns5()
- {
- srand (time(NULL));
- double qn1 = rand() %200 + 1;
- double qn2 = rand() % 100 + 1;
- double QN3 = rand()%100+1;
- double input;
- double qnsans;
- cout<<"Here is your question!"<<endl;
- cout<< qn1 <<"-"<< qn2<<"+"<<QN3<<endl;
- qnsans= qn1-qn2+QN3;
- bool Restart=true;
- while(Restart==true)
- {
- cout<<"Enter your answer : ";
- cin>>input;
- Restart = cin.fail();
- if(cin.fail()==true)
- cout<<"\nError, Invalid Choice, Please Key in a Numerical Value\n";
- else if(qnsans==input)// if no error is present
- {
- cout<<"You Won the round!"<<endl;
- Restart = false; // to allow do loop to end
- system("Pause");
- }
- else if(qnsans!=input)
- {
- cout<<"try again"<<endl;
- Restart = true;
- }
- else
- {
- cout<<"try again"<<endl;
- Restart = true;
- }
- cin.clear(); //Restart error flag
- }
- }
- //minusplus
- void qns6()
- {
- srand (time(NULL));
- double qn1 = rand() % 200 + 1;
- double qn2 = rand() % 20 + 1;
- double QN3 = rand() % 10+1;
- double input;
- double qnsans;
- cout<<"Here is your question!"<<endl;
- cout<< qn1 <<"+"<< qn2<<"*"<<QN3<<endl;
- qnsans= qn1+(qn2*QN3);
- bool Restart=true;
- while(Restart==true)
- {
- cout<<"Enter your answer : ";
- cin>>input;
- Restart = cin.fail();
- if(cin.fail()==true)
- cout<<"\nError, Invalid Choice, Please Key in a Numerical Value\n";
- else if(qnsans==input)// if no error is present
- {
- cout<<"You Won the round!"<<endl;
- Restart = false; // to allow do loop to end
- system("Pause");
- }
- else if(qnsans!=input)
- {
- cout<<"try again"<<endl;
- Restart = true;
- }
- else
- {
- cout<<"try again"<<endl;
- Restart = true;
- }
- cin.clear(); //Restart error flag
- }
- }
- //plus times
- void qns7()
- {
- srand (time(NULL));
- double qn1 = rand() % 200 + 1;
- double qn2 = rand() % 20 + 1;
- double QN3 = rand() % 10+1;
- double input;
- double qnsans;
- cout<<"Here is your question!"<<endl;
- cout<< qn1 <<"-"<< qn2<<"*"<<QN3<<endl;
- qnsans= qn1-(qn2*QN3);
- bool Restart=true;
- while(Restart==true)
- {
- cout<<"Enter your answer : ";
- cin>>input;
- Restart = cin.fail();
- if(cin.fail()==true)
- cout<<"\nError, Invalid Choice, Please Key in a Numerical Value\n";
- else if(qnsans==input)// if no error is present
- {
- cout<<"You Won the round!"<<endl;
- Restart = false; // to allow do loop to end
- system("Pause");
- }
- else if(qnsans!=input)
- {
- cout<<"try again"<<endl;
- Restart = true;
- }
- else
- {
- cout<<"try again"<<endl;
- Restart = true;
- }
- cin.clear(); //Restart error flag
- }
- }
- //minus times
- void qns8()
- {
- srand (time(NULL));
- double qn1 = rand() % 200 + 1;
- double qn2 = rand() % 30 + 1;
- double QN3 = rand() % 10+1;
- double QN4 = rand() % 10+1;
- double input;
- double qnsans;
- cout<<"Here is your question!"<<endl;
- cout<< qn1 <<"+"<< qn2<<"*"<<QN3<<"-"<<QN4<<endl;
- qnsans= qn1+qn2*QN3-QN4;
- bool Restart=true;
- while(Restart==true)
- {
- cout<<"Enter your answer : ";
- cin>>input;
- Restart = cin.fail();
- if(cin.fail()==true)
- cout<<"\nError, Invalid Choice, Please Key in a Numerical Value\n";
- else if(qnsans==input)// if no error is present
- {
- cout<<"You Won the round!"<<endl;
- Restart = false; // to allow do loop to end
- system("Pause");
- }
- else if(qnsans!=input)
- {
- cout<<"try again"<<endl;
- Restart = true;
- }
- else
- {
- cout<<"try again"<<endl;
- Restart = true;
- }
- cin.clear(); //Restart error flag
- }
- }
- //plus times minus
- void qns9()
- {
- srand (time(NULL));
- double qn1 = rand() % 50 + 1;
- double qn2 = rand() % 20 + 1;
- double QN3 = rand() % 10+1;
- double QN4 = rand() % 10+1;
- double input;
- double qnsans;
- cout<<"Here is your question!"<<endl;
- cout<< qn1 <<"+"<< qn2<<"*"<<QN3<<"*"<<QN4<<endl;
- qnsans= qn1+qn2*QN3*QN4;
- bool Restart=true;
- while(Restart==true)
- {
- cout<<"Enter your answer : ";
- cin>>input;
- Restart = cin.fail();
- if(cin.fail()==true)
- cout<<"\nError, Invalid Choice, Please Key in a Numerical Value\n";
- else if(qnsans==input)// if no error is present
- {
- cout<<"You Won the round!"<<endl;
- Restart = false; // to allow do loop to end
- system("Pause");
- }
- else if(qnsans!=input)
- {
- cout<<"try again"<<endl;
- Restart = true;
- }
- else
- {
- cout<<"try again"<<endl;
- Restart = true;
- }
- cin.clear(); //Restart error flag
- }
- }
- //plus timestimes
- void qns10()
- {
- srand (time(NULL));
- double qn1 = rand() % 200 + 1;
- double qn2 = rand() % 20 + 1;
- double QN3 = rand() % 10+1;
- double QN4 = rand() % 20+1;
- double QN5 = rand() % 20+1;
- double input;
- double qnsans;
- cout<<"Here is your question!"<<endl;
- cout<< "("<<qn1 <<"-"<< qn2<<")"<<"*"<<QN3<<"*"<<QN4<<"+"<<QN5<<endl;
- qnsans= (qn1-qn2)*QN3*QN4+QN5;
- bool Restart=true;
- while(Restart==true)
- {
- cout<<"Enter your answer : ";
- cin>>input;
- Restart = cin.fail();
- if(cin.fail()==true)
- cout<<"\nError, Invalid Choice, Please Key in a Numerical Value\n";
- else if(qnsans==input)// if no error is present
- {
- cout<<"You Won the round!"<<endl;
- Restart = false; // to allow do loop to end
- system("Pause");
- }
- else if(qnsans!=input)
- {
- cout<<"try again"<<endl;
- Restart = true;
- }
- else
- {
- cout<<"try again"<<endl;
- Restart = true;
- }
- cin.clear(); //Restart error flag
- }
- }
- //(minus times) times plus
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement