Permalink
Cannot retrieve contributors at this time
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?
C3-Game/npc.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
83 lines (70 sloc)
2.05 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <iostream> | |
#include <sqlite3.h> | |
#include "libsqlite.hpp" | |
#include <ctime> | |
#include <thread> | |
#include <chrono> | |
using namespace std; | |
void speech1() | |
{ | |
string sqlitefile = "npc.sqlite"; | |
string streets1; | |
string name; | |
string speech; //states variables | |
int speechID; | |
string npcID; | |
try | |
{ | |
sqlite::sqlite db(sqlitefile); //accesses required database | |
for( speechID = 1; speechID < 4; speechID++) | |
{ | |
auto cur = db.get_statement(); | |
cur->set_sql( "SELECT npcSpeech FROM Speech " //accesses required table | |
"WHERE speechID = ?"); //placeholder | |
cur->prepare(); | |
cur->bind(1, speechID); //collects the required data | |
cur-> step() ; | |
speech = cur->get_text(0); | |
cout << speech <<endl; //outputs data from database | |
std::this_thread::sleep_for (std::chrono::seconds(1)); //tells the program to wait for 1 second | |
} | |
} | |
catch( sqlite::exception e ) | |
{ | |
std::cerr << e.what() << std::endl; | |
} | |
} | |
int speech2() | |
{ | |
string sqlitefile = "npc.sqlite"; | |
string streets1; | |
string name; | |
string speech; | |
int speechID; | |
string npcID; | |
try | |
{ | |
sqlite::sqlite db(sqlitefile); | |
for( speechID = 4; speechID < 9; speechID++) | |
{ | |
auto cur = db.get_statement(); | |
cur->set_sql( "SELECT npcSpeech FROM Speech " | |
"WHERE speechID = ?"); | |
cur->prepare(); | |
cur->bind(1, speechID); | |
cur-> step() ; | |
speech = cur->get_text(0); | |
cout << speech <<endl; | |
std::this_thread::sleep_for (std::chrono::seconds(1)); | |
} | |
} | |
catch( sqlite::exception e ) | |
{ | |
std::cerr << e.what() << std::endl; | |
} | |
} | |
int npc() | |
{ | |
speech1(); | |
} |