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 <vector>
#include <iostream>
#include <sstream>
#include<string>
#include "libsqlite.hpp"
using namespace std; //declaring global variables
int Inteligencee,Mightt,Malicee,Defensee,Agilityy; //declaring global variables
int Inteligencee2,Mightt2,Malicee2,Defensee2,Agilityy2; //declaring global variables
void playerDeck ()
{
sqlite::sqlite db( "main.sqlite" ); //connects the database
auto cur = db.get_statement();
cur->set_sql( "SELECT * FROM 'rpg_cards_pack_1' ORDER BY random() LIMIT 5"); //create query which draws 5 random records from the db
cur->prepare(); //run query
string Name;
int Attack1, Attack2, Attack3, Attack4, Attack5;
cout <<" Player 1 DECK" << endl;
cout <<"---------------------------------"<< endl;
while(cur->step()) {
Name = cur->get_text(0); //Assigning the fields of each record to the global variables
Inteligencee = cur->get_int(1);
Mightt = cur->get_int(2);
Malicee = cur->get_int(3);
Defensee = cur->get_int(4);
Agilityy = cur->get_int(5);
cout << "Name: "<<Name<< endl;
cout <<"---------------------------------"<< endl;
}
}
void specificCardChoose() //A Function Which You choose your card according to the Name you input
{
string player_card;
cout << "Player 1 Enter Card name: " ;
cin >> player_card ;
sqlite::sqlite db( "main.sqlite" ); //connects the db
auto cur = db.get_statement(); // create query
cur->set_sql("SELECT * FROM 'rpg_cards_pack_1'"
"WHERE NAME = (?1)");
cur->prepare(); //runing the query
cur->bind(1,player_card); //binding the value to the set_sql
int Attack1, Attack2, Attack3, Attack4, Attack5;
string nam;
while(cur->step()){
cout<< nam <<endl;
nam = cur->get_text(0);
Attack1 = cur->get_int(1); //assigining 1 random record fields to
//some variables inside a function and then print them
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(){ //A function which compares values to determine the winner
string Choice;
cout<<"What Stat would you like to choose?"<<endl;
cout<<"Choose from A to E!"<<endl;
cin>>Choice;
if (Choice=="A"){
if (Inteligencee>Inteligencee2){
cout<<"Player 1 Inteligence is: "<<Inteligencee<<endl;
cout<<"Computer Inteligence is: "<<Inteligencee2<<endl;
cout<<"========================"<<endl;
cout<<"Player 1 Wins the Round!"<<endl;
cout<<"========================"<<endl;}
if(Inteligencee<Inteligencee2){
cout<<"Player 1 Inteligence is: "<<Inteligencee<<endl;
cout<<"Computer Inteligence is: "<<Inteligencee2<<endl;
cout<<"========================"<<endl;
cout<<"Computer Wins the Round!"<<endl;
cout<<"========================"<<endl;}
if(Inteligencee==Inteligencee2){
cout<<"Player 1 Inteligence is: "<<Inteligencee<<endl;
cout<<"Computer Inteligence is: "<<Inteligencee2<<endl;
cout<<"========================"<<endl;
cout<<"This Round is a Tie!"<<endl;
cout<<"========================"<<endl;}
}
if (Choice=="B"){
if (Mightt>Mightt2){
cout<<"Player 1 Might is: "<<Mightt<<endl;
cout<<"Computer Might is: "<<Mightt2<<endl;
cout<<"Player 1 Wins the Round!"<<endl;
cout<<"======================"<<endl;}
if(Mightt<Mightt2){
cout<<"Player 1 Might is: "<<Mightt<<endl;
cout<<"Computer Might is: "<<Mightt2<<endl;
cout<<"Computer Wins the Round!"<<endl;
cout<<"======================"<<endl;}
if(Mightt==Mightt2){
cout<<"Player 1 Might is: "<<Mightt<<endl;
cout<<"Computer Might is: "<<Mightt2<<endl;
cout<<"This Round is a Tie!"<<endl;
cout<<"======================"<<endl;}
}
if (Choice=="C"){
if (Malicee>Malicee2){
cout<<"Player 1 Malice is: "<<Malicee<<endl;
cout<<"Computer Malice is: "<<Malicee2<<endl;
cout<<"========================"<<endl;
cout<<"Player 1 Wins the Round!"<<endl;
cout<<"========================"<<endl;}
if(Malicee<Malicee2){
cout<<"Player 1 Malice is: "<<Malicee<<endl;
cout<<"Computer Malice is: "<<Malicee2<<endl;
cout<<"========================"<<endl;
cout<<"Computer Wins the Round!"<<endl;
cout<<"========================"<<endl;}
if(Malicee==Malicee2){
cout<<"Player 1 Malice is: "<<Malicee<<endl;
cout<<"Computer Malice is: "<<Malicee2<<endl;
cout<<"========================"<<endl;
cout<<"This Round is a Tie!"<<endl;
cout<<"========================"<<endl;}
}
if (Choice=="D"){
if (Defensee>Defensee2){
cout<<"Player 1 Defense is: "<<Defensee<<endl;
cout<<"Computer Defense is: "<<Defensee2<<endl;
cout<<"========================"<<endl;
cout<<"Player 1 Wins the Round!"<<endl;
cout<<"========================"<<endl;}
if(Defensee<Defensee2){
cout<<"Player 1 Defense is: "<<Defensee<<endl;
cout<<"Computer Defense is: "<<Defensee2<<endl;
cout<<"========================"<<endl;
cout<<"Computer Wins the Round!"<<endl;
cout<<"========================"<<endl;}
if(Defensee==Defensee2){
cout<<"Player 1 Defense is: "<<Defensee<<endl;
cout<<"Computer Defense is: "<<Defensee2<<endl;
cout<<"========================"<<endl;
cout<<"This Round is a Tie!"<<endl;
cout<<"========================"<<endl;}
}
if (Choice=="E"){
if (Agilityy>Agilityy2){
cout<<"Player 1 Agility is: "<<Agilityy<<endl;
cout<<"Computer Agility is: "<<Agilityy2<<endl;
cout<<"========================"<<endl;
cout<<"Player 1 Wins the Round!"<<endl;
cout<<"========================"<<endl;}
if(Agilityy<Agilityy2){
cout<<"Player 1 Agility is: "<<Agilityy<<endl;
cout<<"Computer Agility is: "<<Agilityy2<<endl;
cout<<"========================"<<endl;
cout<<"Computer Wins the Round!"<<endl;
cout<<"========================"<<endl;}
if(Agilityy==Agilityy2){
cout<<"Player 1 Agility is: "<<Agilityy<<endl;
cout<<"Computer Agility is: "<<Agilityy2<<endl;
cout<<"========================"<<endl;
cout<<"This Round is a Tie!"<<endl;
cout<<"========================"<<endl;}
}
}
void pcDeck () //This Function choose randmly each round a card for the PC
{
sqlite::sqlite db( "main.sqlite" ); //connects the db
auto cur = db.get_statement();
cur->set_sql( "SELECT * FROM 'rpg_cards_pack_1' ORDER BY random() LIMIT 1"); //create a query which randomly selects 1 record
cur->prepare(); //run query
string Name;
int Attack1, Attack2, Attack3, Attack4, Attack5;
cout <<" Computer DECK" << endl;
cout <<"---------------------------------"<< endl;
while(cur->step()) {
Name = cur->get_text(0);
Inteligencee2 = cur->get_int(1);
Mightt2 = cur->get_int(2);
Malicee2 = cur->get_int(3);
Defensee2 = cur->get_int(4);
Agilityy2 = cur->get_int(5);
cout << "Name: "<<Name<< endl;
cout <<"---------------------------------"<< endl;
}
}
int main(){
playerDeck();
cout<<""<<endl;
pcDeck();
cout<<""<<endl;
for( int a = 0; a <5; a = a + 1 ) {
specificCardChoose();
comparisonCalc();
}
return 0;
}