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?
Cave-Crawler/Ncurses.txt
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
219 lines (176 sloc)
5.68 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
#include <ncurses.h> | |
#include <string> | |
using namespace std; | |
int main() | |
{ | |
initscr(); | |
cbreak(); | |
noecho(); | |
int yMax,xMax; | |
getmaxyx(stdscr, yMax , xMax); | |
// MAKING A TEXT WINDOW TO DISPLAY INFORMATION //(20,xMax-12, 5, 5 ); | |
WINDOW * text_win = newwin(20,xMax-12,5,5); | |
box(text_win, 0, 0); | |
mvwprintw(text_win, 1, 1, "IN THIS GAME YOU WILL BE ASKED TO ANSWER A"); | |
mvwprintw(text_win, 2, 1, "SIMPLE RIDDLE, ONLY THOSE WHO SUCCEED"); | |
mvwprintw(text_win, 3, 1, "SHALL PROCEED"); | |
mvwprintw(text_win, 18, 1, "press enter to continue"); | |
wrefresh(text_win); | |
while(true) | |
{ | |
int v = wgetch(text_win); | |
if(v == 10) | |
break; | |
} | |
// THIS IS THE RIDDLE TEXT INSIDE OF THE | |
wclear(text_win); | |
wrefresh(text_win); | |
refresh(); | |
box(text_win, 0, 0); | |
mvwprintw(text_win, 1, 1, "After you go through a fall I will"); | |
mvwprintw(text_win, 2, 1, "take over. All life will stall, or at "); | |
mvwprintw(text_win, 3, 1, "least grow slower. What am I?"); | |
mvwprintw(text_win, 16, 1, "select the answer with the up and down arrow keys"); | |
mvwprintw(text_win, 18, 1, "press enter to choose your answer"); | |
wrefresh(text_win); | |
// THIS IS THE INPUT WINDOW | |
char c = '~'; | |
char x = '!'; | |
WINDOW * inputwin = newwin(8, xMax-12, yMax - 8, 5); | |
box(inputwin, (int)x , (int)c); | |
refresh(); | |
keypad(inputwin,true); | |
wrefresh(inputwin); | |
string answer[5] = {"Marathon","Winter","Time","Death","Pain"}; | |
// THIS IS THE USER MENU FOR THE INPUT WINDOW | |
int choice; | |
int select = 0; | |
while(true) | |
{ | |
for(int i = 0; i < 5; i ++) | |
{ | |
if(i == select) | |
wattron(inputwin, A_REVERSE); | |
mvwprintw(inputwin, i+1, 2, answer[i].c_str()); | |
wattroff(inputwin, A_REVERSE); | |
} | |
choice = wgetch(inputwin); | |
if(choice == KEY_UP) | |
{ | |
select--; | |
if(select == -1) | |
select = 0; | |
} | |
if(choice == KEY_DOWN) | |
{ | |
select++; | |
if(select == 5) | |
select = 4; | |
} | |
if(choice == 10) | |
break; | |
} | |
wclear(text_win); | |
wrefresh(text_win); | |
refresh(); | |
// THIS IS THE RESULTS TEXT BOX | |
box(text_win, 0, 0); | |
mvwprintw(text_win, 1, 1, "You chose: "); | |
mvwprintw(text_win, 2, 1, answer[select].c_str()); | |
mvwprintw(text_win, 18, 1, "press enter to see result"); | |
wrefresh(text_win); | |
while(true) | |
{ | |
int v = wgetch(text_win); | |
if(v == 10) | |
break; | |
} | |
wclear(text_win); | |
wrefresh(text_win); | |
refresh(); | |
box(text_win, 0, (int)c); | |
if(select != 1) | |
{ | |
mvwprintw(text_win, 1, 1, "YOU LOST"); | |
wrefresh(text_win); | |
getch(); | |
endwin(); | |
} | |
// IF THE ANSWER WAS CORRECT THE USER CAN CONTINUE TO MORE QUESTIONS | |
else | |
{ | |
mvwprintw(text_win, 1, 1, "YOU WON, YOU CAN CONTINUE TO THE NEXT QUESTION"); | |
wrefresh(text_win); | |
getch(); | |
wclear(text_win); | |
wrefresh(text_win); | |
refresh(); | |
box(text_win, 0, 0); | |
mvwprintw(text_win, 1, 1, "You can run but cannot walk. You have "); | |
mvwprintw(text_win, 2, 1, "a mouth but cannot talk. You "); | |
mvwprintw(text_win, 3, 1, "have a head but never weep "); | |
mvwprintw(text_win, 4, 1, "and have a bed but never sleep. What are you?"); | |
mvwprintw(text_win, 18, 1, "press enter to choose your answer"); | |
wrefresh(text_win); | |
wrefresh(inputwin); | |
string second_answer[5] = {"A Doorway","A Mountain","A River","A Road","An Ocean"}; | |
while(true) | |
{ | |
for(int i = 0; i < 5; i ++) | |
{ | |
if(i == select) | |
wattron(inputwin, A_REVERSE); | |
mvwprintw(inputwin, i+1, 2, second_answer[i].c_str()); | |
wattroff(inputwin, A_REVERSE); | |
} | |
choice = wgetch(inputwin); | |
if(choice == KEY_UP) | |
{ | |
select--; | |
if(select == -1) | |
select = 0; | |
} | |
if(choice == KEY_DOWN) | |
{ | |
select++; | |
if(select == 5) | |
select = 4; | |
} | |
if(choice == 10) | |
break; | |
} | |
wclear(text_win); | |
wrefresh(text_win); | |
refresh(); | |
box(text_win, 0, 0); | |
mvwprintw(text_win, 1, 1, "You chose: "); | |
mvwprintw(text_win, 2, 1, second_answer[select].c_str()); | |
mvwprintw(text_win, 18, 1, "press enter to see result"); | |
wrefresh(text_win); | |
while(true) | |
{ | |
int v = wgetch(text_win); | |
if(v == 10) | |
break; | |
} | |
wclear(text_win); | |
wrefresh(text_win); | |
refresh(); | |
box(text_win, 0, (int)c); | |
if(select != 2) | |
{ | |
mvwprintw(text_win, 1, 1, "YOU LOST"); | |
wrefresh(text_win); | |
getch(); | |
endwin(); | |
} | |
else | |
{ | |
mvwprintw(text_win, 1, 1, "YOU WON, CONGRATULATIONS"); | |
wrefresh(text_win); | |
getch(); | |
endwin(); | |
} | |
} | |
return 0; | |
} |