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
#ifndef _MAINMENU_H_
#define _MAINMENU_H_
#include "map.h"
/** Creates main menu on the bottom of terminal with options to choose from **/
std::string startMenu()
{
int ymax, xmax;
getmaxyx(stdscr, ymax, xmax);
char c='-';
WINDOW * mainMenu=newwin(10, xmax -12, ymax-10, 6);
refresh();
wborder(mainMenu, 0, 0, c, c, 0, 0, 0, 0);
wrefresh(mainMenu);
keypad(mainMenu, true); // KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT, KEY_F(n) n=1-12
std::array<std::string, 3> choices={"New Game", "Continue", "Quit"};
std::array<std::string, 2> yesNo={"Yes", "No"};
int choice, highlight=0, hl=1, ch;
while(true)
{
for(int i=0;i<3;i++)
{
if(i==highlight)
wattron(mainMenu, A_REVERSE);
mvwprintw(mainMenu, i+1, 1, choices[i].c_str());
wattroff(mainMenu, A_REVERSE);
}
choice=wgetch(mainMenu);
switch(choice)
{
case KEY_UP:
highlight--;
if(highlight==-1)
highlight=0;
break;
case KEY_DOWN:
highlight++;
if(highlight==3)
highlight=2;
break;
default:
break;
}
if (choice==10)
break;
}
if (choices[highlight]=="New Game")
{
mvwprintw(mainMenu, 1, 1, "Move with arrow keys");
mvwprintw(mainMenu, 2, 1, " ");
mvwprintw(mainMenu, 3, 1, "Press 'x' to quit");
wrefresh(mainMenu);
}
else if (choices[highlight]=="Quit")
{
mvwprintw(mainMenu, 1, 1, "You sure you want to quit?");
mvwprintw(mainMenu, 2, 1, " ");
mvwprintw(mainMenu, 3, 1, " ");
wrefresh(mainMenu);
while(true)
{
for(int i=1;i<3;i++)
{
if (i==hl)
wattron(mainMenu, A_REVERSE);
mvwprintw(mainMenu, i+1, 1, yesNo[i-1].c_str());
wattroff(mainMenu, A_REVERSE);
}
ch=wgetch(mainMenu);
switch(ch)
{
case KEY_UP:
hl--;
if(hl==0)
hl=1;
break;
case KEY_DOWN:
hl++;
if(hl==3)
hl=2;
break;
default:
break;
}
if (ch==10)
break;
}
}
return choices[highlight];
}
#endif