Skip to content
Permalink
master
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
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include "libsqlite.hpp"
using namespace std;
int Inteligence,Might,Malice,Defense,Agility;
int Inteligence2,Might2,Malice2,Defense2,Agility2;
int win_status = 1;
int sScore;
int score1 = 0;
int score2 = 0;
string highScoreShow;
string scoreName;
void playerDeck ()
{
sqlite::sqlite db( "rpg_cards_pack_1.sqlite" );
auto cur = db.get_statement();
cur->set_sql( "SELECT * FROM 'Table 1' ORDER BY random() LIMIT 5");
cur->prepare();
string Name;
int Attack1, Attack2, Attack3, Attack4, Attack5;
cout <<" Player 1 DECK" << endl;
cout <<"---------------------------------"<< endl;
while(cur->step()) {
Name = cur->get_text(0);
Inteligence = cur->get_int(1);
Might = cur->get_int(2);
Malice = cur->get_int(3);
Defense = cur->get_int(4);
Agility = cur->get_int(5);
cout << "Name: "<<Name<< endl;
cout <<"---------------------------------"<< endl;
}
}
void specificCardChoose()
{
string player_card;
cout << "Player 1 Enter Card name: " ;
cin >> player_card ;
sqlite::sqlite db( "rpg_cards_pack_1.sqlite" );
auto cur = db.get_statement(); // create query
cur->set_sql("SELECT * FROM 'Table 1'"
"WHERE NAME = (?1)");
cur->prepare();
cur->bind(1,player_card);
int Attack1, Attack2, Attack3, Attack4, Attack5;
string nam;
vector<int>attacks;
while(cur->step()){
cout<< nam <<endl;
nam = cur->get_text(0);
Attack1 = cur->get_int(1);
Attack2 = cur->get_int(2);
Attack3 = cur->get_int(3);
Attack4 = cur->get_int(4);
Attack5 = cur->get_int(5);
cout<<nam<<endl;
cout<<"A: "<<"Inteligence --> "<<Attack1<<endl;
cout<<"B: "<<"Might --> "<<Attack2<<endl;
cout<<"C: "<<"Malice --> "<<Attack3<<endl;
cout<<"D: "<<"Defense --> "<<Attack4<<endl;
cout<<"E: "<<"Agility --> "<<Attack5<<endl;
}
}
void comparisonCalc(){
string Choice;
cout<<"What Stat would you like to choose?"<<endl;
cout<<"Choose from A to E!"<<endl;
cin>>Choice;
if ((Choice=="A") || (Choice=="a")){
if (Inteligence>Inteligence2){
cout<<"Player 1 Inteligence is: "<<Inteligence<<endl;
cout<<"Computer Inteligence is: "<<Inteligence2<<endl;
cout<<"========================"<<endl;
cout<<"Player 1 Wins the Round!"<<endl;
cout<<"========================"<<endl;
score1=score1+20;}
if(Inteligence<Inteligence2){
cout<<"Player 1 Inteligence is: "<<Inteligence<<endl;
cout<<"Computer Inteligence is: "<<Inteligence2<<endl;
cout<<"========================"<<endl;
cout<<"Computer Wins the Round!"<<endl;
cout<<"========================"<<endl;
score2=score2+20;}
if(Inteligence==Inteligence2){
cout<<"Player 1 Inteligence is: "<<Inteligence<<endl;
cout<<"Computer Inteligence is: "<<Inteligence2<<endl;
cout<<"========================"<<endl;
cout<<"This Round is a Tie!"<<endl;
cout<<"========================"<<endl;}
}
if ((Choice=="B") || (Choice=="b")){
if (Might>Might2){
cout<<"Player 1 Might is: "<<Might<<endl;
cout<<"Computer Might is: "<<Might2<<endl;
cout<<"Player 1 Wins the Round!"<<endl;
cout<<"======================"<<endl;
score1=score1+20;}
if(Might<Might2){
cout<<"Player 1 Might is: "<<Might<<endl;
cout<<"Computer Might is: "<<Might2<<endl;
cout<<"Computer Wins the Round!"<<endl;
cout<<"======================"<<endl;
score2=score2+20;}
if(Might==Might2){
cout<<"Player 1 Might is: "<<Might<<endl;
cout<<"Computer Might is: "<<Might2<<endl;
cout<<"This Round is a Tie!"<<endl;
cout<<"======================"<<endl;}
}
if ((Choice=="C") || (Choice=="c")){
if (Malice>Malice2){
cout<<"Player 1 Malice is: "<<Malice<<endl;
cout<<"Computer Malice is: "<<Malice2<<endl;
cout<<"========================"<<endl;
cout<<"Player 1 Wins the Round!"<<endl;
cout<<"========================"<<endl;
score1=score1+20;}
if(Malice<Malice2){
cout<<"Player 1 Malice is: "<<Malice<<endl;
cout<<"Computer Malice is: "<<Malice2<<endl;
cout<<"========================"<<endl;
cout<<"Computer Wins the Round!"<<endl;
cout<<"========================"<<endl;
score2=score2+20;}
if(Malice==Malice2){
cout<<"Player 1 Malice is: "<<Malice<<endl;
cout<<"Computer Malice is: "<<Malice2<<endl;
cout<<"========================"<<endl;
cout<<"This Round is a Tie!"<<endl;
cout<<"========================"<<endl;}
}
if ((Choice=="D") || (Choice=="d")){
if (Defense>Defense2){
cout<<"Player 1 Defense is: "<<Defense<<endl;
cout<<"Computer Defense is: "<<Defense2<<endl;
cout<<"========================"<<endl;
cout<<"Player 1 Wins the Round!"<<endl;
cout<<"========================"<<endl;
score1=score1+20;}
if(Defense<Defense2){
cout<<"Player 1 Defense is: "<<Defense<<endl;
cout<<"Computer Defense is: "<<Defense2<<endl;
cout<<"========================"<<endl;
cout<<"Computer Wins the Round!"<<endl;
cout<<"========================"<<endl;
score2=score2+20;}
if(Defense==Defense2){
cout<<"Player 1 Defense is: "<<Defense<<endl;
cout<<"Computer Defense is: "<<Defense2<<endl;
cout<<"========================"<<endl;
cout<<"This Round is a Tie!"<<endl;
cout<<"========================"<<endl;}
}
if ((Choice=="E") || (Choice=="e")){
if (Agility>Agility2){
cout<<"Player 1 Agility is: "<<Agility<<endl;
cout<<"Computer Agility is: "<<Agility2<<endl;
cout<<"========================"<<endl;
cout<<"Player 1 Wins the Round!"<<endl;
cout<<"========================"<<endl;
score1=score1+20;}
if(Agility<Agility2){
cout<<"Player 1 Agility is: "<<Agility<<endl;
cout<<"Computer Agility is: "<<Agility2<<endl;
cout<<"========================"<<endl;
cout<<"Computer Wins the Round!"<<endl;
cout<<"========================"<<endl;
score2=score2+20;}
if(Agility==Agility2){
cout<<"Player 1 Agility is: "<<Agility<<endl;
cout<<"Computer Agility is: "<<Agility2<<endl;
cout<<"========================"<<endl;
cout<<"This Round is a Tie!"<<endl;
cout<<"========================"<<endl;}
}
}
void pcDeck ()
{
sqlite::sqlite db( "rpg_cards_pack_1.sqlite" );
auto cur = db.get_statement();
cur->set_sql( "SELECT * FROM 'Table 1' ORDER BY random() LIMIT 1");
cur->prepare();
string Name;
int Attack1, Attack2, Attack3, Attack4, Attack5;
cout <<" Computer DECK" << endl;
cout <<"---------------------------------"<< endl;
while(cur->step()) {
Name = cur->get_text(0);
Inteligence2 = cur->get_int(1);
Might2 = cur->get_int(2);
Malice2 = cur->get_int(3);
Defense2 = cur->get_int(4);
Agility2 = cur->get_int(5);
cout << "Name: "<<Name<< endl;
cout <<"---------------------------------"<< endl;
}
}
void scorePrint ()// this function will print the High Score database
{
sqlite::sqlite db( "Leaderboard.sqlite" ); // open database
auto cur = db.get_statement(); // create query
cur->set_sql( "SELECT * FROM 'Leaderboard' "
"WHERE Highscore =(?1)");
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()
{
playerDeck();
cout<<""<<endl;
pcDeck();
cout<<""<<endl;
for( int a = 0; a <5; a = a + 1 ) {
specificCardChoose();
comparisonCalc();
}
string player1 = "Player1";
string player2 = "Player2";
/*
string player_card;
cout << "Player 1 Enter Card name: " ;
cin >> player_card ;
sqlite::sqlite db( "rpg_cards_pack_1.sqlite" );
auto cur = db.get_statement(); // create query
cur->set_sql("SELECT * FROM 'Table 1'"
"WHERE NAME = (?1)");
cur->prepare();
cur->bind(1,player_card);
*/
cout<<"Player Score is >>> "<<score1<<endl;
cout<<"Computer Score is >>>"<<score2<<endl;
if (score1>score2){
cout<<"What Name You Want in Leaderboard? "<<endl;
cin>>scoreName;
sqlite::sqlite db( "Leaderboard.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)
{
cout<<"What Name You Want in Leaderboard? "<<endl;
cin>>scoreName;
sqlite::sqlite db( "Leaderboard.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();
}
cout<<"Do You Want To Show The Leaderboard?"<<endl;
cout<<"(Yes or No)"<<endl;
cin>> highScoreShow;
if (highScoreShow=="Yes"){
scorePrint();
}
return 0;
}