Skip to content
Permalink
e7e8a75a86
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
205 lines (176 sloc) 6.01 KB
// game class 2.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <sqlite3.h>
#include <iostream>
#include <stdio.h>
using namespace std;
static int createDB(const char* s);
static int insert_data(const char* s);
static int callback(void* NotUsed, int argc, char** argv, char** azColName);
static int create_table(const char* s);
static int select_data(const char* s);
void create_player();
string names[10] = { "Bob Guy","James Soften","Steph Soup","Michelle Gordan","Shaquille O'sit",
"Natuto Uzumuki","Magic Joseph","LeBron Jenkins","Bartholomew Humphrey"," Dwayne spade"};
class Player
{
public:
string name;
int shooting;
int dribbling;
int defence;
void increase_shoot(int sh_amount)
{
shooting = shooting + sh_amount;
}
void increase_dribble(int dr_amount)
{
dribbling = dribbling + dr_amount;
}
void increse_defence(int de_amount)
{
defence = defence + de_amount;
}
Player()
{
name = names[rand() % 10];
shooting = 0;
dribbling = 0;
defence = 0;
}
};
class new_recruit : public Player
{
void train()
{}
};
static int createDB(const char* s)
{
sqlite3* DB;
int exit = 0;
exit = sqlite3_open(s, &DB);
sqlite3_close(DB);
return 0;
}
static int create_table(const char* s)
{
sqlite3* DB;
string sql = "CREATE TABLE IF NOT EXISTS Players(" \
"NAME TEXT ,"\
"SHOOTING INT ,"\
"DRIBBLING INT ,"\
"DEFENCE INT );";
try {
int exit = 0;
exit = sqlite3_open(s, &DB);
char* messaggeError;
exit = sqlite3_exec(DB, sql.c_str(), NULL, NULL, &messaggeError);
if (exit != SQLITE_OK) {
cerr << "table error" << endl;
cout << exit;
sqlite3_free(messaggeError);
}
else
cout << "success" << endl;
sqlite3_close(DB);
}
catch (const exception & e)
{
cerr << e.what();
}
return 0;
}
static int select_data(const char* s)
{
sqlite3* DB{};
sqlite3_open(s, &DB);
string sql = "SELECT * FROM Players;";
int exit = sqlite3_exec(DB, sql.c_str(), callback, NULL, NULL);
cout << exit;
return 0;
}
static int callback(void* NotUsed, int argc,char** argv, char** azColName)
{
for (int i = 0; i < argc; i++) {
cout << azColName[i] << ": " << argv[i] << endl;
}
cout << endl;
return 0;
}
static int insert_data(const char* s,string inname, int inshooting, int indribbling, int indefence)
{
sqlite3* DB;
char* messaggeError;
int exit = sqlite3_open(s, &DB);
string sql = "INSERT INTO Players('NAME', 'SHOOTING', 'DRIBBLING', 'DEFENCE') VALUES(+inname+,+inshooting+ ,+indribbling+ ,+indefence+ );";
exit = sqlite3_exec(DB, sql.c_str(), NULL, 0, &messaggeError);
cout << exit << endl;
if (exit != SQLITE_OK) {
cerr << "Error Insert" << endl;
//cout << exit;
sqlite3_free(messaggeError);
}
else
cout << "records created " << endl;
return 0;
}
void create_player()
{
const char* dir = "c:\\DATABASE\\Players.db";
sqlite3* DB{};
int currency = 500;
for (int i = 0; i < 2; ++i)
{
Player aninstance;
int increase = 0;
string ans = "";
cout << "budget:"; cout << currency << endl;
cout << aninstance.name << endl;
//cout << "which stat would you like to increase: \n shooting(SH)\n dribbling(DR) \n defence(DE)";
//cin >> ans;
cout << "how much SHOOTING would you like this player to have? ";
cin >> increase;
cout << "" << endl;
aninstance.increase_shoot(increase);
currency = currency - increase;
cout << "how much DRIBBLING would you like this player to have? ";
cin >> increase;
cout << "" << endl;
aninstance.increase_dribble(increase);
currency = currency - increase;
cout << "how much DEFENCE would you like this player to have? ";
cin >> increase;
cout << "" << endl;
aninstance.increse_defence(increase);
currency = currency - increase;
cout << "name:"; cout << aninstance.name << endl;
cout << "shooting:"; cout << aninstance.shooting << endl;
cout << "dribbling:"; cout << aninstance.dribbling << endl;
cout << "defence:"; cout << aninstance.defence << endl;
cout << "" << endl;
sqlite3_open(dir,&DB);
insert_data(dir, aninstance.name, aninstance.shooting, aninstance.dribbling, aninstance.defence);
//string sql("INSERT INTO Players (NAME, SHOOTING, DRIBBLING, DEFENCE) VALUES(?,? ,? ,? )", (aninstance.name, aninstance.shooting, aninstance.dribbling, aninstance.defence));
//sqlite3_exec(DB, sql.c_str(), NULL, 0, NULL);
}
}
int main()
{
const char* dir = "c:\\DATABASE\\Players.db";
sqlite3* DB;
createDB(dir);
create_table(dir);
//insert_data(dir);
create_player();
select_data(dir);
return 0;
}
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu
// Tips for Getting Started:
// 1. Use the Solution Explorer window to add/manage files
// 2. Use the Team Explorer window to connect to source control
// 3. Use the Output window to see build output and other messages
// 4. Use the Error List window to view errors
// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file