From ed934e7d13db854826788ac362a13ee1021914cb Mon Sep 17 00:00:00 2001 From: Benjamin Grant Date: Mon, 25 Feb 2019 10:13:46 +0000 Subject: [PATCH] Change objects.h, implement DB into interface --- interface.cpp | 1028 ++++++++++++++++++++++++------------------------- objects.h | 89 ++--- sqlite.cpp | 0 tests.cpp | 6 +- 4 files changed, 552 insertions(+), 571 deletions(-) create mode 100644 sqlite.cpp diff --git a/interface.cpp b/interface.cpp index 9988435..236af24 100644 --- a/interface.cpp +++ b/interface.cpp @@ -1,515 +1,515 @@ -#include -#include -#include -#include "timer.h" - -using namespace std; - -void timerDone(){ - -} - -void tick(WINDOW* timerWindow, Timer timer){ - - int minutes = timer.getMinutes(), seconds = timer.getSeconds(); - - if(minutes <= 0 && seconds <= 0){ - timerDone(); - return; - } - - string timerText = "0" + to_string(minutes) + ":"; - - if(timer.getSeconds() < 10){ - timerText += "0" + to_string(seconds); - }else{ - timerText += to_string(seconds); - } - - mvwprintw(timerWindow, 1, 3, timerText.c_str()); - - wrefresh(timerWindow); -} - -int main() -{ - //ncurses start - initscr(); - //do not show user input - noecho(); - //enables ctrl+c - cbreak(); - //enables colors - start_color(); - - curs_set(0); //disable cursor - - //check if colors are supported - if(!has_colors()) - { - printw("Terminal does not support colors"); - getch(); - return -1; - } - - //get screen size - bool ScreenTooSmall = false; - int yMax, xMax; - getmaxyx(stdscr, yMax, xMax); - - //initialize colour pairs - init_color(COLOR_YELLOW, 700, 920, 880); //dark purple - init_color(COLOR_MAGENTA, 520, 280, 680); //lighter purple - init_color(COLOR_BLUE, 785, 560, 840); //the lightest purple - - init_color(COLOR_RED, 1000, 800, 400); //light orange - //init_color(COLOR_RED, 1000, 720, 320); //light orange - - - - - init_pair(1, COLOR_BLACK, COLOR_YELLOW); //dark purple - init_pair(2, COLOR_BLACK, COLOR_MAGENTA); // lighter purple - init_pair(3, COLOR_BLACK, COLOR_BLUE); //lightest purple - init_pair(4, COLOR_BLACK, COLOR_RED); //light orange - init_pair(5, COLOR_BLACK, COLOR_BLACK); - - - - /* - ************************************** - TIMER WINDOW - ************************************** - */ - - WINDOW * timerWindow = newwin(3, 11, 2, xMax-14); - box(timerWindow, 0, 0); - refresh(); - wrefresh(timerWindow); - - wbkgd(timerWindow, COLOR_PAIR(4)); - - mvwprintw(timerWindow, 1, 3, "05:00"); - - wrefresh(timerWindow); - - - Timer timer = Timer(5*60); - - - WINDOW * text = newwin(8, 70, 0, (xMax-70)/2); - //box(text, 0,0); - refresh(); - wrefresh(text); - - string thiss = "( \ - :::::::: ::: ::: ::: ::: ::: :::::::::: \ - :+: :+: :+: :+: :+: :+: :+: :+: :+: \ - +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ \ - +#++:++#++ +#++:++#++ +#++:++#++: +#++:++ +#++:++# \ - +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ \ - #+# #+# #+# #+# #+# #+# #+# #+# #+# \ - ######## ### ### ### ### ### ### ##########)" ; - - - mvwprintw(text, 0, 0 , thiss.c_str()); - wrefresh(text); - refresh(); - - - - - - - /* - ************************************** - RECIPE BOOK WINDOW - ************************************** - */ - - WINDOW * recipeBook = newwin(3, 30, 11, xMax-33); - box(recipeBook,0,0); - refresh(); - wrefresh(recipeBook); - - wbkgd(recipeBook, COLOR_PAIR(1)); - - mvwprintw(recipeBook, 1, 1, "<-- RECIPE BOOK -->"); - - WINDOW * recipeBook2 = newwin(20, 30, 15, xMax-33); - box(recipeBook2,0,0); - refresh(); - wrefresh(recipeBook2); - - wbkgd(recipeBook2, COLOR_PAIR(3)); - - mvwprintw(recipeBook2, 1, 10, "Bloody Mary"); - mvwprintw(recipeBook2, 3, 1, "Tall glass"); - mvwprintw(recipeBook2, 4, 1, "Tomato Juice"); - mvwprintw(recipeBook2, 5, 1, "Vodka"); - - - wrefresh(recipeBook); - wrefresh(recipeBook2); - - /* - ************************************** - INGREDIENTS WINDOW - ************************************** - */ - - WINDOW * ingredients = newwin( 3, 21, 11, 3); - box(ingredients, 0, 0); - refresh(); - wrefresh(ingredients); - - wbkgd(ingredients, COLOR_PAIR(1)); - - mvwprintw(ingredients, 1, 5, "INGREDIENTS"); - - wrefresh(ingredients); - - WINDOW * ingr2 = newwin( 20, 21, 15, 3); - box(ingr2, 0, 0); - refresh(); - wrefresh(ingr2); - - wbkgd(ingr2, COLOR_PAIR(3)); - - mvwprintw(ingr2, 1, 1, "Vodka"); - mvwprintw(ingr2, 2, 1, "Tomato Juice"); - mvwprintw(ingr2, 3, 1, "Ice"); - mvwprintw(ingr2, 4, 1, "Whiskey"); - - - wrefresh(ingr2); - - /* - ************************************** - GLASS WINDOW - ************************************** - */ - - WINDOW * glass = newwin( 3, 21, 11, 26); - box(glass, 0, 0); - refresh(); - wrefresh(glass); - - wbkgd(glass, COLOR_PAIR(1)); - - mvwprintw(glass, 1, 8, "GLASS"); - - wrefresh(glass); - - WINDOW * glass2 = newwin( 20, 21, 15, 26); - box(glass2, 0, 0); - refresh(); - wrefresh(glass2); - - wbkgd(glass2, COLOR_PAIR(3)); - - mvwprintw(glass2, 1, 1, "Tall"); - mvwprintw(glass2, 2, 1, "Small"); - mvwprintw(glass2, 3, 1, "Wine"); - - - wrefresh(glass2); - - /* - ************************************** - DECORATION WINDOW - ************************************** - */ - - WINDOW * decoration = newwin( 3, 20, 11, 49); - box(decoration, 0, 0); - refresh(); - wrefresh(decoration); - - wbkgd(decoration, COLOR_PAIR(1)); - - - mvwprintw(decoration, 1, 5, "DECORATION"); - - wrefresh(decoration); - - WINDOW * dec2 = newwin( 20, 20, 15, 49); - box(dec2, 0, 0); - refresh(); - wrefresh(dec2); - - wbkgd(dec2, COLOR_PAIR(3)); - - - mvwprintw(dec2, 1, 1, "Peppermint"); - mvwprintw(dec2, 2, 1, "Lemon"); - mvwprintw(dec2, 3, 1, "Umbrella"); - - - wrefresh(dec2); - - /* - ************************************** - SETTINGS WINDOW - ************************************** - */ - - WINDOW * settings = newwin( 3, 18, 2, 3); - box(settings, 0, 0); - refresh(); - wrefresh(settings); - - wbkgd(settings, COLOR_PAIR(4)); - - mvwprintw(settings, 1, 5, "SETTINGS"); - - - wrefresh(settings); - - - - - - /* - ************************************** - CUSTOMER WINDOW - ************************************** - */ - - WINDOW * Customer = newwin(13, 30, 37,3); - - refresh(); - - wbkgd(Customer,COLOR_PAIR(2)); - box(Customer,0,0); - - mvwprintw(Customer, 1, 1, "Customer:"); - mvwprintw(Customer, 2, 1, "I want Bloody Mary, please!"); - mvwprintw(Customer, 7, 1, "You:"); - mvwprintw(Customer, 8, 1, "It will be 10 Pounds."); - - wrefresh(Customer); - - - /* - ************************************** - SHAKER WINDOW - ************************************** - */ - - WINDOW * Shaker = newwin(13, 34, 37,35); - - box(Shaker,0,0); - refresh(); - - wbkgd(Shaker,COLOR_PAIR(2)); - - mvwprintw(Shaker, 1, 9, "COCKTAIL SHAKER"); - - wrefresh(Shaker); - - - /* - ************************************** - SHAKE BUTTON WINDOW - ************************************** - */ - - WINDOW * title = newwin(7, 35, 37, xMax-38); - refresh(); - box(title,0,0); - wbkgd(title,COLOR_PAIR(4)); - - wattron(title,COLOR_PAIR(5)); - //S - mvwprintw(title, 1, 2, " "); - mvwprintw(title, 2, 2," "); - mvwprintw(title, 3, 2," "); - mvwprintw(title, 4, 3," "); - mvwprintw(title, 5, 2," "); - - //H - mvwprintw(title, 1,6 ," "); - mvwprintw(title, 2,6 ," "); - mvwprintw(title, 3,6 ," "); - mvwprintw(title, 4,6 ," "); - mvwprintw(title, 5,6 ," "); - - mvwprintw(title, 3,8 ," "); - - mvwprintw(title, 1,10 ," "); - mvwprintw(title, 2,10 ," "); - mvwprintw(title, 3,10 ," "); - mvwprintw(title, 4,10 ," "); - mvwprintw(title, 5,10 ," "); - - //A - - /*mvwprintw(title, 5,20 ," "); - mvwprintw(title, 6,19 ," "); - mvwprintw(title, 7,18 ," "); - mvwprintw(title, 4,21 ," "); - mvwprintw(title, 3,22 ," "); - - mvwprintw(title, 5,21 ," "); - - mvwprintw(title, 3,24 ," "); - mvwprintw(title, 4,25 ," "); - mvwprintw(title, 5,26 ," "); - mvwprintw(title, 6,27 ," "); - mvwprintw(title, 7,28 ," ");*/ - - mvwprintw(title, 1,14 ," "); - mvwprintw(title, 2,14 ," "); - mvwprintw(title, 3,14 ," "); - mvwprintw(title, 4,14 ," "); - mvwprintw(title, 5,14 ," "); - - mvwprintw(title, 1,14 ," "); - - - mvwprintw(title, 1,18 ," "); - mvwprintw(title, 2,18 ," "); - mvwprintw(title, 3,18 ," "); - mvwprintw(title, 4,18 ," "); - mvwprintw(title, 5,18 ," "); - - mvwprintw(title, 3,13 ," "); - - //k - - mvwprintw(title, 1,22 ," "); - mvwprintw(title, 2,22 ," "); - mvwprintw(title, 3,22 ," "); - mvwprintw(title, 4,22 ," "); - mvwprintw(title, 5,22 ," "); - - mvwprintw(title, 3,24 ," "); - mvwprintw(title, 2,25 ," "); - mvwprintw(title, 1,26 ," "); - - mvwprintw(title, 4,25 ," "); - mvwprintw(title, 5,26 ," "); - - //E - - mvwprintw(title, 1,29 ," "); - mvwprintw(title, 2,29 ," "); - mvwprintw(title, 3,29 ," "); - mvwprintw(title, 4,29 ," "); - mvwprintw(title, 5,29 ," "); - - wrefresh(title); - - /* - ************************************** - STRIPES - ************************************** - */ - //WINDOW * stripe1 = newwin( 1, xMax, yMax-5, 0); - //wbkgd(stripe1,COLOR_PAIR(1)); - - WINDOW * stripe2 = newwin( 1, xMax, yMax-3, 0); - wbkgd(stripe2,COLOR_PAIR(3)); - - WINDOW * stripe3 = newwin( 1, xMax, yMax-1, 0); - wbkgd(stripe3,COLOR_PAIR(4)); - - refresh(); - //wrefresh(stripe1); - wrefresh(stripe2); - wrefresh(stripe3); - - - - /* - ************************************** - MONEY WINDOW - ************************************** - */ - - int moneyVal = 0; - - WINDOW * money = newwin( 5, 35, 45, xMax-38); - box(money, 0, 0); - - wbkgd(money,COLOR_PAIR(2)); - - mvwprintw(money, 2, 14, "MONEY: %d", moneyVal); - - refresh(); - wrefresh(money); - - while(1){ - tick(timerWindow, timer); - } - - /* - ************************************** - READ FROM TEMRINAL - ************************************** - */ - /* - char * s; - wmove(ingr2, 1,1); - getline(s, 6); - - mvprintw(52, 1, s); - - - - ************************************** - MOUSE FUNCTIONALITY - ************************************** - - - //enable mouse detection - mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, NULL); - keypad(stdscr, TRUE); - - - - MEVENT event; - int i = 0; - while(1) - { - mvprintw(50, 1, "%d", i); - int c = wgetch(stdscr); - - if (c == '\n') - break; - - if (c == KEY_MOUSE) - { - MEVENT event; - if (getmouse(&event) == OK) - { - - move(55,1); - clrtoeol(); - printw("Row=%d", event.y); - move(56,1); - clrtoeol(); - printw("Column=%d", event.x); - refresh(); - - - - //if(event.x>0 && event.x<14 && event.y>5 && event.y<9){} - - } - } - - - i++; - } - */ - - - - //make sure program waits before exiting - getch(); - endwin(); - - return 0; +#include +#include +#include +#include +#include "timer.h" +#include "objects.h" + +using namespace std; + +void timerDone(){ + +} + +void tick(WINDOW* timerWindow, Timer timer){ + + int minutes = timer.getMinutes(), seconds = timer.getSeconds(); + + if(minutes <= 0 && seconds <= 0){ + timerDone(); + return; + } + + string timerText = "0" + to_string(minutes) + ":"; + + if(timer.getSeconds() < 10){ + timerText += "0" + to_string(seconds); + }else{ + timerText += to_string(seconds); + } + + mvwprintw(timerWindow, 1, 3, timerText.c_str()); + + wrefresh(timerWindow); +} + +int main() +{ + + Database db = Database("cocktail.db"); + + initialiseObjectsFromDatabase(db); + + //ncurses start + initscr(); + //do not show user input + noecho(); + //enables ctrl+c + cbreak(); + //enables colors + start_color(); + + curs_set(0); //disable cursor + + //check if colors are supported + if(!has_colors()) + { + printw("Terminal does not support colors"); + getch(); + return -1; + } + + //get screen size + bool ScreenTooSmall = false; + int yMax, xMax; + getmaxyx(stdscr, yMax, xMax); + + //initialize colour pairs + init_color(COLOR_YELLOW, 700, 920, 880); //dark purple + init_color(COLOR_MAGENTA, 520, 280, 680); //lighter purple + init_color(COLOR_BLUE, 785, 560, 840); //the lightest purple + + init_color(COLOR_RED, 1000, 800, 400); //light orange + //init_color(COLOR_RED, 1000, 720, 320); //light orange + + + + + init_pair(1, COLOR_BLACK, COLOR_YELLOW); //dark purple + init_pair(2, COLOR_BLACK, COLOR_MAGENTA); // lighter purple + init_pair(3, COLOR_BLACK, COLOR_BLUE); //lightest purple + init_pair(4, COLOR_BLACK, COLOR_RED); //light orange + init_pair(5, COLOR_BLACK, COLOR_BLACK); + + + + /* + ************************************** + TIMER WINDOW + ************************************** + */ + + WINDOW * timerWindow = newwin(3, 11, 2, xMax-14); + box(timerWindow, 0, 0); + refresh(); + wrefresh(timerWindow); + + wbkgd(timerWindow, COLOR_PAIR(4)); + + mvwprintw(timerWindow, 1, 3, "05:00"); + + wrefresh(timerWindow); + + + Timer timer = Timer(5*60); + + + WINDOW * text = newwin(8, 70, 0, (xMax-70)/2); + //box(text, 0,0); + refresh(); + wrefresh(text); + + string thiss = "( \ + :::::::: ::: ::: ::: ::: ::: :::::::::: \ + :+: :+: :+: :+: :+: :+: :+: :+: :+: \ + +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ \ + +#++:++#++ +#++:++#++ +#++:++#++: +#++:++ +#++:++# \ + +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ \ + #+# #+# #+# #+# #+# #+# #+# #+# #+# \ + ######## ### ### ### ### ### ### ##########)" ; + + + mvwprintw(text, 0, 0 , thiss.c_str()); + wrefresh(text); + refresh(); + + + + + + + /* + ************************************** + RECIPE BOOK WINDOW + ************************************** + */ + + WINDOW * recipeBook = newwin(3, 30, 11, xMax-33); + box(recipeBook,0,0); + refresh(); + wrefresh(recipeBook); + + wbkgd(recipeBook, COLOR_PAIR(1)); + + mvwprintw(recipeBook, 1, 1, "<-- RECIPE BOOK -->"); + + WINDOW * recipeBook2 = newwin(20, 30, 15, xMax-33); + box(recipeBook2,0,0); + refresh(); + wrefresh(recipeBook2); + + wbkgd(recipeBook2, COLOR_PAIR(3)); + + mvwprintw(recipeBook2, 1, 10, "Bloody Mary"); + mvwprintw(recipeBook2, 3, 1, "Tall glass"); + mvwprintw(recipeBook2, 4, 1, "Tomato Juice"); + mvwprintw(recipeBook2, 5, 1, "Vodka"); + + + wrefresh(recipeBook); + wrefresh(recipeBook2); + + /* + ************************************** + INGREDIENTS WINDOW + ************************************** + */ + + WINDOW * ingredientsWindow = newwin( 3, 21, 11, 3); + box(ingredientsWindow, 0, 0); + refresh(); + wrefresh(ingredientsWindow); + + wbkgd(ingredientsWindow, COLOR_PAIR(1)); + + mvwprintw(ingredientsWindow, 1, 5, "INGREDIENTS"); + + wrefresh(ingredientsWindow); + + WINDOW * ingr2 = newwin( 20, 21, 15, 3); + box(ingr2, 0, 0); + refresh(); + wrefresh(ingr2); + + wbkgd(ingr2, COLOR_PAIR(3)); + + /* Loop inspired by John H. https://stackoverflow.com/a/26282004 */ + int tmpY = 1; + for(map::iterator it = ingredients.begin(); it != ingredients.end(); it++){ + mvwprintw(ingr2, tmpY, 1, it->first.c_str()); + tmpY++; + } + + wrefresh(ingr2); + + /* + ************************************** + GLASS WINDOW + ************************************** + */ + + WINDOW * glass = newwin( 3, 21, 11, 26); + box(glass, 0, 0); + refresh(); + wrefresh(glass); + + wbkgd(glass, COLOR_PAIR(1)); + + mvwprintw(glass, 1, 8, "GLASS"); + + wrefresh(glass); + + WINDOW * glass2 = newwin( 20, 21, 15, 26); + box(glass2, 0, 0); + refresh(); + wrefresh(glass2); + + wbkgd(glass2, COLOR_PAIR(3)); + + for(int i = 0; i < glasses.size(); i++){ + mvwprintw(glass2, i+1, 1, glasses[i].c_str()); + } + + wrefresh(glass2); + + /* + ************************************** + DECORATION WINDOW + ************************************** + */ + + WINDOW * decoration = newwin( 3, 20, 11, 49); + box(decoration, 0, 0); + refresh(); + wrefresh(decoration); + + wbkgd(decoration, COLOR_PAIR(1)); + WINDOW * dec2 = newwin( 20, 20, 15, 49); + box(dec2, 0, 0); + refresh(); + wrefresh(dec2); + + wbkgd(dec2, COLOR_PAIR(3)); + + for(int i = 0; i < decorations.size(); i++){ + mvwprintw(dec2, i+1, 1, decorations[i].c_str()); + } + + + wrefresh(dec2); + + /* + ************************************** + SETTINGS WINDOW + ************************************** + */ + + WINDOW * settings = newwin( 3, 18, 2, 3); + box(settings, 0, 0); + refresh(); + wrefresh(settings); + + wbkgd(settings, COLOR_PAIR(4)); + + mvwprintw(settings, 1, 5, "SETTINGS"); + + + wrefresh(settings); + + + + + + /* + ************************************** + CUSTOMER WINDOW + ************************************** + */ + + WINDOW * Customer = newwin(13, 30, 37,3); + + refresh(); + + wbkgd(Customer,COLOR_PAIR(2)); + box(Customer,0,0); + + mvwprintw(Customer, 1, 1, "Customer:"); + mvwprintw(Customer, 2, 1, "I want Bloody Mary, please!"); + mvwprintw(Customer, 7, 1, "You:"); + mvwprintw(Customer, 8, 1, "It will be 10 Pounds."); + + wrefresh(Customer); + + + /* + ************************************** + SHAKER WINDOW + ************************************** + */ + + WINDOW * Shaker = newwin(13, 34, 37,35); + + box(Shaker,0,0); + refresh(); + + wbkgd(Shaker,COLOR_PAIR(2)); + + mvwprintw(Shaker, 1, 9, "COCKTAIL SHAKER"); + + wrefresh(Shaker); + + + /* + ************************************** + SHAKE BUTTON WINDOW + ************************************** + */ + + WINDOW * title = newwin(7, 35, 37, xMax-38); + refresh(); + box(title,0,0); + wbkgd(title,COLOR_PAIR(4)); + + wattron(title,COLOR_PAIR(5)); + //S + mvwprintw(title, 1, 2, " "); + mvwprintw(title, 2, 2," "); + mvwprintw(title, 3, 2," "); + mvwprintw(title, 4, 3," "); + mvwprintw(title, 5, 2," "); + + //H + mvwprintw(title, 1,6 ," "); + mvwprintw(title, 2,6 ," "); + mvwprintw(title, 3,6 ," "); + mvwprintw(title, 4,6 ," "); + mvwprintw(title, 5,6 ," "); + + mvwprintw(title, 3,8 ," "); + + mvwprintw(title, 1,10 ," "); + mvwprintw(title, 2,10 ," "); + mvwprintw(title, 3,10 ," "); + mvwprintw(title, 4,10 ," "); + mvwprintw(title, 5,10 ," "); + + //A + + /*mvwprintw(title, 5,20 ," "); + mvwprintw(title, 6,19 ," "); + mvwprintw(title, 7,18 ," "); + mvwprintw(title, 4,21 ," "); + mvwprintw(title, 3,22 ," "); + + mvwprintw(title, 5,21 ," "); + + mvwprintw(title, 3,24 ," "); + mvwprintw(title, 4,25 ," "); + mvwprintw(title, 5,26 ," "); + mvwprintw(title, 6,27 ," "); + mvwprintw(title, 7,28 ," ");*/ + + mvwprintw(title, 1,14 ," "); + mvwprintw(title, 2,14 ," "); + mvwprintw(title, 3,14 ," "); + mvwprintw(title, 4,14 ," "); + mvwprintw(title, 5,14 ," "); + + mvwprintw(title, 1,14 ," "); + + + mvwprintw(title, 1,18 ," "); + mvwprintw(title, 2,18 ," "); + mvwprintw(title, 3,18 ," "); + mvwprintw(title, 4,18 ," "); + mvwprintw(title, 5,18 ," "); + + mvwprintw(title, 3,13 ," "); + + //k + + mvwprintw(title, 1,22 ," "); + mvwprintw(title, 2,22 ," "); + mvwprintw(title, 3,22 ," "); + mvwprintw(title, 4,22 ," "); + mvwprintw(title, 5,22 ," "); + + mvwprintw(title, 3,24 ," "); + mvwprintw(title, 2,25 ," "); + mvwprintw(title, 1,26 ," "); + + mvwprintw(title, 4,25 ," "); + mvwprintw(title, 5,26 ," "); + + //E + + mvwprintw(title, 1,29 ," "); + mvwprintw(title, 2,29 ," "); + mvwprintw(title, 3,29 ," "); + mvwprintw(title, 4,29 ," "); + mvwprintw(title, 5,29 ," "); + + wrefresh(title); + + /* + ************************************** + STRIPES + ************************************** + */ + //WINDOW * stripe1 = newwin( 1, xMax, yMax-5, 0); + //wbkgd(stripe1,COLOR_PAIR(1)); + + WINDOW * stripe2 = newwin( 1, xMax, yMax-3, 0); + wbkgd(stripe2,COLOR_PAIR(3)); + + WINDOW * stripe3 = newwin( 1, xMax, yMax-1, 0); + wbkgd(stripe3,COLOR_PAIR(4)); + + refresh(); + //wrefresh(stripe1); + wrefresh(stripe2); + wrefresh(stripe3); + + + + /* + ************************************** + MONEY WINDOW + ************************************** + */ + + int moneyVal = 0; + + WINDOW * money = newwin( 5, 35, 45, xMax-38); + box(money, 0, 0); + + wbkgd(money,COLOR_PAIR(2)); + + mvwprintw(money, 2, 14, "MONEY: %d", moneyVal); + + refresh(); + wrefresh(money); + + while(1){ + tick(timerWindow, timer); + } + + /* + ************************************** + READ FROM TEMRINAL + ************************************** + */ + /* + char * s; + wmove(ingr2, 1,1); + getline(s, 6); + + mvprintw(52, 1, s); + + + + ************************************** + MOUSE FUNCTIONALITY + ************************************** + + + //enable mouse detection + mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, NULL); + keypad(stdscr, TRUE); + + + + MEVENT event; + int i = 0; + while(1) + { + mvprintw(50, 1, "%d", i); + int c = wgetch(stdscr); + + if (c == '\n') + break; + + if (c == KEY_MOUSE) + { + MEVENT event; + if (getmouse(&event) == OK) + { + + move(55,1); + clrtoeol(); + printw("Row=%d", event.y); + move(56,1); + clrtoeol(); + printw("Column=%d", event.x); + refresh(); + + + + //if(event.x>0 && event.x<14 && event.y>5 && event.y<9){} + + } + } + + + i++; + } + */ + + + + //make sure program waits before exiting + getch(); + endwin(); + + return 0; } \ No newline at end of file diff --git a/objects.h b/objects.h index f533166..310b51a 100644 --- a/objects.h +++ b/objects.h @@ -65,75 +65,56 @@ class Beverage std::string decoration; }; -class Helper -{ - public: - - std::map getIngredients() const { - return ingredients; - } - - std::vector getDecorations() const { - return decorations; - } - - std::vector getGlasses() const { - return glasses; - } +std::map ingredients; +std::vector decorations; +std::vector glasses; - Beverage rowToCocktail(Row row, Database db){ +Beverage rowToCocktail(Row row, Database db){ - std::vector columns = row.getColumns(); + std::vector columns = row.getColumns(); - std::string glass = db.query("SELECT GlassType FROM Glass WHERE ID_Glass='"+columns[2]+"';")[0].getColumns()[0]; + std::string glass = db.query("SELECT GlassType FROM Glass WHERE ID_Glass='"+columns[2]+"';")[0].getColumns()[0]; - std::vector ingredientList; - std::vector ingredientIds = db.query("SELECT ID_Ing FROM Recipe WHERE ID_Bev='"+columns[0]+"';"); + std::vector ingredientList; + std::vector ingredientIds = db.query("SELECT ID_Ing FROM Recipe WHERE ID_Bev='"+columns[0]+"';"); - for(int ing = 0; ing < ingredientIds.size(); ing++){ + for(int ing = 0; ing < ingredientIds.size(); ing++){ - std::vector columns = ingredientIds[ing].getColumns(); - ingredientList.push_back(db.query("SELECT IngName FROM Ingredient WHERE ID_Ing='"+columns[0]+"';")[0].getColumns()[0]); + std::vector 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 ingredientRows = db.query("SELECT IngName, IngPrice FROM Ingredient;"); + return Beverage(columns[1], ingredientList, "Lime", glass); +} - for(int row = 0; row < ingredientRows.size(); row++) - { - std::vector columns = ingredientRows[row].getColumns(); - ingredients[columns[0]] = std::stod(columns[1]); - } +void initialiseObjectsFromDatabase(Database db) +{ - std::vector decorationRows = db.query("SELECT DecName FROM Decoration;"); + std::vector ingredientRows = db.query("SELECT IngName, IngPrice FROM Ingredient;"); - for(int dec = 0; dec < decorationRows.size(); dec++) - { - std::vector columns = decorationRows[dec].getColumns(); - decorations.push_back(columns[0]); - } + for(int row = 0; row < ingredientRows.size(); row++) + { + std::vector columns = ingredientRows[row].getColumns(); + ingredients[columns[0]] = std::stod(columns[1]); + } - std::vector glassRows = db.query("SELECT DecName FROM Decoration;"); + std::vector decorationRows = db.query("SELECT DecName FROM Decoration;"); - for(int glass = 0; glass < glassRows.size(); glass++) - { - std::vector columns = glassRows[glass].getColumns(); - glasses.push_back(columns[0]); - } + for(int dec = 0; dec < decorationRows.size(); dec++) + { + std::vector columns = decorationRows[dec].getColumns(); + decorations.push_back(columns[0]); + } - } + std::vector glassRows = db.query("SELECT GlassType FROM Glass;"); - private: - std::map ingredients; - std::vector decorations; - std::vector glasses; + for(int glass = 0; glass < glassRows.size(); glass++) + { + std::vector columns = glassRows[glass].getColumns(); + glasses.push_back(columns[0]); + } -}; +} #endif \ No newline at end of file diff --git a/sqlite.cpp b/sqlite.cpp new file mode 100644 index 0000000..e69de29 diff --git a/tests.cpp b/tests.cpp index 7ece0dd..5bcd484 100644 --- a/tests.cpp +++ b/tests.cpp @@ -40,16 +40,16 @@ void testTimer(int seconds){ int main(){ Database db = Database("cocktail.db"); - Helper helper = Helper(); + //Helper helper = Helper(); - helper.initialiseObjectsFromDatabase(db); + initialiseObjectsFromDatabase(db); cout << "COCKTAIL TEST:" << endl; vector bevs = db.query("SELECT * FROM Beverage"); for(int cocktail = 0; cocktail < bevs.size(); cocktail++){ - printCocktailMetadata(helper.rowToCocktail(bevs[cocktail], db)); + printCocktailMetadata(rowToCocktail(bevs[cocktail], db)); } cout << endl << "TIMER TEST:" << endl;