Skip to content
Permalink
Browse files
Finish basic options/pause menu
  • Loading branch information
benjibobs committed Feb 22, 2019
1 parent 538b281 commit f244cec48eb134a7d4ffc6b84b1bf79dcd201aed
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 114 deletions.
242 menu.cpp
@@ -14,27 +14,27 @@ bool muted = false;
int kbhit() {
int ch = getch();

if (ch != ERR) {
ungetch(ch);
return 1;
} else {
return 0;
}
if (ch != ERR) {
ungetch(ch);
return 1;
} else {
return 0;
}
}

bool isMuted(){
return muted;
return muted;
}

void toggleMute() {
muted = !muted;
muted = !muted;
}

int showMainMenu() {
//get screen size
//get screen size
int yMax, xMax;
getmaxyx(stdscr, yMax, xMax);
bool ScreenTooSmall = xMax < 120;
bool ScreenTooSmall = xMax < 120;

mvprintw(yMax-1, 0,"Created by: Mazin, Luke, Ben, Paula, Kelvin, Tudor, Adrian, Konrad");

@@ -50,7 +50,7 @@ int showMainMenu() {
**********************************************
*/

drawLogo(xMax);
drawLogo(xMax);

/*
**********************************************
@@ -71,16 +71,16 @@ int showMainMenu() {

string choices[3] = {"Start", "Options", "Leave"};
int choice, highlight = 0,
mid = (((xMax-96)/2-1)-19)/2+1, mid2 = xMax-mid-19, //mid and mid2 = middle position
counter = 0, counter2 = yMax - 17, time = 0; //for moving cocktails
WINDOW * pic = newwin(16, 19, 0, mid); // cocktail 1 window
WINDOW * pic2 = newwin(16, 19, yMax-17, mid2); //cocktail 2 window
//Skip coctails if screen too small
mid = (((xMax-96)/2-1)-19)/2+1, mid2 = xMax-mid-19, //mid and mid2 = middle position
counter = 0, counter2 = yMax - 17, time = 0; //for moving cocktails

WINDOW * pic = newwin(16, 19, 0, mid); // cocktail 1 window
WINDOW * pic2 = newwin(16, 19, yMax-17, mid2); //cocktail 2 window

//Skip coctails if screen too small
if(!ScreenTooSmall){
drawCocktails(xMax, yMax, mid, mid2, pic, pic2);
}
}



@@ -152,17 +152,18 @@ int showMainMenu() {


//if key pressed, record it and save to choice
if(kbhit())
if(kbhit()){
choice = int(wgetch(choicesWin));
}

/*
*********************************************
Part based, again, on Casual Coder's tutorial
*/
//65 key_up, 66 key_down
switch(choice)
{
/*
*********************************************
Part based, again, on Casual Coder's tutorial
*/

//65 key_up, 66 key_down
switch(choice)
{
case 65:
highlight--;
if(highlight == -1)
@@ -175,35 +176,37 @@ int showMainMenu() {
break;
default:
break;
}
}
//when 'enter' pressed
if(choice==10)
{
//exit
if(highlight==2)
//exit
if(highlight==2)
{
endwin();
clear();
refresh();
endwin();
exit(0);
return 0;
}

//options
if(highlight == 1)
{
clear();
refresh();
showOptionsScreen(xMax, false);
showOptionsScreen(yMax, xMax, true);
}
if(highlight == 2){
endwin();
return 0;
}
endwin();
return 0;
}
}


}

//if 'Exit' chosen
if(highlight == 2)
{
@@ -216,88 +219,104 @@ int showMainMenu() {
//*********************************************
}

int showOptionsScreen(int xMax, bool isPauseMenu){
int showOptionsScreen(int yMax, int xMax, bool isPauseMenu){

//create window for choices
WINDOW * optionsWin = newwin(10, 10, 35, (xMax-10)/2);
//create window for choices
WINDOW * optionsWin = newwin(16, 16, (yMax-4)/2, (xMax-16)/2);
refresh();
wrefresh(optionsWin);
vector<string> choices;

int highlightIndex = 0, mute = isPauseMenu ? 2 : 0; //inline boolean
int highlightIndex = 0, mute = isPauseMenu ? 2 : 0; //inline boolean

if(isPauseMenu){
choices = {"Return to Game", "Save", "Music: ON", "Quit to Menu"};
}else{
choices = {"Music: ON", "Back"};
}
choices.push_back("Return to Game");
choices.push_back("Save");
choices.push_back("Music: ON");
choices.push_back("Quit to Menu");
//choices = {"Return to Game", "Save", "Music: ON", "Quit to Menu"};
}else{
choices.push_back("Music: ON");
choices.push_back("Back");
//choices = {"Music: ON", "Back"};
}

while(1)
{
if(isMuted()){
choices[mute] = "Music: OFF";
}else{
choices[mute] = "Music: ON";
}
wclear(optionsWin);
if(isMuted()){
choices[mute] = "Music: OFF";
}else{
choices[mute] = "Music: ON";
}

for(int i=0; i < choices.size(); i++)
{
if(i == highlightIndex)
{
wattron(optionsWin, A_REVERSE);
}
mvwprintw(optionsWin, i+1, (10 - choices[i].length())/2+1, choices[i].c_str());
wattroff(optionsWin, A_REVERSE);
}
for(int i=0; i < choices.size(); i++)
{
if(i == highlightIndex)
{
wattron(optionsWin, A_REVERSE);
}
mvwprintw(optionsWin, i+1, (16 - choices[i].length())/2+1, choices[i].c_str());
wattroff(optionsWin, A_REVERSE);
}

wrefresh(optionsWin);

int buttonHit = int(wgetch(optionsWin));

switch(buttonHit)
{
case UP_KEY:
highlightIndex--;
if(highlightIndex == -1)
highlightIndex = 0;
break;
case DOWN_KEY:
highlightIndex++;
if(highlightIndex == choices.size())
highlightIndex--;
break;
case ENTER_KEY:
if(highlightIndex == choices.size()-1)
{
endwin();
showMainMenu();
return 0;
}
else if(highlightIndex == mute)
{
toggleMute();
}
else if(choices.size() == 4 && highlightIndex == 0) // return to game
{
printw("%s", choices[highlightIndex].c_str());
move(0,0);
refresh();

}
else if(choices.size() == 4 && highlightIndex == 1) // save
{
printw("%s", choices[highlightIndex].c_str());
move(0,0);
refresh();

}
break;
default:
break;
}

}
wrefresh(optionsWin);

int buttonHit = int(wgetch(optionsWin));

switch(buttonHit)
{
case UP_KEY:

highlightIndex--;
if(highlightIndex == -1){
highlightIndex = 0;
}
break;

case DOWN_KEY:

highlightIndex++;
if(highlightIndex == choices.size()){
highlightIndex--;
}
break;

case ENTER_KEY:

if(highlightIndex == choices.size()-1)
{
clear();
refresh();
endwin();
showMainMenu();
return 0;
}
else if(highlightIndex == mute)
{
toggleMute();
}
else if(choices.size() == 4 && highlightIndex == 0) // return to game
{
printw("%s", choices[highlightIndex].c_str());
move(0,0);
refresh();

}
else if(choices.size() == 4 && highlightIndex == 1) // save
{
printw("%s", choices[highlightIndex].c_str());
move(0,0);
refresh();
}

break;

default:
break;
}

}
return 0;
}

@@ -546,6 +565,7 @@ int main()
//enables colors
start_color();

curs_set(0); //disable cursor

//check if colors are supported
if(!has_colors())
@@ -557,10 +577,6 @@ int main()

showMainMenu();

//make sure program waits before exiting
move(0,0);
nodelay(stdscr, false);
getch();
endwin();

return 0;
2 menu.h
@@ -10,7 +10,7 @@ void drawLogo(int xMax);

int kbhit();

int showOptionsScreen(int xMax, bool isPauseMenu);
int showOptionsScreen(int yMax, int xMax, bool isPauseMenu);
int showMainMenu();

bool isMuted();

0 comments on commit f244cec

Please sign in to comment.