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
#include <ncurses.h>
#include <string>
#include "window.h"
#include "newWindow.h"
#include "print_menu.h"
#include "Print_Output.h"
#include <iostream>
#include <fstream>
#include <cstdlib>
//#include "Combat.h"
#include "Monster.h"
#include "Player.h"
void Print_Output(std::string inputAction, Window outputWindow, int outputY);
void Refresh_Window(Window window);
int Combat(Player& P1, Monster& Mon);
void DrawMenu();
void CallCombatFunction(Player player, Monster mon, WINDOW* menu_win);
/////////////////BASED ON CODE FROM: http://www.tldp.org/HOWTO/NCURSES-Programming-HOWTO/keys.html//////////////
int Create_Game_Screen(Player& P1, Monster& Mon1, Monster& Mon2, Monster& Mon3)
{
WINDOW *menu_win;
int highlight = 1;
int choice = 0;
string path = "";
int c;
#define WIDTH 30
#define HEIGHT 10
int startx = 0;
int starty = 0;
int inputState = 0;
//INPUT STATE: 0 = CHOOSING A DOOR; 1 = YES OR NO RESPONSE; 2 = ENTERING A SINGLE DOOR; 3 = IN ANY OTHER CIRCUMSTANCE
char *choices[] = {
" LEFT DOOR ",
" RIGHT DOOR ",
" Exit",
};
char *choicesYesNo[] = {
" YES ",
" NO ",
" Exit",
};
char *choicesEnterDoor[] = {
" ENTER DOOR ",
" DON'T ENTER ",
" Exit",
};
char *choicesEmpty[] = {
" Continue ",
" Exit ",
" ",
};
int n_choices = sizeof(choices) / sizeof(char *);
/* NCURSES START */
initscr();
noecho();
cbreak();
// SCREENSIZE
int yMax, xMax;
int output_y = 0;
getmaxyx(stdscr,yMax,xMax);
START:
//TEXT OUTPUT
Window textOutputWindow(20, 60, yMax - 20, xMax - 60);
newWindow(textOutputWindow);
//MAP OUTPUT
//Window mapOutputWindow(20, 40, yMax - 20, xMax);
//newWindow(mapOutputWindow);
startx = xMax - 120;
starty = yMax - 15;
menu_win = newwin(HEIGHT, WIDTH, starty, startx);
keypad(menu_win, TRUE);
mvprintw(0, 0, "Welcome to Zorcc");
WindowPrint("Before you are two doors...", textOutputWindow, false, output_y);
output_y +=1;
WindowPrint("...enter one of them.", textOutputWindow, false, output_y);
output_y +=1;
LOOP:
refresh();
while(1)
{
switch(inputState)
{
case 0:
n_choices = sizeof(choices) / sizeof(char *);
print_menu(menu_win, highlight, n_choices, choices);
break;
case 1:
n_choices = sizeof(choices) / sizeof(char *);
print_menu(menu_win, highlight, n_choices, choicesYesNo);
break;
case 2:
n_choices = sizeof(choices) / sizeof(char *);
print_menu(menu_win, highlight, n_choices, choicesEnterDoor);
break;
case 3:
print_menu(menu_win, highlight, n_choices, choicesEmpty);
n_choices = 2;
break;
}
c = wgetch(menu_win);
switch(c)
{
case KEY_UP:
if(highlight == 1)
highlight = n_choices;
else
--highlight;
break;
case KEY_DOWN:
if(highlight == n_choices)
highlight = 1;
else
++highlight;
break;
case 10:
choice = highlight;
output_y +=1;
break;
default:
refresh();
break;
}
//print_menu(menu_win, highlight, n_choices, choices);
if(choice != 0) /* User did a choice come out of the infinite loop */
{
if (output_y > 17)
{
Refresh_Window(textOutputWindow);
output_y = 0;
}
if (choice == 1 || choice == 2)
{
if (choice == 2 && inputState == 3)
{
endwin();
exit(0);
}
else
{
break;
}
}
if (choice == 3 && inputState != 3)
{
endwin();
exit(0);
}
//Print_Output(choices[choice - 1], textOutputWindow, output_y);;
refresh();
}
}
if (choice == 1 || choice == 2)
{
path = path + to_string(choice);
}
//PATH STUFF**************************************************************
if (path == "1")
{
inputState = 0;
WindowPrint("You enter room 1.", textOutputWindow, false, output_y);
output_y +=1;
WindowPrint("A monster appears...", textOutputWindow, false, output_y);
inputState = 3;
CallCombatFunction(P1, Mon1, menu_win);
output_y = 0;
inputState = 0;
WindowPrint("You survived!", textOutputWindow, false, output_y);
output_y +=1;
WindowPrint("Before you are two more doors...", textOutputWindow, false, output_y);
output_y +=1;
}
if (path == "11")
{
inputState = 0;
WindowPrint("You go through the left door...", textOutputWindow, false, output_y);
output_y +=1;
WindowPrint("...on the other side lies a sword.", textOutputWindow, false, output_y);
output_y +=1;
WindowPrint("Would you like to trade your current unarmed attacks for a sword?", textOutputWindow, false, output_y);
output_y +=1;
inputState = 1;
}
if (path == "111")
{
inputState = 0;
if(P1.PlayerClassName == "Fighter")
{
P1.PlayerSTRDEX += 5;
WindowPrint("Your damage increases by +5!", textOutputWindow, false, output_y);
output_y +=1;
}
else
{
P1.PlayerSTRDEX += 1;
WindowPrint("Your damage increases by +1!", textOutputWindow, false, output_y);
output_y +=1;
}
inputState = 3;
WindowPrint("This portion of the game is over. Thank you for playing :)", textOutputWindow, false, output_y);
output_y +=1;
}
if (path == "112")
{
inputState = 0;
WindowPrint("You leave the sword alone and continue on your way...", textOutputWindow, false, output_y);
output_y +=1;
inputState = 3;
WindowPrint("This portion of the game is over. Thank you for playing :)", textOutputWindow, false, output_y);
output_y +=1;
}
if (path == "12")
{
inputState = 0;
WindowPrint("You go through the rigot door...", textOutputWindow, false, output_y);
output_y +=1;
WindowPrint("...on the other side lies a knife.", textOutputWindow, false, output_y);
output_y +=1;
WindowPrint("Would you like to trade your current unarmed attacks for a Knife?", textOutputWindow, false, output_y);
output_y +=1;
inputState = 1;
}
if (path == "121")
{
inputState = 0;
if(P1.PlayerClassName == "Rogue")
{
P1.PlayerSTRDEX += 5;
WindowPrint("Your damage increases by +5!", textOutputWindow, false, output_y);
output_y +=1;
}
else
{
P1.PlayerSTRDEX += 1;
WindowPrint("Your damage increases by +1!", textOutputWindow, false, output_y);
output_y +=1;
}
inputState = 3;
WindowPrint("This portion of the game is over. Thank you for playing :)", textOutputWindow, false, output_y);
output_y +=1;
}
if (path == "122")
{
inputState = 0;
WindowPrint("You leave the knife alone and continue on your way...", textOutputWindow, false, output_y);
output_y +=1;
inputState = 3;
WindowPrint("This portion of the game is over. Thank you for playing :)", textOutputWindow, false, output_y);
output_y +=1;
}
if (path == "2")
{
inputState = 0;
WindowPrint("You enter room 2.", textOutputWindow, false, output_y);
output_y +=1;
WindowPrint("You find a hammer on the floor...", textOutputWindow, false, output_y);
output_y +=1;
WindowPrint("Would you like to trade your current unarmed attacks for a Hammer?", textOutputWindow, false, output_y);
output_y +=1;
inputState = 1;
}
if (path == "21" || path == "22")
{
if (path == "21")
{
inputState = 0;
switch(P1.PlayerClass)
{
case 0:
P1.PlayerSTRDEX += 1;
WindowPrint("Your damage increases by +1!", textOutputWindow, false, output_y);
break;
case 1:
P1.PlayerSTRDEX += 5;
WindowPrint("Your damage increases by +5!", textOutputWindow, false, output_y);
break;
case 2:
WindowPrint("Yikes! The Hammer is to heavy for you to pick up!", textOutputWindow, false, output_y);
break;
}
output_y +=1;
}
if (path == "22")
{
inputState = 0;
WindowPrint("You leave the hammer alone and continue on your way...", textOutputWindow, false, output_y);
output_y +=1;
}
WindowPrint("There is a large door ahead of you...", textOutputWindow, false, output_y);
output_y +=1;
inputState = 2;
}
if (path == "211" || path == "221")
{
WindowPrint("You open the large door...", textOutputWindow, false, output_y);
output_y +=1;
WindowPrint("...", textOutputWindow, false, output_y);
output_y +=1;
inputState = 3;
WindowPrint("A monster appears...", textOutputWindow, false, output_y);
CallCombatFunction(P1, Mon2, menu_win);
inputState = 3;
output_y = 0;
WindowPrint("This portion of the game is over. Thank you for playing :)", textOutputWindow, false, output_y);
output_y +=1;
}
if (path == "212" || path == "222")
{
inputState = 3;
WindowPrint("You died :(", textOutputWindow, false, output_y);
output_y +=1;
}
//WindowPrint(path + " ", textOutputWindow, false, output_y);
//PATH STUFF ENDS*********************************************************
choice = 0;
goto LOOP;
clear();
refresh();
endwin();
}
void DrawMenu()
{
WINDOW *menu_win;
#define WIDTH 30
#define HEIGHT 10
int startx = 0;
int starty = 0;
// SCREENSIZE
int yMax, xMax;
int output_y = 0;
getmaxyx(stdscr,yMax,xMax);
START:
//TEXT OUTPUT
Window textOutputWindow(20, 60, yMax - 20, xMax - 60);
newWindow(textOutputWindow);
//MAP OUTPUT
//Window mapOutputWindow(20, 40, yMax - 20, xMax);
//newWindow(mapOutputWindow);
startx = xMax - 120;
starty = yMax - 15;
menu_win = newwin(HEIGHT, WIDTH, starty, startx);
keypad(menu_win, TRUE);
}
void CallCombatFunction(Player player, Monster mon, WINDOW* menu_win)
{
//getch();
clear();
Combat(player, mon);
refresh();
wrefresh(menu_win);
DrawMenu();
}