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 <random>
#include "libsqlite.hpp" // sqlite library
#include <sstream>
#include <string>
using namespace std;
void deck_1()
{
sqlite::sqlite db( "table_2.sqlite" ); // open database
auto cur = db.get_statement(); // create query
cur->set_sql("SELECT * FROM table_2 ORDER BY random() LIMIT 4 ;");
cur->prepare(); // run query
cur->step();
string name, attack_1, attack_2, attack_3;
name = cur->get_text(0);
attack_1 = cur->get_text(1);
attack_2 = cur->get_text(2);
attack_3 = cur->get_text(3);
//while( cur->step() ) // loop over results
// cout << cur->get_text(0) << "\nAttack 1: " << cur->get_text(1) << "\nAttack 2: " << cur->get_text(2) << "\nAttack 3: " << cur->get_text(3) <<"\n "<< endl;
while( cur->step() ) // loop over results
cout << cur->get_text(0) << "\nAttack 1: " << cur->get_text(1) << "\nAttack 2: " << cur->get_text(2) << "\nAttack 3: " << cur->get_text(3) <<"\n ";
}
void deck_2()
{
sqlite::sqlite db( "table_3.sqlite" ); // open database
auto cur = db.get_statement(); // create query
cur->set_sql( "SELECT * FROM table_3 ORDER BY random() LIMIT 4 ;");
cur->prepare(); // run query
cur->step();
string attack_1, attack_2;
attack_1 = cur->get_text(0);
attack_2 = cur->get_text(1);
while( cur->step() ) // loop over results
cout << cur->get_text(0) << "\nAttack 1: " << cur->get_text(1) << "\nAttack 2: " << cur->get_text(2) << "\nAttack 3: " << cur->get_text(3) <<"\n ";
}
void player_data()
{
sqlite::sqlite db( "table_3.sqlite" ); // open database
auto cur = db.get_statement(); // create query
cur->set_sql( "INSERT INTO player_data VALUES(");
cur->prepare(); // run query
}
void deck2_set()
{
string player_card;
cout << "Player 2 Enter Card name: " ;
cin >> player_card ;
std::ostringstream oss;
//oss << "sometext" << somevar << "sometext" << somevar;
oss << "SELECT * FROM table_3 WHERE Name = " << " \"" <<player_card << "\"" << ";";
std::string var = oss.str();
//cout << oss.str() << endl;
sqlite::sqlite db( "table_3.sqlite" ); // open database
auto cur = db.get_statement(); // create query
cur->set_sql( oss.str());
cur->prepare(); // run query
cur->step();
string name, attack_1, attack_2, attack_3;
int attack_4, Attack1, Attack2,Attack3, result, answer, d_attk, d_attk2;
name = cur->get_text(0);
attack_1 = cur->get_text(1);
attack_2 = cur->get_text(2);
attack_3 = cur->get_text(3);
d_attk = 100;
d_attk2 =24;
std::istringstream ( attack_1 ) >> Attack1;
std::istringstream ( attack_2 ) >> Attack2;
std::istringstream ( attack_3 ) >> Attack3;
result = 100;
answer = result - Attack1;
cout << cur->get_text(0) << "\nAttack 1: " << cur->get_text(1) << "\nAttack 2: " << cur->get_text(2) << "\nAttack 3: " << cur->get_text(3) <<"\n "<< endl;
cout << name << endl;
cout << "A>> ATTACK 1: " << Attack1 << endl;
cout << "B>> ATTACK 2: " << Attack2 << endl;
cout << "C>> ATTACK 3: " << Attack3 << endl;
cout << " " << endl;
string choice;
cout << "Enter Card: " << endl;
cin >> choice;
if(choice == "A")
if (Attack1 > d_attk)
cout << "Player 1 Wins!"<<endl;
else if (Attack1 < d_attk)
cout << "Player 2 Wins !" << endl;
else
cout << "Players have Tied" << endl;
else if(choice == "B")
if (Attack2 > d_attk2)
cout << "Player 1 Wins!"<<endl;
else if (Attack2 < d_attk2)
cout << "Player 2 Wins !" << endl;
else
cout << "Players have Tied" << endl;
}
void deck1_set()
{
string player_card;
cout << "Player 1 Enter Card name: " ;
cin >> player_card ;
std::ostringstream oss;
//oss << "sometext" << somevar << "sometext" << somevar;
oss << "SELECT * FROM table_2 WHERE Name = " << " \"" <<player_card << "\"" << ";";
std::string var = oss.str();
//cout << oss.str() << endl;
sqlite::sqlite db( "table_2.sqlite" ); // open database
auto cur = db.get_statement(); // create query
cur->set_sql( oss.str());
cur->prepare(); // run query
cur->step();
string names, attack_5, attack_6, attack_7;
int attack_8, Attack5, Attack6,Attack7;
names = cur->get_text(0);
attack_5 = cur->get_text(1);
attack_6 = cur->get_text(2);
attack_7 = cur->get_text(3);
std::istringstream ( attack_5 ) >> Attack5;
std::istringstream ( attack_6 ) >> Attack6;
std::istringstream ( attack_7 ) >> Attack7;
cout << cur->get_text(0) << "\nAttack 1: " << cur->get_text(1) << "\nAttack 2: " << cur->get_text(2) << "\nAttack 3: " << cur->get_text(3) <<"\n "<< endl;
cout << names << endl;
cout << Attack5 << endl;
cout << Attack6 << endl;
cout << Attack7 << endl;
}
int main()
{
cout << "PLAYER 1 DECK! " << endl;
deck_1();
cout << " " << endl;
cout << "PLAYER 2 DECK! " << endl;
deck_2();
//name_search_engine();
deck1_set();
deck2_set();
}