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 "libsqlite.hpp"
#include <time.h>
#include <stdlib.h>
using namespace std;
int puzzles()
{
int Intelligence = 7; //temporary int stat generated for testing purposes, would use the intelligence stat from the player
int IntCheck = 4;
int difficultyTemp;
int puzzleMax;
string sqliteFile = "GameDatabase.sqlite";
string rightAns;
string plAns;
string plQuestion;
try {
sqlite::sqlite db( sqliteFile );
if (IntCheck < 10)
{
difficultyTemp=1;
puzzleMax = 7;
}
else if (IntCheck < 20)
{
difficultyTemp=2;
puzzleMax = 5;
}
else
{
difficultyTemp=3;
puzzleMax = 10;
}
srand ( time(NULL) );
int randPuzzNr = rand() % (puzzleMax) + 1;
auto cur = db.get_statement();
cur->set_sql( "SELECT question FROM game_puzzles "
"WHERE difficulty = ? AND randomNr = ? AND completed = 0");
cur->prepare();
cur->bind(1, difficultyTemp);
cur->bind(2, randPuzzNr);
cur-> step() ;
plQuestion = cur->get_text(0);
cout <<plQuestion <<endl;
string plAnsTemp ;
cin >> plAnsTemp;
auto cur2 = db.get_statement();
cur2->set_sql( "select answer from game_puzzles "
"where difficulty = ? and randomNr = ?");
cur2->prepare();
cur2->bind( 1, difficultyTemp);
cur2->bind( 2, randPuzzNr);
cur2->step();
rightAns = cur2->get_text(0);
for (char c :plAnsTemp)
{
plAns += tolower(c);
}
if (rightAns == plAns)
{
//myPlayer.inc_skill(Intelligence, difficultyTemp) //line that if run in the main function will work
auto cur3 = db.get_statement();
cur3->set_sql("update game_puzzles set completed = '1' where difficulty = ? and randomNr = ?");
cur3->prepare();
cur3->bind(1, difficultyTemp);
cur3->bind(2, randPuzzNr);
cur3->step();
cout << "Right! Your intelligence stat has increased!" << endl;
}
else
{
cout << "Sorry, traveller! Your answer was wrong!" << endl;
}
}
catch( sqlite::exception e )
{
std::cerr << e.what() << std::endl;
return 1;
}
return 0;
}