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 "Player.h"
#include "Monster.h"
using namespace std;
void Print_Output(std::string inputAction, Window outputWindow, int outputY);
void Refresh_Window(Window window);
void WindowPrint(string text, Window outputWindow, bool isOutput, int Youtput);
int Combat(Player& P1, Monster& Mon)
{
WINDOW *menu_win;
int highlight = 1;
int choice = 0;
int c;
#define WIDTH 30
#define HEIGHT 7
int startx = 0;
int starty = 0;
srand(time(NULL));
int Num = 0;
int Atk = 0;
bool SpAv = true;
int combatChoice;
int Damage;
bool isItThePlayersTurn = true;
bool hasCombatFinished = false;
char *choices[] = {
" Attack (1)",
" Special Attack (2)",
" Exit Game",
};
char *finalChoices[] = {
" Continue ",
" Exit Game ",
" ",
};
int n_choices = sizeof(choices) / sizeof(char *);
/* NCURSES START */
initscr();
noecho();
cbreak();
// SCREENSIZE
int yMax, xMax;
int output_y = 0;
getmaxyx(stdscr,yMax,xMax);
//TEXT OUTPUT
Window textOutputWindow(20, 60, yMax - 16, xMax - 60);
newWindow(textOutputWindow);
startx = xMax - 120;
starty = yMax - 15;
menu_win = newwin(HEIGHT, WIDTH, starty, startx);
keypad(menu_win, TRUE);
mvprintw(0, 0, "Welcome to Zorcc");
string combatText = "You have enccountered " + Mon.MonsterName + " " + Mon.MonsterTitle + " " + Mon.MonsterType + "...";
mvprintw( textOutputWindow.Start_y - textOutputWindow.Height -1 , textOutputWindow.Start_x - textOutputWindow.Width , combatText.c_str());
string monName = Mon.MonsterName;
LOOP:
refresh();
if (hasCombatFinished)
{
print_menu(menu_win, highlight, 3, finalChoices);
while(1)
{ c = wgetch(menu_win);
switch(c)
{ case KEY_UP:
if(highlight == 1)
highlight = 2;
else
--highlight;
break;
case KEY_DOWN:
if(highlight == 2)
highlight = 1;
else
++highlight;
break;
case 10:
choice = highlight;
output_y +=1;
break;
default:
refresh();
break;
}
print_menu(menu_win, highlight, 2, finalChoices);
if(choice != 0) /* User did a choice come out of the infinite loop */
{
if (choice == 1)
{
break;
}
if (choice == 2)
{
endwin();
exit(0);
}
refresh();
}
}
if (choice == 1)
{
clear();
endwin();
}
}
else if (!hasCombatFinished)
{
print_menu(menu_win, highlight, n_choices, choices);
while(1)
{
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 */
{
switch(choice)
{
case 3:
endwin();
exit(0);
break;
case 1:
break;
case 2:
break;
default:
WindowPrint(choices[choice - 1], textOutputWindow, false, output_y);
break;
}
if (choice == 1)
{
break;
}
if (choice == 2)
{
break;
}
refresh();
}
if (!isItThePlayersTurn)
{
break;
}
}
}
if (output_y > 16)
{
Refresh_Window(textOutputWindow);
output_y = 0;
refresh();
}
if (choice == 1 && !hasCombatFinished)
{
WindowPrint("Normal Attack", textOutputWindow, false, output_y);
Num = ((rand() % 20) + 1);
Atk = (Num + P1.PlayerSTRDEX);
if(Atk >= Mon.MonsterAc)
{
Damage = (P1.PlayerSTRDEX);
Mon.MonsterHP = Mon.MonsterHP-Damage;
if (Mon.MonsterHP > 0)
{
WindowPrint(monName + "'s health is now at " + to_string(Mon.MonsterHP), textOutputWindow, false, output_y);
}
}
else
{
WindowPrint( "You missed. " + monName + "'s health is " + to_string(Mon.MonsterHP), textOutputWindow, false, output_y);
}
isItThePlayersTurn = false;
refresh();
}
else if (choice == 2 && !hasCombatFinished)
{
if(SpAv == true)
{
SpAv = false;
Num = ((rand() % 20) + 1);
Atk = (Num + P1.PlayerSTRDEX)*2;
if(Atk >= Mon.MonsterAc)
{
Damage = (5+P1.PlayerSTRDEX);
Mon.MonsterHP = Mon.MonsterHP-Damage;
if (Mon.MonsterHP > 0)
{
WindowPrint( "HIT! " + monName + "'s health is now at " + to_string(Mon.MonsterHP), textOutputWindow, false, output_y);
}
}
else
{
WindowPrint( "You missed. " + monName + "'s health is " + to_string(Mon.MonsterHP), textOutputWindow, false, output_y);
}
}
else
{
WindowPrint( "Special Attack Unavailable! Try Again!", textOutputWindow, false, output_y);
goto LOOP;
}
isItThePlayersTurn = false;
refresh();
}
if (!isItThePlayersTurn && !hasCombatFinished)
{
Num = ((rand() % 20) + 1);
Atk = (Num + Mon.MonsterAtk);
if(Atk >= P1.PlayerAc)
{
if (output_y > 15)
{
Refresh_Window(textOutputWindow);
output_y = 0;
refresh();
}
output_y +=1;
WindowPrint(monName + " attacked you and hit!", textOutputWindow, true, output_y);
refresh();
Damage = (Mon.MonsterAtk+(rand() % 5));
P1.PlayerHP = P1.PlayerHP-Damage;
output_y +=1;
WindowPrint("Your health is now at " + to_string(P1.PlayerHP), textOutputWindow, true, output_y);
refresh();
}
else
{
output_y +=1;
WindowPrint(monName + " missed. Your health is " + to_string(P1.PlayerHP), textOutputWindow, true,output_y);
refresh();
}
isItThePlayersTurn = true;
}
refresh();
wrefresh(menu_win);
choice = 0;
if (Mon.MonsterHP <= 0 || P1.PlayerHP <= 0)
{
if (!hasCombatFinished)
{
if (Mon.MonsterHP <= 0)
{
WindowPrint(monName + " Was Defeated! " + "Your health is currently at " + to_string(P1.PlayerHP) + " ", textOutputWindow, false, output_y);
hasCombatFinished = true;
refresh();
wrefresh(menu_win);
goto LOOP;
}
else if (P1.PlayerHP <= 0)
{
WindowPrint("You have died :( ", textOutputWindow, false, output_y);
hasCombatFinished = true;
refresh();
wrefresh(menu_win);
goto LOOP;
}
}
clear();
refresh();
wrefresh(menu_win);
endwin();
}
else
{
goto LOOP;
}
}