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?
dcrawlerproject/mo_ncurses.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
198 lines (168 sloc)
5.29 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
//This code is for the user interface for our text based game. | |
//Using ncurses to create this user interface | |
//http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/windows.html | |
#include <ncurses.h> | |
#include <menu.h> | |
#include "mo_ncurses.h" | |
#include <string> | |
#include "othermenuwindow.cpp" | |
#include <stdlib.h> | |
#include <vector> | |
using namespace std; | |
void gamemenu::mainmenu() | |
//Creates the menu for the game. Contains further windows for each option in the window. | |
{ | |
initscr(); // Starts ncurses | |
noecho(); | |
cbreak(); | |
start_color(); | |
curs_set(0); | |
nodelay(stdscr,0); | |
init_pair(1,COLOR_BLACK, COLOR_WHITE); | |
init_pair(2,COLOR_WHITE, COLOR_BLACK); | |
int height,width,start_y,start_x; | |
height = 20; | |
width = 180; | |
start_y = 0; | |
start_x = 0; | |
WINDOW * win = newwin(height, width, start_y, start_x); | |
wborder(win, 0, 0, '-', '-', 0, 0, 0, 0); | |
refresh(); | |
wrefresh(win); | |
wattron(win, A_UNDERLINE); | |
mvwprintw(win,10,70,"This is your menu screen! Press ENTER to continue."); | |
wattroff(win, A_UNDERLINE); | |
wrefresh(win); | |
wbkgd(win, COLOR_PAIR(1)); | |
refresh(); // Refreshes the screen based on memory | |
keypad(win, true); | |
int c; | |
c = wgetch(win); | |
if (c == 13) | |
{ | |
wclear(win); | |
refresh(); | |
} | |
WINDOW * menuwindow = newwin(height, width, start_y, start_x); | |
wborder(menuwindow, 0, 0, '-', '-', 0, 0, 0, 0); | |
mvwvline(menuwindow, 0, 40,'|', 20); | |
wbkgd(menuwindow, COLOR_PAIR(1)); | |
refresh(); | |
wrefresh(menuwindow); | |
//Menu Code | |
keypad(menuwindow, true); // Allows input from the arrow keys. | |
vector<string> options = {"Start/Continue Game", "Status", "Synopsis", "Exit Game"}; | |
int choice; | |
int hover = 0; | |
bool flag = false; | |
while(!flag) | |
{ | |
wattron(menuwindow, A_UNDERLINE); | |
mvwprintw(menuwindow,1,68, "Use the ESC key to leave the menu"); | |
wattroff(menuwindow, A_UNDERLINE); | |
mvwprintw(menuwindow,6,70, "You can start/continue the game here!"); | |
mvwprintw(menuwindow,12,70, "You can exit the game here"); | |
mvwprintw(menuwindow,8,70, "You can check your status in here"); | |
mvwprintw(menuwindow,10,70, "Short summary of the game"); | |
for(int counter = 0; counter<4; counter++) | |
{ | |
if (counter == hover) | |
wattron(menuwindow, A_REVERSE); | |
mvwprintw(menuwindow, ((counter*2) + 6), 10, options[counter].c_str()); | |
wattroff(menuwindow, A_REVERSE); | |
} | |
choice = wgetch(menuwindow); | |
height = 20; | |
width = 180; | |
start_y = 0; | |
start_x = 0; | |
switch(choice) | |
{ | |
case KEY_DOWN: | |
hover ++; | |
if (hover == 4) | |
hover = 0; | |
break; | |
case KEY_UP: | |
hover --; | |
if (hover == -1) | |
hover = 3; | |
break; | |
case '\n': | |
if (hover==0) | |
{ | |
flag = true; | |
endwin(); | |
} | |
if (hover==1) | |
{ | |
flag = true; | |
erase(); | |
wrefresh(menuwindow); | |
status(); | |
if (getch() == 27) | |
{ | |
clear(); | |
refresh(); | |
menuwindow2(); | |
flag = false; | |
} | |
break; | |
} | |
if (hover==2) | |
{ | |
flag = true; | |
erase(); | |
wrefresh(menuwindow); | |
synopsis(); | |
int x; | |
x = getch(); | |
if (x == 27) | |
{ | |
clear(); | |
refresh(); | |
menuwindow2(); | |
flag = false; | |
} | |
break; | |
} | |
if (hover==3) | |
{ | |
flag = true; | |
erase(); | |
wrefresh(menuwindow); | |
exit(); | |
if (getch() == 27) | |
{ | |
clear(); | |
refresh(); | |
menuwindow2(); | |
flag = false; | |
} | |
break; | |
} | |
default: | |
mvwprintw(menuwindow,18,76, "Use the Arrow keys!"); | |
break; | |
} | |
if (choice == 27) | |
{ | |
endwin(); | |
break; | |
} | |
} | |
cout << "\n"; | |
cout << "Press Enter to carry on with the game!" << "\n" << endl; | |
bool wut = true; | |
while(wut) | |
{ | |
keypad(stdscr, TRUE); | |
int x; | |
x = getch(); | |
if (x == 27); | |
{ | |
endwin(); | |
wut = false; | |
} | |
} | |
} | |