Skip to content
Permalink
Browse files
Implemented characters
- Created character mechanics
- Enhanced UI, maze and battle, and fixed some bugs
- Added full screen function
  • Loading branch information
mateussa committed Feb 24, 2018
1 parent de47b3f commit 49edf8828ad441137594e33f300f0230ff5508f1
Show file tree
Hide file tree
Showing 13 changed files with 564 additions and 133 deletions.
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>mazeraider</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>
@@ -70,77 +70,5 @@ class BattleScene
void PlayDefend(int dtype, int colour);
// Play heal animation
void PlayHeal(int htype, int colour);

// Meshes
vector<vector<string>> enemyMesh = {{" ",
" . . ",
" ) ( ",
" _ _ _ _ _ _ _ _ _ _ _(.--.) ",
" {{ { { { { { { { { { { ( '_') ",
" >>>>>>>>>>>>>>>>>>>>>>>`--'> ",
" ",
" "},
{" ",
R"( _.---._ /\\ )",
R"( ./' "--`\// )",
R"( ./ o \ )",
R"( /./\ )______ \__ \ )",
R"( ./ / /\ \ | \ \ \ \ )",
R"( / / \ \ | |\ \ \7 )",
" "},
{" ",
R"( (o)--(o) )",
R"( /.______.\ )",
R"( \________/ )",
R"( ./ \. )",
R"( ( . , ) )",
R"( \ \_\\//_/ / )",
R"( ~~ ~~ ~~ )"},
{" ",
R"( .-._ )",
R"( {_}^ )o )",
R"( {\________//~` )",
R"( ( ) )",
R"( /||~~~~~||\ )",
R"( |_\\_ \\_\ )",
R"( "' ""' ""'"' )"}};


vector<vector<string>> playerMesh = {{" _O_ ",
R"( / \ )",
R"( |==/=\==| )",
" | O O | ",
R"( \ V / )",
R"( /`---'\ )",
" O'_:_`O ",
" -- -- "},

{" _____ ",
" | | ",
R"( |[/_\]| )",
R"( / O O \ )",
R"( /\ - /\ )",
R"( /`---'\ )",
" O'M|M`O ",
" -- -- "},

{" _<>_ ",
R"( / \ )",
R"( |==\==/==| )",
" | >< | ",
R"( ,-\ () /-. )",
" V( `-====-' )V ",
" (_____:|_____) ",
" ---- ---- "},

{" ___ ",
R"( / _ \ )",
R"( | / \ | )",
" | |*| | ",
R"( \ X / )",
R"( /`---'\ )",
" O'_|_`O ",
" -- -- ",}};

};
#endif // BATTLESCENE_H
@@ -14,7 +14,7 @@ class EnemyAI;
class LevelManager
{
public:
LevelManager();
LevelManager(int pID);

UI* ui;
Maze* maze;
@@ -23,9 +23,12 @@ class LevelManager
EnemyAI* enemyai;
vector<Enemy*> enemies;

int getPlayerID();

protected:

private:
int playerID;
};

#endif // LEVELMANAGER_H
@@ -23,19 +23,22 @@ class Player


int playerPoints = 0;
int pCharID = 0;
string pName = "<player>";
int pMesh = 0;
int pHealth = 100;
int pDamage = 10;
int pArmor = 2;
int pArmour = 2;
pair<string, int> pWeapon = make_pair("Sword", 10);
int pKeys = 0;
int pHealPower = 10;

// Type is 0 or 1
// Colour sheet on maizeraider folder
int pAttackType = 0;
int pAttackColour = 10;
int pDefendType = 0;
int pDefendColour = 3;
int pAttackColour = 3;
int pDefenceType = 0;
int pDefenceColour = 3;
int pHealType = 0;
int pHealColour = 2;

@@ -1,6 +1,10 @@
#ifndef UI_H
#define UI_H
#include <vector>
#include <array>
#include <map>
#include <windows.h>
#include <mysql.h>



@@ -16,17 +20,90 @@ class UI

// Build UI
void ShowUI();

//Show player character selection screen
void ShowSelectionScreen();

// Check if it's in battle
bool inBattle;

BattleScene* btlScene;

// Meshes
vector<array<string, 8>> enemyMesh = {{" ",
" . . ",
" ) ( ",
" _ _ _ _ _ _ _ _ _ _ _(.--.) ",
" {{ { { { { { { { { { { ( '_') ",
" >>>>>>>>>>>>>>>>>>>>>>>`--'> ",
" ",
" "},

{" ",
R"( _.---._ /\\ )",
R"( ./' "--`\// )",
R"( ./ o \ )",
R"( /./\ )______ \__ \ )",
R"( ./ / /\ \ | \ \ \ \ )",
R"( / / \ \ | |\ \ \7 )",
" "},

{" ",
R"( (o)--(o) )",
R"( /.______.\ )",
R"( \________/ )",
R"( ./ \. )",
R"( ( . , ) )",
R"( \ \_\\//_/ / )",
R"( ~~ ~~ ~~ )"},

{" ",
R"( .-._ )",
R"( {_}^ )o )",
R"( {\________//~` )",
R"( ( ) )",
R"( /||~~~~~||\ )",
R"( |_\\_ \\_\ )",
R"( "' ""' ""'"' )"}};

vector<array<string, 8>> playerMesh = {{" _O_ ",
R"( / \ )",
R"( |==/=\==| )",
" | O O | ",
R"( \ V / )",
R"( /`---'\ )",
" O'_:_`O ",
" -- -- "},

{" _____ ",
" | | ",
R"( |[/_\]| )",
R"( / O O \ )",
R"( /\ - /\ )",
R"( /`---'\ )",
" O'M|M`O ",
" -- -- "},

{" _<>_ ",
R"( / \ )",
R"( |==\==/==| )",
" | >< | ",
R"( ,-\ () /-. )",
" V( `-====-' )V ",
" (_____:|_____) ",
" ---- ---- "},

{" ___ ",
R"( / _ \ )",
R"( | / \ | )",
" | |*| | ",
R"( \ X / )",
R"( /`---'\ )",
" O'_|_`O ",
" -- -- "}};

protected:

private:

// Pointer to level manager
LevelManager* lvlManager;

@@ -38,6 +115,14 @@ class UI
void PrintUOptions();
// Screen for gameover
void ShowGameOver();
// Print array to screen
void selCharPrintOptions(array<string, 12> &mOptions, int &c);
// White space between char info
void selCharWhiteSpaceDivider(array<string, 12> &mOptions, int c);
// Screen to create character
void selCharCreateNew(MYSQL* connection);
// Delete character
void selCharDelete(MYSQL* connection, int charID, string name);

};

@@ -3,8 +3,12 @@

#include <string>
#include <iostream>
#include <vector>
#include <array>
#include <cctype>

#ifdef _WIN32
#define _WIN32_WINNT 0x0500
#include <windows.h>
#include <stdlib.h>
#define clearScreen() system("cls")
@@ -51,6 +55,7 @@

#ifdef __linux__
#include <sstream>
#include <iostream>
#include <chrono>
#include <thread>
#define Sleep(x) cout << flush; this_thread::sleep_for(chrono::milliseconds(x));
@@ -100,6 +105,12 @@ namespace UIHelpers
void PrintC(string character, int color = 7, bool twoChar = false);
// change the text colour
bool ChangeColor(int color);

string toLower(string str);

void setFullScreen();


};

#endif // UIHELPERS_H
@@ -161,8 +161,8 @@ int BattleScene::BuildScene()
// Player name
else if (w == 5 && h == 1)
{
string name = "<player>";
PrintC(name, 3);
string name = lvlManager->player->pName;
PrintC(name, lvlManager->player->pAttackColour);

w += name.size() - 1;
}
@@ -221,9 +221,9 @@ int BattleScene::BuildScene()
// Draw player
else if (h >= (sceneHeight / 2) - 1 && h < sceneHeight && w > 5 && w <= (playerWidth + 5))
{
if (h - ((sceneHeight / 2) - 1) < playerMesh[1].size())
if (h - ((sceneHeight / 2) - 1) < lvlManager->ui->playerMesh[lvlManager->player->pMesh].size())
{
cout << playerMesh[1][h - ((sceneHeight / 2) - 1)];
cout << lvlManager->ui->playerMesh[lvlManager->player->pMesh][h - ((sceneHeight / 2) - 1)];
playerCounter++;
w += playerWidth - 1;
}
@@ -232,9 +232,9 @@ int BattleScene::BuildScene()
// Draw enemy
else if (h > 0 && h <= sceneHeight / 2 && w >= sceneWidth - (enemyWidth + 5) && w < sceneWidth - 5)
{
if (h - 1 < enemyMesh[enemy->getMesh()].size())
if (h - 1 < lvlManager->ui->enemyMesh[enemy->getMesh()].size())
{
cout << enemyMesh[enemy->getMesh()][h - 1];
cout << lvlManager->ui->enemyMesh[enemy->getMesh()][h - 1];
enemyCounter++;
w += enemyWidth - 1;
}
@@ -767,17 +767,17 @@ void BattleScene::PlayerAttack()
}

tempHealth = tempHealth - enemyHealth;
UpdateBattleInfo("<player> dealt " + to_string(tempHealth) + " damage", 1);
UpdateBattleInfo(lvlManager->player->pName + " dealt " + to_string(tempHealth) + " damage", 1);

isEnemyDefending = false;
TPlayerFEnemy = false;
}

void BattleScene::PlayerDefend()
{
PlayDefend(lvlManager->player->pDefendType, lvlManager->player->pDefendColour);
PlayDefend(lvlManager->player->pDefenceType, lvlManager->player->pDefenceColour);

UpdateBattleInfo("<player> is defending", 2);
UpdateBattleInfo(lvlManager->player->pName + " is defending", 2);

isPlayerDefending = true;
isEnemyDefending = false;
@@ -796,7 +796,7 @@ void BattleScene::PlayerHeal()
playerHealth = playerMaxHealth;

tempHealth = playerHealth - tempHealth;
UpdateBattleInfo("<player> healed by " + to_string(tempHealth), 3);
UpdateBattleInfo(lvlManager->player->pName + " healed by " + to_string(tempHealth), 3);

isEnemyDefending = false;
TPlayerFEnemy = false;
@@ -815,7 +815,7 @@ bool BattleScene::canPlayerRun()

if (chance <= changeLimit)
{
UpdateBattleInfo("<player> ran from battle.", 0);
UpdateBattleInfo(lvlManager->player->pName + " ran from battle.", 0);

// Delete enemy from vector
auto it = find(lvlManager->enemies.begin(), lvlManager->enemies.end(), enemy);
@@ -831,7 +831,7 @@ bool BattleScene::canPlayerRun()
}
else
{
UpdateBattleInfo(enemy->getName() + " stopped <player> from running.", 0);
UpdateBattleInfo(enemy->getName() + " stopped " + lvlManager->player->pName + " from running.", 0);
isEnemyDefending = false;
TPlayerFEnemy = false;
return false;
@@ -849,8 +849,8 @@ void BattleScene::EnemyAttack()
{
int damageToDeal = 0;

if(enemy->getAttackPower() > lvlManager->player->pArmor)
damageToDeal = (enemy->getAttackPower() + enemy->getWeapon().second) - lvlManager->player->pArmor;
if(enemy->getAttackPower() > lvlManager->player->pArmour)
damageToDeal = (enemy->getAttackPower() + enemy->getWeapon().second) - lvlManager->player->pArmour;

if(enemyHealth - damageToDeal >= 0)
playerHealth -= damageToDeal;
@@ -149,8 +149,7 @@ void Enemy::statsFromDatabase()
"FROM Enemy e, Weapon w WHERE e.weapon_id = w.weapon_id "
"ORDER BY RAND() LIMIT 1;";

int query_state = mysql_query(connection, query.c_str());
if (query_state !=0)
if (mysql_query(connection, query.c_str()))
cout << mysql_error(connection) << endl;

MYSQL_RES* result = mysql_store_result(connection);

0 comments on commit 49edf88

Please sign in to comment.