Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
462662ec42
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time
258 lines (195 sloc) 9.01 KB
#include <vector>
#include <iostream>
#include <sstream>
#include <string>
#include <stdexcept>
using namespace std;
#include "libsqlite.hpp"
#include "InGameMenu.cpp"
int createTeam(int Player_ID, string teamName)
{
cout << Player_ID<<endl;
cout << "team name ";
cout<< teamName<<endl;
sqlite::sqlite db( "ball.sqlite" );
auto cur = db.get_statement();
// create the team in MyTeam table
//try
//{
//
cur->set_sql( "INSERT INTO MyTeam (Player_ID, TeamName) VALUES (?,?);" );
cur->prepare();
cur->bind( 1, Player_ID );
cur->bind( 2, teamName );
int insertt =cur->step();
if(insertt=true)
{
cout<<"insert true, "<<endl;
}
//}
//catch( sqlite::exception e )
//{
//cerr << e.what() << endl;
//return 1;
//} // end if registatin fails i dk
return 0;
}
// First menu, this will be showed when u start
char menuu()
{
char choice;
MainMenu:
do
{
cout << "*******************************\n";
cout << " 1 - Login."<< endl;
cout << " 2 - Register "<< endl;
cout << " 3 - Credits."<< endl;
cout << " 4 - Exit."<< endl;
cout << " Enter your choice and press return: ";
cin >> choice;
} // end of do while
while (choice >'5' || choice<'0' );
switch (choice)
{
case '1':
{
string username, password;
bool Blog = false;
// login part
logs:
cout << "ID: ";
cin >> username ;
cout << "Password: ";
cin >> password ;
cout << "Checking Data..." << endl ;
// cheking on the data base
sqlite::sqlite db( "ball.sqlite" );
auto cur = db.get_statement();
try
{
cur->set_sql( "SELECT Player_ID FROM Player "
"WHERE UserName = ? AND Password = ?;" );
cur->prepare();
cur->bind( 1, username );
cur->bind( 2, password );
int result= cur->step();
int Player_ID = cur->get_int(0); // to get the playerID (unique identification on DB)
if (result == true){
cout<<"login Sucessful"<<endl;
MenuGame(Player_ID);
}
else{
cout<<"Username of password are wrong"<<endl;
} //end else case
}
catch( sqlite::exception e )
{
cerr << e.what() << endl;
return 1;
}
break;
}
case '2':
{
string username, email, password, veriyPassword, teamName;
regist:
// login part
cout << "ID: ";
cin >> username ;
do{
cout << "Password: ";
cin >> password ;
cout << "Insert tha same password" << endl ;
cout << "Repeat Password: ";
cin >> veriyPassword ;
}
while(password != veriyPassword);
cout << "Email: ";
cin >> email ;
cout << "Team Name: ";
cin >> teamName ;
cout << "Processing Data" << endl ;
cout << ""<< endl;
//check if already with same user name
sqlite::sqlite db( "ball.sqlite" );
auto cur = db.get_statement();
try
{
cur->set_sql( "SELECT * FROM Player "
"WHERE UserName = ? OR Email = ?;" );
cur->prepare();
cur->bind( 1, username );
cur->bind( 2, email );
int result= cur->step();
if (result == true){
cout<<"The username or email are already in use!"<<endl;
goto regist;
}
else{
//registin part
// sqlite::sqlite db( "ball.sqlite" );
cur = db.get_statement();
try
{
cur->set_sql( "INSERT INTO Player (UserName, Email,Password) "
"VALUES (?, ?,?);" );
cur->prepare();
cur->bind( 1, username );
cur->bind( 2, email );
cur->bind( 3, password );
cur->step();
cout<<"Registed Sucessful"<<endl;
cout<<endl<<endl;
}
catch( sqlite::exception e )
{
cerr << e.what() << endl;
return 1;
} // if registatin fails
// // to get the playerID (unique identification on DB)
// sqlite::sqlite db( "ball.sqlite" );
cur = db.get_statement();
try
{
cur->set_sql( "SELECT Player_ID FROM Player "
"WHERE UserName = ? AND Password = ?;" );
cur->prepare();
cur->bind( 1, username );
cur->bind( 2, password );
int result= cur->step();
int Player_ID = cur->get_int(0);
//sqlite::sqlite3_close(db);
cout<<teamName<<endl;
cout<<Player_ID<<endl;
cur = NULL;
createTeam(Player_ID,teamName); // caling to create a team
}
catch( sqlite::exception e )
{
cerr << e.what() << endl;
return 1;
}// end of getting the ID
}
}
catch( sqlite::exception e )
{
cerr << e.what() << endl;
return 1;
} // if checking if the user already exists fails
break;
}
case '3':
cout << "Group E7"<< endl;
break;
case '4':
cout << "End of Program."<< endl;
break;
default:
cout << "Not a Valid Choice."<< endl;
cout << "Choose again."<< endl;
goto MainMenu;
break;
}
return 0;
}// end of menu