This repository has been archived by the owner. It is now read-only.
Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
ALLGameGheorghe/InGameMenu.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
266 lines (207 sloc)
8.79 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <sstream> | |
#include <string> | |
#include <stdexcept> | |
#include <vector> | |
#include <iostream> | |
#include <openssl/md5.h> | |
#include <stdio.h> | |
#include <string.h> | |
using namespace std; | |
#include "libsqlite.hpp" | |
#include "md5.h" | |
#include <openssl/md5.h> | |
class PlayerInfo { | |
public: | |
//method to change the password | |
void changePassword(int Player_ID, sqlite::sqlite &db ) | |
{ | |
newpass: | |
string password, veriyPassword; | |
cout<<"Insert the new Password"<<endl; | |
do{ | |
cout << "Password: "; | |
cin >> password ; | |
cout << "Insert tha same password" << endl ; | |
cout << "Repeat Password: "; | |
cin >> veriyPassword ; | |
} | |
while(password != veriyPassword); | |
string ecryptedPassword = md5(password); // this is the funcition to encrypt the password, tha that i did some research about it ITS NOT MINE | |
//updting the password | |
auto cur = db.get_statement(); | |
cur->set_sql( " UPDATE Player SET Password = ? WHERE Player_ID = ? ; " ); | |
cur->prepare(); | |
cur->bind( 1, ecryptedPassword ); | |
cur->bind( 2, Player_ID ); | |
cur->step(); | |
int result= cur->step(); | |
if (result == 0) | |
{ | |
cout<<"Password Updated Successful"<<endl; | |
} | |
else | |
{ | |
cout<<"Something went wrong"<<endl << "Try Again" << endl; | |
goto newpass; | |
} //end else case | |
}//end changePassword | |
void updateDetails(int Player_ID, sqlite::sqlite &db) // function that alows the user to updtade his details like mail, mentality, age, favourite club. | |
{ | |
update: | |
string email, mentality, nationality, favourite_club; | |
int age; | |
cout << "Input your age"<< endl; | |
cin>> age; | |
cout << "Input your email"<< endl; | |
cin>> email; | |
cout << "Input your mentality"<< endl; | |
cin>> mentality; | |
cout << "Input your nationality"<< endl; | |
cin>> nationality; | |
cout << "Input your favourite club"<< endl; | |
cin>> favourite_club; | |
// updting details on BD | |
auto cur = db.get_statement(); | |
cur->set_sql( " UPDATE Player SET Email = ? , Mentality = ? , Age = ? , Nationality = ? , Club = ? WHERE Player_ID = ? ; " ); | |
cur->prepare(); | |
cur->bind( 1, email ); | |
cur->bind( 2, mentality ); | |
cur->bind( 3, age ); | |
cur->bind( 4, nationality ); | |
cur->bind( 5, favourite_club ); | |
cur->bind( 6, Player_ID ); | |
int result= cur->step(); | |
if (result == 0) | |
{ | |
cout<<"Details Updated Successful"<<endl; | |
} | |
else | |
{ | |
cout<<"Something went wrong"<<endl << "Try Again" << endl; | |
goto update; | |
} //end else case | |
} // end updateDetails | |
// sqlite::sqlite &db | |
// geting the details from the database and show | |
void printDetails(int Player_ID, sqlite::sqlite &db) | |
{ | |
auto cur = db.get_statement(); | |
cur->set_sql( " SELECT * FROM Player WHERE Player_ID = ? ; " ); | |
cur->prepare(); | |
cur->bind( 1, Player_ID ); | |
while( cur->step() ) | |
{ // loop over results# | |
cout << "*******************************\n"; | |
cout << "Here are you actual details"<< endl; | |
cout << "UserName:" << cur->get_text(1) << endl; | |
cout << "Email:" << cur->get_text(2) << endl; | |
cout << "Mentality:" << cur->get_text(4) << endl; | |
cout << "Age:" << cur->get_int(5) << endl; | |
cout << "Nationality:" << cur->get_text(6) << endl; | |
cout << "Favorite Club:" << cur->get_text(7) << endl; | |
cout << "*******************************\n"; | |
} | |
}// end printDetails | |
};// end clas PlayerInfo | |
// // function to display the Menu after you logged in | |
int MenuGame(int Player_ID, sqlite::sqlite &db){ | |
char choice; | |
//sqlite::sqlite db( "ball.sqlite" ); | |
MenuInGame: | |
do | |
{ | |
cout << "*******************************\n"; | |
cout << " 1 - Play Game."<< endl; | |
cout << " 2 - Manage My Team "<< endl; | |
cout << " 3 - Market"<< endl; | |
cout << " 4 - Setings "<< endl; | |
cout << " 5 - Exit."<< endl; | |
cout << " Enter your choice and press return: "; | |
cin >> choice; | |
} // end of do while | |
while (choice >'5' || choice<'0' ); | |
switch (choice) | |
{ | |
case '1': | |
{ | |
cout<< "Not available yet..."<< endl ; | |
goto MenuInGame; | |
break; | |
} // end case 1 play game | |
case '2': | |
{ | |
cout<< "Not available yet..."<< endl ; | |
goto MenuInGame; | |
break; | |
}//end case 2 my team | |
case '3':{ | |
cout<< "Not available yet..."<< endl ; | |
goto MenuInGame; | |
break; | |
}// end case 3 market | |
case '4':{ | |
MenuSettings: | |
do | |
{ | |
cout << "*******************************\n"; | |
cout << " 1 - Personalize yourself"<< endl; | |
cout << " 2 - Change Password "<< endl; | |
cout << " 3 - Show Details"<< endl; | |
cout << " 4 - Go Back"<< endl; | |
cout << " Enter your choice and press return: "; | |
cin >> choice; | |
} // end of do while | |
while (choice >'4' || choice<'0' ); | |
switch (choice) | |
{ | |
case '1': | |
{ | |
PlayerInfo obj1; | |
obj1.printDetails(Player_ID, db); | |
obj1.updateDetails(Player_ID, db); | |
goto MenuSettings; | |
break; | |
} // end case 1 personalize yourself | |
case '2': | |
{ | |
PlayerInfo obj1; | |
obj1.changePassword(Player_ID, db); | |
goto MenuSettings; | |
break; | |
}//end case 2 change password | |
case '3':{ | |
PlayerInfo obj1; | |
obj1.printDetails(Player_ID, db); | |
goto MenuSettings; | |
break; | |
}// end case 3 Go Back | |
case '4':{ | |
goto MenuInGame; | |
break; | |
}// end case 3 Go Back | |
default: | |
{ | |
cout << "Not a Valid Choice."<< endl; | |
cout << "Choose again."<< endl; | |
goto MenuSettings; | |
break; | |
}// end default case MenuSettings | |
return 0; | |
}// end of menuSettings | |
break; | |
} // end Menu Setings | |
case '5':{ | |
cout << "End of Program."<< endl; | |
break; | |
} | |
default: | |
{ | |
cout << "Not a Valid Choice."<< endl; | |
cout << "Choose again."<< endl; | |
goto MenuInGame; | |
break; | |
}// end default case | |
return 0; | |
}// end of menu | |
}// end of MenuGame function |