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 "libsqlite.hpp" // sqlite library
#include <sstream>
#include <string>
#include <vector>
#include <fstream>
using namespace std;
// Global variable declaration:
string name, malice, might, inteligence, agility, defense;
int Malice, Might, Inteligence, Agility, Defense;
string malice_2, might_2, inteligence_2, agility_2, defense_2;
int Malice2, Might2, Inteligence2, Agility2, Defense2;
void deck_1()
{
sqlite::sqlite db( "rpg_cards_pack_1.sqlite" ); // open database
auto cur = db.get_statement(); // create query
cur->set_sql("SELECT name FROM 'Table 1' ORDER BY random() LIMIT 5 ;");
cur->prepare(); // run query
ofstream myfile;
myfile.open ("player_deck.txt");
while( cur->step() ) // loop over results
myfile << cur->get_text(0) << endl ;
myfile.close();
}
void deck_2()
{
sqlite::sqlite db( "rpg_cards_pack_2.sqlite" ); // open database
auto cur = db.get_statement(); // create query
cur->set_sql( "SELECT name FROM 'Table 1' ORDER BY random() LIMIT 5 ;");
cur->prepare(); // run query
ofstream myfile;
myfile.open ("player_deck2.txt");
while( cur->step() ) // loop over results
myfile << cur->get_text(0) << endl ;
myfile.close();
}
void output_deck1()
{
string player1_deck;
ifstream openfile ("player_deck.txt");
if(openfile.is_open())
{
while(! openfile.eof())
{
getline(openfile, player1_deck);
cout << " " << player1_deck << endl;
}
}
}
void output_deck2()
{
string player2_deck;
ifstream openfile ("player_deck2.txt");
if(openfile.is_open())
{
while(! openfile.eof())
{
getline(openfile, player2_deck);
cout << " " << player2_deck << endl;
}
}
}
void deck1_set()
{
string player_card;
cout << "Player 1 Enter Card name: " ;
cin >> player_card ;
std::ostringstream oss;
oss << "SELECT * FROM 'Table 1' WHERE Name = " << " \"" << player_card << "\"" << ";";
std::string var = oss.str();
sqlite::sqlite db( "rpg_cards_pack_1.sqlite" ); // open database
auto cur = db.get_statement(); // create query
cur->set_sql( oss.str());
cur->prepare(); // run query
cur->step();
name = cur->get_text(0);
malice = cur->get_text(1);
might = cur->get_text(2);
inteligence = cur->get_text(3);
agility = cur->get_text(4);
defense = cur->get_text(5);
std::istringstream ( malice ) >> Malice;
std::istringstream ( might ) >> Might;
std::istringstream ( inteligence ) >> Inteligence;
std::istringstream ( agility ) >> Agility;
std::istringstream ( defense ) >> Defense;
}
void deck2_set()
{
string player_card;
cout << "Player 2 Enter Card name: " ;
cin >> player_card ;
std::ostringstream oss;
oss << "SELECT * FROM 'Table 1' WHERE Name = " << " \"" << player_card << "\"" << ";";
std::string var = oss.str();
sqlite::sqlite db( "rpg_cards_pack_2.sqlite" ); // open database
auto cur = db.get_statement(); // create query
cur->set_sql( oss.str());
cur->prepare(); // run query
cur->step();
name = cur->get_text(0);
malice_2 = cur->get_text(1);
might_2 = cur->get_text(2);
inteligence_2 = cur->get_text(3);
agility_2 = cur->get_text(4);
defense_2 = cur->get_text(5);
std::istringstream ( malice_2 ) >> Malice2;
std::istringstream ( might_2 ) >> Might2;
std::istringstream ( inteligence_2 ) >> Inteligence2;
std::istringstream ( agility_2 ) >> Agility2;
std::istringstream ( defense_2 ) >> Defense2;
}
void comp_sys()
{
string choice;
cout << "Enter Card Stats: ";
cin >> choice;
if(choice == "A" or choice == "a")
if (Malice > Malice2)
cout << "\n PLayer 1 MALICE: " << Malice << "\n Player 2 MALICE: " << Malice2 << "\n Player 1 Wins!"<<endl;
else if (Malice < Malice2)
cout << "\n PLayer 1 MALICE: " << Malice << "\n Player 2 MALICE: " << Malice2 << "\nPlayer 2 Wins !" << endl;
else
cout << "Players have Tied" << endl;
else if(choice == "B" or choice == "b")
if (Might > Might2)
cout << "\n PLayer 1 MIGHT: " << Might << "\n Player 2 MIGHT " << Might2 << "\n Player 1 Wins!"<<endl;
else if (Might < Might2)
cout << "\n PLayer 1 MIGHT: " << Might << "\n Player 2 MIGHT: " << Might2 << "\n Player 2 Wins!"<<endl;
else
cout << "Players have Tied" << endl;
else if(choice == "C" or choice == "c")
if (Inteligence > Inteligence2)
cout << "\n PLayer 1 INTELIGENCE: " << Inteligence << "\n Player 2 INTELIGENCE " << Inteligence2 << "\n Player 1 Wins!"<<endl;
else if (Inteligence < Inteligence2)
cout << "\n PLayer 1 INTELIGENCE: " << Inteligence << "\n Player 2 INTELIGENCE: " << Inteligence2<< "\n Player 2 Wins!"<<endl;
else
cout << "Players have Tied" << endl;
else if(choice == "D" or choice == "d")
if (Agility > Agility2)
cout << "\n PLayer 1 AGILITY: " << Agility << "\n Player 2 AGILITY " << Agility2 << "\n Player 1 Wins!"<<endl;
else if (Agility < Agility2)
cout << "\n PLayer 1 AGILITY: " << Agility << "\n Player 2 AGILITY: " << Agility2 << "\n Player 2 Wins!"<<endl;
else
cout << "Players have Tied" << endl;
else if(choice == "E" or choice == "e")
if (Defense > Defense2)
cout << "\n PLayer 1 DEFENSE: " << Defense << "\n Player 2 DEFENSE " << Defense2 << "\n Player 1 Wins!"<<endl;
else if (Defense < Defense2)
cout << "\n PLayer 1 DEFENSE: " << Defense << "\n Player 2 DEFENSE: " << Defense2 << "\n Player 2 Wins!"<<endl;
else
cout << "Players have Tied" << endl;
}
void player_1()
{
deck1_set();
cout << name << endl;
cout << "A>> Malice: " << Malice << endl;
cout << "B>> Might: " << Might << endl;
cout << "C>> Inteligence: " << Inteligence << endl;
cout << "D>> Agility: " << Agility << endl;
cout << "E>> Defense: " << Defense << endl;
cout << " " << endl;
deck2_set();
comp_sys();
}
void player_2()
{
deck2_set();
cout << name << endl;
cout << "A>> Malice: " << Malice2 << endl;
cout << "B>> Might: " << Might2 << endl;
cout << "C>> Inteligence: " << Inteligence2 << endl;
cout << "D>> Agility: " << Agility2 << endl;
cout << "E>> Defense: " << Defense2 << endl;
cout << " " << endl;
deck1_set();
comp_sys();
}
int main ()
{
cout << "" << endl;
cout << "######################################" << endl;
cout << "\n PLAYER 1s DECK OF CARDS!" << endl;
deck_1();
output_deck1();
cout << "" ;
cout << "######################################" << endl;
cout << "\n PLAYER 2s DECK OF CARDS!" << endl;
deck_2();
output_deck2();
cout << "######################################" << endl;
for (int n=5; n>0; n--) {
string choice;
cout << "Who is Playing This round: " ;
cin >> choice;
if(choice == "1")
player_1();
else if (choice == "2")
player_2();
}
}