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?
The-Age-of-The-Great-Labyrinth/game.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1051 lines (822 sloc)
51 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 <iostream> | |
#include <ncurses.h> | |
#include <string> | |
#include <cstdlib> | |
#include <ctime> | |
#include <sqlite3.h> | |
#include <libgrandmaze/mapfile.hpp> | |
#include <cstring> | |
//everything here is written by andrei unless stated otherwise | |
using namespace std; | |
class Entity{ | |
public: | |
int last_x; //mainly to "mask" anything left behind the player -- basically cleanup | |
int last_y; | |
int x; | |
int y; | |
char symbol; | |
char horizontal_attack; | |
char vertical_attack; | |
int color; //0:black, 1:red, 2:green, 3:yellow, 4:blue, 5:magenta, 6:cyan, and 7:white | |
int hp; | |
int dmg; | |
int gold; | |
}; | |
/* | |
class Item{ | |
public: | |
string prefix; | |
string weapon; | |
string suffix; | |
int dmg; | |
int def; | |
int price; | |
}; | |
*/ | |
bool adjacency(int player_x, int player_y, int enemy_x, int enemy_y) //tests if the player is adjacent to an enemy | |
{ | |
//if(player_x == enemy_x - 1 && player_y == enemy_y - 1) return true; | |
if(player_x == enemy_x - 1 && player_y == enemy_y) return true; | |
//if(player_x == enemy_x - 1 && player_y == enemy_y + 1) return true; | |
if(player_x == enemy_x && player_y == enemy_y - 1) return true; | |
if(player_x == enemy_x && player_y == enemy_y + 1) return true; | |
//if(player_x == enemy_x + 1 && player_y == enemy_y - 1) return true; | |
if(player_x == enemy_x + 1 && player_y == enemy_y) return true; | |
//if(player_x == enemy_x + 1 && player_y == enemy_y + 1) return true; | |
return false; | |
} | |
///database stuff | |
typedef struct Item //written by declan & josh | |
{ | |
int modID; | |
std::string modName; | |
int matID; | |
std::string matName; | |
int itemID; | |
std::string itemName; | |
int total_attack; | |
int total_strength; | |
int total_defence; | |
int total_price; | |
int total_rarity; | |
} | |
Item; | |
static int callback(void* data, int cols, char** values, char** ColName) //written by declan & josh | |
{ | |
Item *item =(Item*)data; | |
item->modID = atoi(values[0]); | |
item->modName = values[1]; | |
item->matID = atoi(values[2]); | |
item->matName = values[3]; | |
item->itemID = atoi(values[4]); | |
item->itemName = values[5]; | |
item->total_attack = atoi(values[6]); | |
item->total_strength = atoi(values[7]); | |
item->total_defence = atoi(values[8]); | |
item->total_price = atoi(values[9]); | |
item->total_rarity = atoi(values[10]); | |
return 0; | |
} | |
Item* getRandomItem(sqlite3 *db) //written by declan & josh | |
{ | |
//Declare variables here. Character pointer as SQL | |
//char *sql; | |
//getting the stuff from the database | |
char *sql = "SELECT" | |
"`rand_mod`.`ID`, `rand_mod`.`name`," | |
"`rand_mat`.`ID`, `rand_mat`.`name`," | |
"`rand_item`.`ID`, `rand_item`.`name`," | |
"`rand_mod`.`attackAdd` + `rand_mat`.`attackAdd` + `rand_item`.`attackAdd` AS `total_attack`," | |
"`rand_mod`.`strengthAdd` + `rand_mat`.`strengthAdd` + `rand_item`.`strengthAdd` AS `total_strength`," | |
"`rand_mod`.`defenceAdd` + `rand_mat`.`defenceAdd` + `rand_item`.`defenceAdd` AS `total_defence`," | |
"`rand_mod`.`priceAdd` + `rand_mat`.`priceAdd` + `rand_item`.`priceAdd` AS `total_price`," | |
"`rand_mod`.`rarityAdd` + `rand_mat`.`rarityAdd` + `rand_item`.`rarityAdd` AS `total_rarity`" | |
"FROM" | |
"(SELECT * FROM itemModifier ORDER BY RANDOM() LIMIT 1) as `rand_mod`," | |
"(SELECT * FROM materials ORDER BY RANDOM() LIMIT 1) as `rand_mat`," | |
"(SELECT * FROM items ORDER BY RANDOM() LIMIT 1) AS `rand_item`;"; | |
Item *item = new Item; | |
//Line to execute SQL commands and callback routine. | |
int execute = sqlite3_exec(db, sql, callback, (void*)item, NULL); | |
//Check if executed correctly. Verification | |
if (execute != SQLITE_OK) | |
cerr << "DB Error!" << endl; | |
return item; | |
} | |
/* | |
void itemisation(string &prefix, string &weapon, string &suffix, int &dmg, int &def, int &price) //randomisation without database | |
{ | |
string pre[5] = {"Legendary", "Uncommon", "Common", "Rare", "Mythic"}; | |
string wep[15] = {"Sword", "Axe", "Bow", "Broadsword", "Giant Axe", "Crossbow", "Wand", "Sceptre", "Tome", "Greatsword"}; | |
string suf[30] = {"of Carthage", "of Divinity", "of Politeness", "of Fashion", "of Rome", "of Rudeness", "of Militrary Prowess", "of Skill", "of Illness", "of Viciousness", "of Corruption", "of Absortion", "of Hunger", "of Blindness", "of Restorarion", "of Insanity"}; | |
prefix = pre[rand() % 5]; | |
weapon = wep[rand() % 10]; | |
suffix = suf[rand() % 16]; | |
dmg = rand() % 89 + 10; | |
def = rand() % 89 + 10; | |
price = rand() % 899 + 100; | |
} | |
*/ | |
void init_player(Entity &player) //player entity setup | |
{ | |
player.x = 2; | |
player.y = 2; | |
player.last_x = 2; | |
player.last_y = 2; | |
player.symbol = '@'; | |
player.vertical_attack = '|'; | |
player.horizontal_attack = '-'; | |
player.color = 3; | |
player.hp = 250; | |
player.dmg = 100; | |
player.gold = 0; | |
} | |
void init_enemy(Entity &mob) //enemy entity setup | |
{ | |
int x[99] = {0, 20, 26, 11, 23, 33, 14, 33, 45, 59, 72, 90, 97, 97, 79, 97, 88, 51, 73}; //18 numbers | |
int y[99] = {0, 2, 1, 16, 16, 21, 21, 16, 15, 14, 20, 18, 15, 17, 6, 6, 4, 15, 19}; // the different (x,y) spawn locations | |
int pos = rand() % 18 + 1; //1 - 18 | |
mob.x = x[pos]; | |
mob.y = y[pos]; | |
mob.symbol = 'E'; | |
mob.vertical_attack = '#'; | |
mob.horizontal_attack = '#'; | |
mob.color = 5; | |
mob.hp = 200; | |
mob.dmg = 10; | |
mob.gold = rand() % 256; | |
} | |
void init_shop(Entity &shopkeeper) //shopkeeper entity setup | |
{ | |
shopkeeper.x = 63; | |
shopkeeper.y = 7; | |
shopkeeper.symbol = 'S'; | |
shopkeeper.vertical_attack = '+'; | |
shopkeeper.horizontal_attack = '+'; | |
shopkeeper.color = 2; | |
shopkeeper.hp = 999999; //hacks | |
shopkeeper.dmg = 999999; //hacks | |
shopkeeper.gold = 999999; //hacks | |
} | |
void start_up(); | |
void main_menu(); | |
void credits(); | |
//this variable skips (basically closes) the game if the player chooses "quit" at the main menu | |
bool that_one_global_variable_that_i_couldve_used_as_a_parameter_in_a_function_but_at_this_point_im_way_too_lazy_and_IT_STILL_WORKS_SO_DONT_TELL_ME_NOTHING = true; | |
int main() | |
{ | |
///NCURSES_SETUP/////////////////////////////////////////////////////////////////////////// | |
srand(time(NULL)); //salt | |
// init screen | |
initscr(); | |
raw(); | |
noecho(); | |
start_color(); // prepares the terminal for colours | |
// initialise all colors | |
for (int i = 1; i < 7; i++) | |
init_pair(i, i, COLOR_BLACK); | |
curs_set(0); // remove the cursor | |
keypad(stdscr, true); | |
///ENTITIES_INITIALIZATION/////////////////////////////////////////////////////////// | |
GrandMaze::FileMapReader reader; | |
GrandMaze::Map *currentMap = reader.load("./final_map.map"); //reading the mapfile | |
Entity player, shopkeeper, enemy[99]; | |
const int enemy_count = 9; //how many enemies should the game spawn | |
int input; | |
int shop_mode = 0; //shop & inventory arrow logic | |
int inv_mode = 0; | |
const int shop_y_pos1 = 10; //position on screen | |
const int shop_y_pos2 = 46; | |
const int inv_y_pos1 = 90; | |
const int inv_y_pos2 = 126; | |
string shop_name = "Gannicus' Weapon Store"; | |
Item *items[11]; | |
int enemy_remaining = 0; //enemies remaining *on screen* | |
int temp_enemy_remaining = 0; | |
init_player(player); | |
init_shop(shopkeeper); | |
for(int i = 1 ; i <= enemy_count ; i++) init_enemy(enemy[i]); | |
///DATABASE_INITIALIZATION/////////////////////////////////////////////////////////// | |
//written by declan & josh | |
sqlite3* DB; | |
int exit = 0; | |
exit = sqlite3_open("game.db", &DB); | |
if (exit) { | |
std::cerr << "Error open DB " << sqlite3_errmsg(DB) << std::endl; | |
return (-1); | |
} | |
//getRandomItem(DB) //Added this | |
///FLAGS///////////////////////////////////////////////////////////////////////////// | |
bool is_shopping = false; | |
bool first_time = true; //shop init | |
bool dead = false; | |
bool win = false; | |
bool startup = true; | |
/* 'E' and yellow 'E' arent the same :/ | |
currentMap->draw(stdscr); | |
mvaddch(player.last_y, player.last_x, ' '); | |
mvaddch(player.y, player.x, player.symbol | COLOR_PAIR(COLOR_YELLOW)); | |
mvaddch(shopkeeper.y, shopkeeper.x, shopkeeper.symbol | COLOR_PAIR(COLOR_BLUE)); | |
for(int i = 1 ; i <= enemy_count ; i++) mvaddch(enemy[i].y, enemy[i].x, enemy[i].symbol | COLOR_PAIR(COLOR_MAGENTA)); | |
mvaddch(99, 99, ' '); //dead enemies spot | |
refresh(); | |
*/ | |
///STARTUP_AND_MAIN_MENU_SEQUENCE//////////////////////////////////////////////////////////////////////////// | |
start_up(); | |
if(that_one_global_variable_that_i_couldve_used_as_a_parameter_in_a_function_but_at_this_point_im_way_too_lazy_and_IT_STILL_WORKS_SO_DONT_TELL_ME_NOTHING == true) | |
{ | |
///INITIAL_PRINT///////////////////////////////////////////////////////////////////////////////// | |
currentMap->draw(stdscr); | |
mvaddch(player.y, player.x, player.symbol); | |
mvaddch(shopkeeper.y, shopkeeper.x, shopkeeper.symbol); | |
for(int i = 1 ; i <= enemy_count ; i++) mvaddch(enemy[i].y, enemy[i].x, enemy[i].symbol); | |
///GET_VISIBLE_ENEMY_COUNT/////////////////////////////////////////////////////////////////////// | |
for(int i = 0 ; i <= 120 ; i++) | |
for(int j = 0 ; j <= 120 ; j++) | |
if(mvinch(i,j) == 'E') | |
enemy_remaining++; | |
//HUD | |
mvprintw(3, 120, "o--------------------o"); | |
mvprintw(4, 120, "| Player HP: %d |", player.hp); | |
mvprintw(5, 120, "| Gold: %d |", player.gold); | |
mvprintw(6, 120, "| Enemies left: %d |", enemy_remaining); | |
mvprintw(7, 120, "o--------------------o"); | |
///GAME LOOP///////////////////////////////////////////////////////////////////////////////////// | |
while (true) | |
{ | |
if(player.hp <= 0) {dead = true; break;} | |
if(enemy_remaining <= 0) {win = true; break;} | |
if(is_shopping == false) | |
{ | |
input = getch(); | |
///dmg player if they get too close | |
for(int i = 1 ; i <= enemy_count ; i++) | |
if( adjacency(player.x, player.y, enemy[i].x, enemy[i].y) == true) | |
{ | |
//debug enemy pos | |
//mvprintw(i, 150, "player: %d %d enemy: %d %d", player.x, player.y, enemy[i].x, enemy[i].y); | |
player.hp -= enemy[i].dmg; | |
} | |
currentMap->draw(stdscr); //Draw map here so everything else is drawn on the map | |
//HUD | |
mvprintw(3, 120, "o--------------------o"); | |
if(player.hp > 99 && player.hp < 1000) mvprintw(4, 120, "| Player HP: %d |", player.hp); | |
else if(player.hp > 9 && player.hp < 100) mvprintw(4, 120, "| Player HP: %d |", player.hp); | |
else mvprintw(4, 120, "| Player HP: %d |", player.hp); | |
if(player.gold < 10) mvprintw(5, 120, "| Gold: %d |", player.gold); | |
else if(player.gold > 9 && player.gold < 100) mvprintw(5, 120, "| Gold: %d |", player.gold); | |
else if(player.gold > 99 && player.gold < 1000) mvprintw(5, 120, "| Gold: %d |", player.gold); | |
else mvprintw(5, 120, "| Gold: %d |", player.gold); | |
mvprintw(6, 120, "| Enemies left: %d |", enemy_remaining); | |
mvprintw(7, 120, "o--------------------o"); | |
//Draw these too so the "look for character" logic works | |
mvaddch(shopkeeper.y, shopkeeper.x, shopkeeper.symbol); | |
for(int i = 1 ; i <= enemy_count ; i++) mvaddch(enemy[i].y, enemy[i].x, enemy[i].symbol); | |
//Player Movement | |
if (input == KEY_UP && mvinch(player.y - 1, player.x) != '#' && mvinch(player.y - 1, player.x) != 'E' && mvinch(player.y - 1, player.x) != 'S') {player.last_y = player.y; player.y--;} | |
if (input == KEY_DOWN && mvinch(player.y + 1, player.x) != '#' && mvinch(player.y + 1, player.x) != 'E' && mvinch(player.y + 1, player.x) != 'S') {player.last_y = player.y; player.y++;} | |
if (input == KEY_LEFT && mvinch(player.y, player.x - 1) != '#' && mvinch(player.y, player.x - 1) != 'E' && mvinch(player.y, player.x - 1) != 'S') {player.last_x = player.x; player.x--;} | |
if (input == KEY_RIGHT && mvinch(player.y, player.x + 1) != '#' && mvinch(player.y, player.x + 1) != 'E' && mvinch(player.y, player.x - 1) != 'S') {player.last_x = player.x; player.x++;} | |
if (input == 27) break; //debug feature | |
//attron(A_STANDOUT); | |
///PLAYER_ATTACK//////////////////////////////////////////////////////////////// | |
switch(char(input)) //sword_attack | |
{ | |
case 'w': | |
{ | |
if(mvinch(player.y - 1, player.x) != '#') mvaddch(player.y - 1, player.x, player.vertical_attack); //print the attack if there isnt a wall | |
if(mvinch(player.y - 1, player.x) == 'E' || mvinch(player.y - 2, player.x) == 'E') | |
{ | |
for(int i = 1 ; i <= enemy_count ; i++) | |
{ | |
if(enemy[i].x == player.x && (enemy[i].y == player.y - 1 || enemy[i].y == player.y - 2)) //if there's an enemy dmg him & kil him | |
{ | |
enemy[i].hp -= player.dmg; | |
if(enemy[i].hp == 0) //if he's dead move him to a "dead spot" | |
{ | |
enemy[i].x = 99; | |
enemy[i].y = 99; | |
player.gold += enemy[i].gold; | |
//enemy_remaining--; | |
} | |
else player.hp -= enemy[i].dmg; | |
} | |
} | |
} | |
} | |
break; | |
case 'a': | |
{ | |
if(mvinch(player.y, player.x - 1) != '#') mvaddch(player.y, player.x - 1, player.horizontal_attack); | |
if(mvinch(player.y, player.x - 1) == 'E' || mvinch(player.y, player.x - 2) == 'E') | |
{ | |
for(int i = 1 ; i <= enemy_count ; i++) | |
{ | |
if(enemy[i].y == player.y && (enemy[i].x == player.x - 1 || enemy[i].x == player.x - 2)) | |
{ | |
enemy[i].hp -= player.dmg; | |
if(enemy[i].hp == 0) | |
{ | |
enemy[i].x = 99; | |
enemy[i].y = 99; | |
player.gold += enemy[i].gold; | |
//enemy_remaining--; | |
} | |
else player.hp -= enemy[i].dmg; | |
} | |
} | |
} | |
} | |
break; | |
case 's': | |
{ | |
if(mvinch(player.y + 1, player.x) != '#') mvaddch(player.y + 1, player.x, player.vertical_attack); | |
if(mvinch(player.y + 1, player.x) == 'E' || mvinch(player.y + 2, player.x) == 'E') | |
{ | |
for(int i = 1 ; i <= enemy_count ; i++) | |
{ | |
if(enemy[i].x == player.x && (enemy[i].y == player.y + 1 || enemy[i].y == player.y + 2)) | |
{ | |
enemy[i].hp -= player.dmg; | |
if(enemy[i].hp == 0) | |
{ | |
enemy[i].x = 99; | |
enemy[i].y = 99; | |
player.gold += enemy[i].gold; | |
//enemy_remaining--; | |
} | |
else player.hp -= enemy[i].dmg; | |
} | |
} | |
} | |
} | |
break; | |
case 'd': | |
{ | |
if(mvinch(player.y, player.x + 1) != '#') mvaddch(player.y, player.x + 1, player.horizontal_attack); | |
if(mvinch(player.y, player.x + 1) == 'E' || mvinch(player.y, player.x + 2) == 'E') | |
{ | |
for(int i = 1 ; i <= enemy_count ; i++) | |
{ | |
if(enemy[i].y == player.y && (enemy[i].x == player.x + 1 || enemy[i].x == player.x + 2)) | |
{ | |
enemy[i].hp -= player.dmg; | |
if(enemy[i].hp == 0) | |
{ | |
enemy[i].x = 99; | |
enemy[i].y = 99; | |
player.gold += enemy[i].gold; | |
//enemy_remaining--; | |
} | |
else player.hp -= enemy[i].dmg; | |
} | |
} | |
} | |
} | |
break; | |
} | |
///PRINT_SCREEN///////////////////////////////////////////////////////////////// | |
if(mvinch(player.last_y, player.last_x) == '@') mvaddch(player.last_y, player.last_x, ' '); | |
mvaddch(player.y, player.x, player.symbol); | |
mvaddch(shopkeeper.y, shopkeeper.x, shopkeeper.symbol); | |
for(int i = 1 ; i <= enemy_count ; i++) mvaddch(enemy[i].y, enemy[i].x, enemy[i].symbol); | |
mvaddch(99, 99, ' '); //dead enemies spot | |
//get remaining enemy count | |
for(int i = 0 ; i <= 120 ; i++) | |
for(int j = 0 ; j <= 120 ; j++) | |
if(mvinch(i,j) == 'E') | |
temp_enemy_remaining++; | |
enemy_remaining = temp_enemy_remaining; //mvprintw(10,120,"%d",temp_enemy_remaining); | |
temp_enemy_remaining = 0; | |
//set the game state to shopping mode | |
if (mvinch(player.y - 1, player.x) == 'S' || mvinch(player.y + 1, player.x) == 'S' || mvinch(player.y, player.x - 1) == 'S' || mvinch(player.y, player.x + 1) == 'S') is_shopping = true; | |
} | |
else //if he's shopping, do this | |
{ | |
clear(); | |
while(is_shopping == true) | |
{ | |
if(char(input) == 'x') //quit shop | |
{ | |
is_shopping = false; | |
player.y -= 1; | |
break; | |
} | |
if(first_time == true) //item randomisation | |
{ | |
srand(time(NULL)); //salt | |
for(int i = 0 ; i <= 10 ; i++) items[i] = getRandomItem(DB); | |
sqlite3_close(DB); | |
first_time = false; | |
} | |
///SHOP////////////////////////////////////////////////////////////////// written by ana, modified by me to fit with the databse | |
mvprintw(10, shop_y_pos1, "o-------------------------------------------------------------------o"); | |
mvprintw(11, shop_y_pos1, "| |"); | |
mvprintw(12, shop_y_pos1, "| %s |", shop_name.c_str()); | |
mvprintw(13, shop_y_pos1, "| |"); | |
mvprintw(14, shop_y_pos1, "| Name Dmg Def Price |"); | |
mvprintw(15, shop_y_pos1, "| |"); | |
mvprintw(16, shop_y_pos1, "| > %s %s %s ", items[0]->modName.c_str(), items[0]->matName.c_str(), items[0]->itemName.c_str()); | |
mvprintw(16, shop_y_pos2, " %d %d %d |", items[0]->total_attack, items[0]->total_defence, items[0]->total_price); | |
mvprintw(17, shop_y_pos1, "| |"); | |
mvprintw(18, shop_y_pos1, "| %s %s %s ", items[1]->modName.c_str(), items[1]->matName.c_str(), items[1]->itemName.c_str()); | |
mvprintw(18, shop_y_pos2, " %d %d %d |", items[1]->total_attack, items[1]->total_defence, items[1]->total_price); | |
mvprintw(19, shop_y_pos1, "| |"); | |
mvprintw(20, shop_y_pos1, "| %s %s %s ", items[2]->modName.c_str(), items[2]->matName.c_str(), items[2]->itemName.c_str()); | |
mvprintw(20, shop_y_pos2, " %d %d %d |", items[2]->total_attack, items[2]->total_defence, items[2]->total_price); | |
mvprintw(21, shop_y_pos1, "| |"); | |
mvprintw(22, shop_y_pos1, "| %s %s %s ", items[3]->modName.c_str(), items[3]->matName.c_str(), items[3]->itemName.c_str()); | |
mvprintw(22, shop_y_pos2, " %d %d %d |", items[3]->total_attack, items[3]->total_defence, items[3]->total_price); | |
mvprintw(23, shop_y_pos1, "| |"); | |
mvprintw(24, shop_y_pos1, "| %s %s %s ", items[4]->modName.c_str(), items[4]->matName.c_str(), items[4]->itemName.c_str()); | |
mvprintw(24, shop_y_pos2, " %d %d %d |", items[4]->total_attack, items[4]->total_defence, items[4]->total_price); | |
mvprintw(25, shop_y_pos1, "| |"); | |
mvprintw(26, shop_y_pos1, "o-------------------------------------------------------------------o"); | |
///SHOP_ARROWS///////////////////////////////////////////////////////////////// written by ana | |
if(char(input) == 'y') | |
{ | |
shop_mode--; | |
if(shop_mode < 0) shop_mode = 4; | |
} | |
if(char(input) == 'h') | |
{ | |
shop_mode++; | |
if(shop_mode > 4) shop_mode = 0; | |
} | |
if(input == 10) //half-implemented shop thing | |
{ | |
if(shop_mode == 0) mvprintw(16, shop_y_pos1, "| |"); | |
if(shop_mode == 1) mvprintw(18, shop_y_pos1, "| |"); | |
if(shop_mode == 2) mvprintw(20, shop_y_pos1, "| |"); | |
if(shop_mode == 3) mvprintw(22, shop_y_pos1, "| |"); | |
if(shop_mode == 4) mvprintw(24, shop_y_pos1, "| |"); | |
} | |
if(shop_mode == 0) //16 | |
{ | |
for(int i = 16 ; i <= 24 ; i+=2) mvprintw(i,shop_y_pos1 + 2," "); | |
mvprintw(16,shop_y_pos1 + 2,">"); | |
} | |
if(shop_mode == 1) //18 | |
{ | |
for(int i = 16 ; i <= 24 ; i+=2) mvprintw(i,shop_y_pos1 + 2," "); | |
mvprintw(18,shop_y_pos1 + 2,">"); | |
} | |
if(shop_mode == 2) //20 | |
{ | |
for(int i = 16 ; i <= 24 ; i+=2) mvprintw(i,shop_y_pos1 + 2," "); | |
mvprintw(20,shop_y_pos1 + 2,">"); | |
} | |
if(shop_mode == 3) //22 | |
{ | |
for(int i = 16 ; i <= 24 ; i+=2) mvprintw(i,shop_y_pos1 + 2," "); | |
mvprintw(22,shop_y_pos1 + 2,">"); | |
} | |
if(shop_mode == 4) //24 | |
{ | |
for(int i = 16 ; i <= 24 ; i+=2) mvprintw(i,shop_y_pos1 + 2," "); | |
mvprintw(24,shop_y_pos1 + 2,">"); | |
} | |
///INVENTORY////////////////////////////////////////////////////////////////// written by ana, modified by me to fit with the databse | |
mvprintw(10, inv_y_pos1, "o-------------------------------------------------------------------o"); | |
mvprintw(11, inv_y_pos1, "| |"); | |
mvprintw(12, inv_y_pos1, "| Inventory |"); | |
mvprintw(13, inv_y_pos1, "| |"); | |
mvprintw(14, inv_y_pos1, "| Name Dmg Def Value |"); | |
mvprintw(15, inv_y_pos1, "| |"); | |
mvprintw(16, inv_y_pos1, "| > %s %s %s ", items[5]->modName.c_str(), items[5]->matName.c_str(), items[5]->itemName.c_str()); | |
mvprintw(16, inv_y_pos2, " %d %d %d |", items[5]->total_attack, items[5]->total_defence, items[5]->total_price / 10); | |
mvprintw(17, inv_y_pos1, "| |"); | |
mvprintw(18, inv_y_pos1, "| %s %s %s ", items[6]->modName.c_str(), items[6]->matName.c_str(), items[6]->itemName.c_str()); | |
mvprintw(18, inv_y_pos2, " %d %d %d |", items[6]->total_attack, items[6]->total_defence, items[6]->total_price / 10); | |
mvprintw(19, inv_y_pos1, "| |"); | |
mvprintw(20, inv_y_pos1, "| %s %s %s ", items[7]->modName.c_str(), items[7]->matName.c_str(), items[7]->itemName.c_str()); | |
mvprintw(20, inv_y_pos2, " %d %d %d |", items[7]->total_attack, items[7]->total_defence, items[7]->total_price / 10); | |
mvprintw(21, inv_y_pos1, "| |"); | |
mvprintw(22, inv_y_pos1, "| |"); | |
//mvprintw(22, inv_y_pos1, "| %s %s %s ", items[8]->modName.c_str(), items[8]->matName.c_str(), items[8]->itemName.c_str()); | |
//mvprintw(22, inv_y_pos2, " %d %d %d |", items[8]->total_attack, items[8]->total_defence, items[8]->total_price / 10); | |
mvprintw(23, inv_y_pos1, "| |"); | |
mvprintw(24, inv_y_pos1, "| |"); | |
//mvprintw(24, inv_y_pos1, "| %s %s %s ", items[9]->modName.c_str(), items[9]->matName.c_str(), items[9]->itemName.c_str()); | |
//mvprintw(24, inv_y_pos2, " %d %d %d |", items[9]->total_attack, items[9]->total_defence, items[9]->total_price / 10); | |
mvprintw(25, inv_y_pos1, "| |"); | |
mvprintw(26, inv_y_pos1, "o-------------------------------------------------------------------o"); | |
///INV_ARROWS/////////////////////////////////////////////////////////////// written by ana | |
if(char(input) == 'i') | |
{ | |
inv_mode--; | |
if(inv_mode < 0) inv_mode = 4; | |
} | |
if(char(input) == 'k') | |
{ | |
inv_mode++; | |
if(inv_mode > 4) inv_mode = 0; | |
} | |
if(inv_mode == 0) //16 | |
{ | |
for(int i = 16 ; i <= 24 ; i+=2) mvprintw(i,inv_y_pos1 + 2," "); | |
mvprintw(16,inv_y_pos1 + 2,">"); | |
} | |
if(inv_mode == 1) //18 | |
{ | |
for(int i = 16 ; i <= 24 ; i+=2) mvprintw(i,inv_y_pos1 + 2," "); | |
mvprintw(18,inv_y_pos1 + 2,">"); | |
} | |
if(inv_mode == 2) //20 | |
{ | |
for(int i = 16 ; i <= 24 ; i+=2) mvprintw(i,inv_y_pos1 + 2," "); | |
mvprintw(20,inv_y_pos1 + 2,">"); | |
} | |
if(inv_mode == 3) //22 | |
{ | |
for(int i = 16 ; i <= 24 ; i+=2) mvprintw(i,inv_y_pos1 + 2," "); | |
mvprintw(22,inv_y_pos1 + 2,">"); | |
} | |
if(inv_mode == 4) //24 | |
{ | |
for(int i = 16 ; i <= 24 ; i+=2) mvprintw(i,inv_y_pos1 + 2," "); | |
mvprintw(24,inv_y_pos1 + 2,">"); | |
} | |
input = getch(); | |
} | |
clear(); | |
///PRINT_SCREEN//////////////////////////////////////////////////////////////// | |
currentMap->draw(stdscr); | |
mvaddch(player.y, player.x, player.symbol); | |
mvaddch(shopkeeper.y, shopkeeper.x, shopkeeper.symbol); | |
for(int i = 1 ; i <= enemy_count ; i++) mvaddch(enemy[i].y, enemy[i].x, enemy[i].symbol); | |
//HUD | |
mvprintw(3, 120, "o--------------------o"); | |
if(player.hp > 99 && player.hp < 1000) mvprintw(4, 120, "| Player HP: %d |", player.hp); | |
else if(player.hp > 9 && player.hp < 100) mvprintw(4, 120, "| Player HP: %d |", player.hp); | |
else mvprintw(4, 120, "| Player HP: %d |", player.hp); | |
if(player.gold < 10) mvprintw(5, 120, "| Gold: %d |", player.gold); | |
else if(player.gold > 9 && player.gold < 100) mvprintw(5, 120, "| Gold: %d |", player.gold); | |
else if(player.gold > 99 && player.gold < 1000) mvprintw(5, 120, "| Gold: %d |", player.gold); | |
else mvprintw(5, 120, "| Gold: %d |", player.gold); | |
mvprintw(6, 120, "| Enemies left: %d |", enemy_remaining); | |
mvprintw(7, 120, "o--------------------o"); | |
} | |
//napms(500); | |
} | |
if(dead == true) | |
{ | |
clear(); | |
int y_offset = 5, x_offset = 5; | |
///LOSE_SCREEN//////////////////////////////////////////////////////////////////// | |
mvprintw(y_offset++, x_offset, "o-------------------------------o"); | |
mvprintw(y_offset++, x_offset, "o o"); | |
mvprintw(y_offset++, x_offset, "o o"); | |
mvprintw(y_offset++, x_offset, "o GAME OVER o"); | |
mvprintw(y_offset++, x_offset, "o o"); | |
mvprintw(y_offset++, x_offset, "o TRY AGAIN NEXT TIME KID o"); | |
mvprintw(y_offset++, x_offset, "o o"); | |
mvprintw(y_offset++, x_offset, "o o"); | |
mvprintw(y_offset++, x_offset, "o-------------------------------o"); | |
refresh(); | |
napms(1000); | |
mvprintw(y_offset + 1, x_offset, "5.."); refresh(); | |
napms(1000); | |
mvprintw(y_offset + 1, x_offset, "4.."); refresh(); | |
napms(1000); | |
mvprintw(y_offset + 1, x_offset, "3.."); refresh(); | |
napms(1000); | |
mvprintw(y_offset + 1, x_offset, "2.."); refresh(); | |
napms(1000); | |
mvprintw(y_offset + 1, x_offset, "1.."); refresh(); | |
napms(1000); | |
main_menu(); | |
} | |
else | |
if(win == true && input != 27) | |
{ | |
clear(); | |
int y_offset = 5, x_offset = 5; | |
///WIN_SCREEN///////////////////////////////////////////////////////////////////// | |
mvprintw(y_offset++, x_offset, "o-------------------------------o"); | |
mvprintw(y_offset++, x_offset, "o o"); | |
mvprintw(y_offset++, x_offset, "o o"); | |
mvprintw(y_offset++, x_offset, "o CONGRATULATIONS o"); | |
mvprintw(y_offset++, x_offset, "o o"); | |
mvprintw(y_offset++, x_offset, "o YOU WIN o"); | |
mvprintw(y_offset++, x_offset, "o o"); | |
mvprintw(y_offset++, x_offset, "o o"); | |
mvprintw(y_offset++, x_offset, "o-------------------------------o"); | |
refresh(); | |
napms(1000); | |
mvprintw(y_offset + 1, x_offset, "5.."); refresh(); | |
napms(1000); | |
mvprintw(y_offset + 1, x_offset, "4.."); refresh(); | |
napms(1000); | |
mvprintw(y_offset + 1, x_offset, "3.."); refresh(); | |
napms(1000); | |
mvprintw(y_offset + 1, x_offset, "2.."); refresh(); | |
napms(1000); | |
mvprintw(y_offset + 1, x_offset, "1.."); refresh(); | |
napms(1000); | |
main_menu(); | |
} | |
// discard screen | |
endwin(); | |
return 0; | |
} | |
else | |
{ | |
//well, not much to say, you quit without playing.. sad... | |
//anyways, hope you do play it tho | |
//its a nice game for when youre really really bored | |
return 1; | |
} | |
} | |
void start_up() | |
{ | |
clear(); | |
//TITLE SCREEN | |
mvprintw(5, 5, "o----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------o"); | |
mvprintw(6, 5, "| |"); | |
mvprintw(7, 5, "| /$$$$$$$$ /$$ /$$$$$$ |"); | |
mvprintw(8, 5, "| |__ $$__/| $$ /$$__ $$ |"); | |
mvprintw(9, 5, "| | $$ | $$$$$$$ /$$$$$$ | $$ \\ $$ /$$$$$$ /$$$$$$ |"); | |
mvprintw(10, 5, "| | $$ | $$__ $$ /$$__ $$ | $$$$$$$$ /$$__ $$ /$$__ $$ |"); | |
mvprintw(11, 5, "| | $$ | $$ \\ $$| $$$$$$$$ | $$__ $$| $$ \\ $$| $$$$$$$$ |"); | |
mvprintw(12, 5, "| | $$ | $$ | $$| $$_____/ | $$ | $$| $$ | $$| $$_____/ |"); | |
mvprintw(13, 5, "| | $$ | $$ | $$| $$$$$$$ | $$ | $$| $$$$$$$| $$$$$$$ |"); | |
mvprintw(14, 5, "| |__/ |__/ |__/ \\_______/ |__/ |__/ \\____ $$ \\_______/ |"); | |
mvprintw(15, 5, "| /$$ \\ $$ |"); | |
mvprintw(16, 5, "| | $$$$$$/ |"); | |
mvprintw(17, 5, "| \\______/ |"); | |
mvprintw(18, 5, "| /$$$$$$ |"); | |
mvprintw(19, 5, "| /$$__ $$ |"); | |
mvprintw(20, 5, "| /$$$$$$ | $$ \\__/ |"); | |
mvprintw(21, 5, "| /$$__ $$| $$$$ |"); | |
mvprintw(22, 5, "| | $$ \\ $$| $$_/ |"); | |
mvprintw(23, 5, "| | $$ | $$| $$ |"); | |
mvprintw(24, 5, "| | $$$$$$/| $$ |"); | |
mvprintw(25, 5, "| \\______/ |__/ |"); | |
mvprintw(26, 5, "| |"); | |
mvprintw(27, 5, "| |"); | |
mvprintw(28, 5, "| |"); | |
mvprintw(29, 5, "| /$$$$$$$$ /$$ /$$$$$$ /$$ /$$ /$$ /$$ /$$ /$$ |"); | |
mvprintw(30, 5, "| |__ $$__/| $$ /$$__ $$ | $$ | $$ | $$ |__/ | $$ | $$ |"); | |
mvprintw(31, 5, "| | $$ | $$$$$$$ /$$$$$$ | $$ \\__/ /$$$$$$ /$$$$$$ /$$$$$$ /$$$$$$ | $$ /$$$$$$ | $$$$$$$ /$$ /$$ /$$$$$$ /$$ /$$$$$$$ /$$$$$$ | $$$$$$$ |"); | |
mvprintw(32, 5, "| | $$ | $$__ $$ /$$__ $$ | $$ /$$$$ /$$__ $$ /$$__ $$ |____ $$|_ $$_/ | $$ |____ $$| $$__ $$| $$ | $$ /$$__ $$| $$| $$__ $$|_ $$_/ | $$__ $$ |"); | |
mvprintw(33, 5, "| | $$ | $$ \\ $$| $$$$$$$$ | $$|_ $$| $$ \\__/| $$$$$$$$ /$$$$$$$ | $$ | $$ /$$$$$$$| $$ \\ $$| $$ | $$| $$ \\__/| $$| $$ \\ $$ | $$ | $$ \\ $$ |"); | |
mvprintw(34, 5, "| | $$ | $$ | $$| $$_____/ | $$ \\ $$| $$ | $$_____/ /$$__ $$ | $$ /$$ | $$ /$$__ $$| $$ | $$| $$ | $$| $$ | $$| $$ | $$ | $$ /$$| $$ | $$ |"); | |
mvprintw(35, 5, "| | $$ | $$ | $$| $$$$$$$ | $$$$$$/| $$ | $$$$$$$| $$$$$$$ | $$$$/ | $$$$$$$$| $$$$$$$| $$$$$$$/| $$$$$$$| $$ | $$| $$ | $$ | $$$$/| $$ | $$ |"); | |
mvprintw(36, 5, "| |__/ |__/ |__/ \\_______/ \\______/ |__/ \\_______/ \\_______/ \\___/ |________/ \\_______/|_______/ \\____ $$|__/ |__/|__/ |__/ \\___/ |__/ |__/ |"); | |
mvprintw(37, 5, "| /$$ | $$ |"); | |
mvprintw(38, 5, "| | $$$$$$/ |"); | |
mvprintw(39, 5, "| \\______/ |"); | |
mvprintw(40, 5, "| |"); | |
mvprintw(41, 5, "o----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------o"); | |
refresh(); | |
mvprintw(43, 5, "Loading [-----]"); refresh(); | |
napms(300); | |
mvprintw(43, 5, "Loading [#----]"); refresh(); | |
napms(300); | |
mvprintw(43, 5, "Loading [##---]"); refresh(); | |
napms(300); | |
mvprintw(43, 5, "Loading [###--]"); refresh(); | |
napms(300); | |
mvprintw(43, 5, "Loading [####-]"); refresh(); | |
napms(100); | |
mvprintw(43, 5, "Loading [#####]"); refresh(); | |
napms(500); | |
mvprintw(43, 5, "Loading Complete!"); refresh(); | |
mvprintw(45, 5, "Commencing Game"); refresh(); | |
napms(800); | |
clear(); refresh(); | |
///CONTROLS | |
mvprintw(5, 5, "o---------------------------------------------------------------o"); | |
mvprintw(6, 5, "| |"); | |
mvprintw(7, 5, "| Controls: |"); | |
mvprintw(8, 5, "| |"); | |
mvprintw(9, 5, "| - Use the Arrow Keys to move. |"); | |
mvprintw(10, 5, "| - Use WASD to attack. |"); | |
mvprintw(11, 5, "| - When navigating the shop use |"); | |
mvprintw(12, 5, "| i & k to browse your inventory |"); | |
mvprintw(13, 5, "| and y & h to browse the shop. |"); | |
mvprintw(14, 5, "| |"); | |
mvprintw(15, 5, "| PRESS ANY KEY TO CONTINUE |"); | |
mvprintw(16, 5, "| |"); | |
mvprintw(17, 5, "o---------------------------------------------------------------o"); | |
refresh(); | |
getch(); | |
clear(); refresh(); | |
//NOTES | |
mvprintw(5, 5, "o---------------------------------------------------------------o"); | |
mvprintw(6, 5, "| |"); | |
mvprintw(7, 5, "| Notes: |"); | |
mvprintw(8, 5, "| |"); | |
mvprintw(9, 5, "| - You have to kill every enemy in order to win. |"); | |
mvprintw(10, 5, "| - Some foes are more powerful than others. |"); | |
mvprintw(11, 5, "| - Getting close will hurt you. |"); | |
mvprintw(12, 5, "| - You can buy items at the shopkeeper (S). |"); | |
mvprintw(13, 5, "| - If you are killed, you die. |"); | |
mvprintw(14, 5, "| |"); | |
mvprintw(15, 5, "| PRESS ANY KEY TO CONTINUE |"); | |
mvprintw(16, 5, "| |"); | |
mvprintw(17, 5, "o---------------------------------------------------------------o"); | |
refresh(); | |
getch(); | |
clear(); refresh(); | |
main_menu(); | |
} | |
void main_menu() | |
{ | |
char menu_input; | |
int mode = 0; | |
clear(); | |
mvprintw(5, 5, "o---------------------------------------------------------------o"); | |
mvprintw(6, 5, "| |"); | |
mvprintw(7, 5, "| The Age of The Great Labyrinth |"); | |
mvprintw(8, 5, "| |"); | |
mvprintw(9, 5, "| |"); | |
mvprintw(10, 5, "| Play |"); | |
mvprintw(11, 5, "| |"); | |
mvprintw(12, 5, "| Credits |"); | |
mvprintw(13, 5, "| |"); | |
mvprintw(14, 5, "| Quit |"); | |
mvprintw(15, 5, "| |"); | |
mvprintw(16, 5, "| |"); | |
mvprintw(17, 5, "o---------------------------------------------------------------o"); | |
refresh(); | |
while(true) | |
{ | |
//mvprintw(19, 5, "%d", menu_input); //debug input | |
if(mode == 0) | |
{ | |
mvprintw(10, 5, "| > Play < |"); | |
mvprintw(12, 5, "| Credits |"); | |
mvprintw(14, 5, "| Quit |"); | |
refresh(); | |
} | |
if(mode == 1) | |
{ | |
mvprintw(10, 5, "| Play |"); | |
mvprintw(12, 5, "| > Credits < |"); | |
mvprintw(14, 5, "| Quit |"); | |
refresh(); | |
} | |
if(mode == 2) | |
{ | |
mvprintw(10, 5, "| Play |"); | |
mvprintw(12, 5, "| Credits |"); | |
mvprintw(14, 5, "| > Quit < |"); | |
refresh(); | |
} | |
menu_input = getch(); | |
if(menu_input == 10) //enter | |
{ | |
if(mode == 0) {clear(); break;} //play | |
if(mode == 1) credits(); //credits | |
if(mode == 2) {that_one_global_variable_that_i_couldve_used_as_a_parameter_in_a_function_but_at_this_point_im_way_too_lazy_and_IT_STILL_WORKS_SO_DONT_TELL_ME_NOTHING = false; endwin(); break;} //quit | |
} | |
if(menu_input == 'w' || menu_input == 3) //up key | |
{ | |
if(mode == 0) mode = 2; else | |
if(mode == 2) mode = 1; else | |
if(mode == 1) mode = 0; | |
} | |
if(menu_input == 's' || menu_input == 2) //down key | |
{ | |
if(mode == 0) mode = 1; else | |
if(mode == 1) mode = 2; else | |
if(mode == 2) mode = 0; | |
} | |
} | |
} | |
void credits() | |
{ | |
clear(); | |
mvprintw(5, 5, "o---------------------------------------------------------------o"); | |
mvprintw(6, 5, "| |"); | |
mvprintw(7, 5, "| Team Squadgang Credits |"); | |
mvprintw(8, 5, "| |"); | |
mvprintw(9, 5, "| Team Leader & Programmer - Declan Soper |"); | |
mvprintw(10, 5, "| Chief Programmer - Pop Andrei |"); | |
mvprintw(11, 5, "| Database Specialist - Joshua L. Handley |"); | |
mvprintw(12, 5, "| Map Making Supervisor - Bertoldas Cepulis |"); | |
mvprintw(13, 5, "| Supreme Pixel Artist - Ioana Circu |"); | |
mvprintw(14, 5, "| Content Manager - Ana Maria |"); | |
mvprintw(15, 5, "| |"); | |
mvprintw(16, 5, "| PRESS ANY KEY TO CONTINUE |"); | |
mvprintw(17, 5, "o---------------------------------------------------------------o"); | |
refresh(); | |
getch(); | |
clear(); | |
mvprintw(5, 5, "o---------------------------------------------------------------o"); | |
mvprintw(6, 5, "| |"); | |
mvprintw(7, 5, "| The Age of The Great Labyrinth |"); | |
mvprintw(8, 5, "| |"); | |
mvprintw(9, 5, "| |"); | |
mvprintw(10, 5, "| Play |"); | |
mvprintw(11, 5, "| |"); | |
mvprintw(12, 5, "| Credits |"); | |
mvprintw(13, 5, "| |"); | |
mvprintw(14, 5, "| Quit |"); | |
mvprintw(15, 5, "| |"); | |
mvprintw(16, 5, "| |"); | |
mvprintw(17, 5, "o---------------------------------------------------------------o"); | |
refresh(); | |
} |