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?
Old-School-Game/LeaderBoards.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
86 lines (69 sloc)
2.18 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
//Author Nicolas MAxoutis | |
#include <iostream> | |
#include <string> | |
#include <fstream> | |
#include <vector> | |
#include "libsqlite.hpp" | |
using namespace std; | |
//Declaring global virables | |
int sScore; | |
int score1 = 0; | |
int score2 = 0; | |
string scoreName; | |
string highScoreShow; | |
void scorePrint ()// this function will print the High Score database | |
{ | |
sqlite::sqlite db( "main.sqlite" ); // open database | |
auto cur = db.get_statement(); // create query | |
cur->set_sql( "SELECT * FROM 'Leaderboard' "); | |
cur->prepare(); // run query | |
string tName; | |
while(cur->step()){ | |
tName = cur->get_text(0); | |
sScore = cur-> get_int(1); | |
cout <<"Name "<< " Score"<<endl; | |
cout<<""<<endl; | |
cout <<tName<<" "<<sScore<<endl; | |
cout<<""<<endl; | |
} | |
} | |
int main() | |
{ | |
string player1 = "Player1"; | |
string player2 = "Player2"; | |
cout<<"Player Score is >>> "<<score1<<endl; | |
cout<<"Computer Score is >>>"<<score2<<endl; | |
if (score1>score2){ //if score1 is more than score2 score1 will go in the database | |
cout<<"What Name You Want in Leaderboard? "<<endl; | |
cin>>scoreName; | |
sqlite::sqlite db( "main.sqlite" ); // open database | |
auto cur = db.get_statement(); // create query | |
cur->set_sql( "INSERT INTO Leaderboard(Name, Highscore)" | |
" VALUES((?1), (?2))" ); | |
cur->prepare(); // run query | |
cur->bind(1,scoreName); | |
cur->bind(2,score1); | |
cur->step(); | |
} | |
else if (score1<score2)//if score2 is more than score1 score2 will go in the database | |
{ | |
cout<<"What Name You Want in Leaderboard? "<<endl; | |
cin>>scoreName; | |
sqlite::sqlite db( "main.sqlite" ); // open database | |
auto cur= db.get_statement(); // create query | |
cur->set_sql( "INSERT INTO Leaderboard(Name, Highscore)" | |
" VALUES((?1), (?2))" ); | |
cur->prepare(); // run query | |
cur->bind(1,scoreName); | |
cur->bind(2,score2); | |
cur->step(); | |
} | |
//An option to ask the player to print or not the leaderboards | |
cout<<"Do You Want To Show The Leaderboard?"<<endl; | |
cout<<"(Yes or No)"<<endl; | |
cin>> highScoreShow; | |
if (highScoreShow=="Yes"){ | |
scorePrint(); | |
} | |
return 0; | |
} |