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>
using namespace std;
#include "libsqlite.hpp"
#include "pch.h"
#include <Windows.h>
#include <mmsystem.h>
void storymode() {
}
int main() {
// local variable declaration:
int ans;
retry:
system("cls");
cout << "Select an option" << endl;
cout << "1. Start new game " << endl;
cout << "2. Continue previous game " << endl;
cout << "3. Play" << endl;
cin >> ans;
if (ans == 1) {
//using online vidoes to learn about adding songs to a project
PlaySound(TEXT("song.wav"), NULL, SND_FILENAME | SND_LOOP | SND_ASYNC);
system("PAUSE");
try
{
sqlite::sqlite db("gamedb.sqlite");
auto cur = db.get_statement();
string name, password;
system("cls");
cout << "Enter name: ";
cin.ignore();
getline(cin, name);
cout << "Welcome " << name << ".\n";
cout << "Enter password: ";
getline(cin, password);
int level, health, cur_exp, min_attack, max_attack, defense, gold;
level = 1;
health = 100;
cur_exp = 0;
min_attack = 10;
max_attack = 50;
defense = 40;
gold = 100;
cur->set_sql("INSERT INTO players (name, level, cur_exp, health, min_attack, max_attack, defense, gold, password) "
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);");
cur->prepare();
cur->bind(1, name);
cur->bind(2, level);
cur->bind(3, cur_exp);
cur->bind(4, health);
cur->bind(5, min_attack);
cur->bind(6, max_attack);
cur->bind(7, defense);
cur->bind(8, gold);
cur->bind(9, password);
cur->step();
}
catch (sqlite::exception e)
{
cerr << e.what() << endl;
return 1;
}
}
if (ans == 2) {
string sqliteFile = "gamedb.sqlite";
try
{
sqlite::sqlite db(sqliteFile);
auto cur = db.get_statement();
cout << "Welcome Back. Please enter your username: ";
string username;
cin.ignore();
getline(cin, username);
cur->set_sql("select name, level "
"from players "
"where name = ?");
cur->prepare();
cur->bind(1, username);
cout << "Welcome Warrior " << username << " you are level ";
while (cur->step())
cout << cur->get_text(1) << ". ";
cout << endl;
cout << "Welcome to the best game yull ever play. The first steps to becoming the warioor you so defire starts now." << endl;
cout << "This is way more than a game its the start of what i know to believe will be a great worior story" << endl;
cout << "That said lets get to work";
system("cls");
int ans;
cout << "Game Menu" << endl;
cout << "1. Story mode" << endl;
cout << "2. Random Training" << endl;
cout << "3. Check Status" << endl;
cout << "4. Shop" << endl;
cin >> ans;
if (ans == 1) {
}
else if (ans == 2) {
}
else if (ans == 3) {
}
else if (ans == 4) {
sqlite::sqlite db("gamedb.sqlite"); // open database
auto cur = db.get_statement(); // create query
cur->set_sql("SELECT * FROM players;");
cur->prepare(); // run query
while (cur->step()) // loop over results
cout << cur->get_int(0) << " " << cur->get_text(1) << endl;
}
else {
cout << "You did not enter a valid character";
}
}
catch (sqlite::exception e) // catch all sql issues
{
std::cerr << e.what() << std::endl;
return 1;
}
}
else {
cout << "Invalid answer" << endl;
goto retry;
}
return 0;
}