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?
Old-School-Game/objects.h
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
120 lines (90 sloc)
2.81 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
#ifndef COCKTAIL_H | |
#define COCKTAIL_H | |
#include <string> | |
#include <vector> | |
#include "db.h" | |
#include <map> | |
/* Enums no longer used due to database implementation. Kept in to display complex technique understanding. */ | |
enum class Glass | |
{ | |
tall, | |
shot, | |
normal | |
}; | |
enum class Decoration | |
{ | |
none, | |
lime | |
}; | |
enum Ingredient { | |
vodka, | |
lemonade | |
}; | |
/* Enums no longer used due to database implementation. Kept in to display complex technique understanding. */ | |
class Beverage | |
{ | |
public: | |
std::string getName() const { //does not edit class so const | |
return name; | |
} | |
std::string getGlassType() const { | |
return glassType; | |
} | |
std::string getDecoration() const { | |
return decoration; | |
} | |
std::vector<string> getRecipe() const { | |
return recipe; | |
} | |
void setName(std::string newName) { //does edit class so not const | |
name = newName; | |
} | |
Beverage(std::string drink_name, std::vector<string> rec, std::string deco, std::string glass) | |
{ | |
name = drink_name; | |
recipe = rec; | |
glassType = glass; | |
decoration = deco; | |
} | |
private: | |
std::string name; | |
std::string glassType; | |
std::vector<string> recipe; | |
std::string decoration; | |
}; | |
std::map<std::string, double> ingredients; | |
std::vector<string> decorations; | |
std::vector<string> glasses; | |
Beverage rowToCocktail(Row row, Database db){ | |
std::vector<std::string> columns = row.getColumns(); | |
std::string glass = db.query("SELECT GlassType FROM Glass WHERE ID_Glass='"+columns[2]+"';")[0].getColumns()[0]; | |
std::vector<std::string> ingredientList; | |
std::vector<Row> ingredientIds = db.query("SELECT ID_Ing FROM Recipe WHERE ID_Bev='"+columns[0]+"';"); | |
for(int ing = 0; ing < ingredientIds.size(); ing++){ | |
std::vector<std::string> columns = ingredientIds[ing].getColumns(); | |
ingredientList.push_back(db.query("SELECT IngName FROM Ingredient WHERE ID_Ing='"+columns[0]+"';")[0].getColumns()[0]); | |
} | |
return Beverage(columns[1], ingredientList, "Lime", glass); | |
} | |
void initialiseObjectsFromDatabase(Database db) | |
{ | |
std::vector<Row> ingredientRows = db.query("SELECT IngName, IngPrice FROM Ingredient;"); | |
for(int row = 0; row < ingredientRows.size(); row++) | |
{ | |
std::vector<string> columns = ingredientRows[row].getColumns(); | |
ingredients[columns[0]] = std::stod(columns[1]); | |
} | |
std::vector<Row> decorationRows = db.query("SELECT DecName FROM Decoration;"); | |
for(int dec = 0; dec < decorationRows.size(); dec++) | |
{ | |
std::vector<string> columns = decorationRows[dec].getColumns(); | |
decorations.push_back(columns[0]); | |
} | |
std::vector<Row> glassRows = db.query("SELECT GlassType FROM Glass;"); | |
for(int glass = 0; glass < glassRows.size(); glass++) | |
{ | |
std::vector<string> columns = glassRows[glass].getColumns(); | |
glasses.push_back(columns[0]); | |
} | |
} | |
#endif |