Skip to content
Permalink
Browse files
…aider

- Ohh and enhanced maze UI
  • Loading branch information
mateussa committed Mar 6, 2018
2 parents 7cbc0b2 + 7101a2a commit bff0f46752e4655e7742824f9e24dd183490b14a
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 39 deletions.
BIN -41 MB Track.wav
Binary file not shown.
@@ -2,6 +2,8 @@
#define LEVELMANAGER_H
#include <vector>
#include <memory>
#include <cstdlib>
#include <string>


using namespace std;
BIN +37.1 MB (1000%) sounds/musics/MainMenu.wav
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -316,6 +316,7 @@ void BattleScene::PlayAttack(int atype, int colour)
cout << "\033[s";
#endif // __linux__

//music
lvlManager.lock()->playEffect(LevelManager::Effect::Attack);

switch (atype)
@@ -31,10 +31,10 @@ void LevelManager::BuildLevel()

enemyai = make_shared<EnemyAI>(shared_from_this());
ui = make_shared<UI>(shared_from_this());

changeMusic(Music::SelectionScreen);
ui->ShowSelectionScreen();

scoretime = new ScoreTime(this);

ui->ShowUI();
}

@@ -59,7 +59,7 @@ void LevelManager::changeMusic(Music m)
PlaySound(TEXT("sounds/musics/SelectionScreen.wav"),NULL, SND_FILENAME | SND_ASYNC | SND_LOOP);
break;
case Music::Map:
i = rand() % 7 + 1;
i = rand() % 8 + 1;
oss << "sounds/musics/Map_" << i << ".wav";
PlaySound(TEXT(oss.str().c_str()),NULL, SND_FILENAME | SND_ASYNC | SND_LOOP);
break;
@@ -6,8 +6,10 @@
#include <stdexcept>
#include <vector>
#include <time.h>
#include <LevelManager.h>
#include <algorithm>


/**
* Constructor.
*
@@ -3,6 +3,9 @@
#include "Enemy.h"
#include "BattleScene.h"
#include "UI.h"
#include "UIHelpers.h"

using namespace UIHelpers;

Player::Player(LevelManager *lvlman)
{
@@ -33,24 +36,25 @@ void Player::movePlayer(char direction)
if(lvlmanager->ui->inBattle)
break;

//checking to see if there's a path on both sides
if(maze->getMazeArray()[xPos-1][yPos+steps] == 0 || maze->getMazeArray()[xPos+1][yPos+steps] == 0)
{
steps+=1;
break;
}
//checking to see if there's a chest in front
else if(maze->getMazeArray()[xPos][yPos+steps] == 3)
{
Player::chestEvent();
break;
}
else if(maze->getMazeArray()[xPos][yPos+steps] == 5)
//checking to see if the exit is on the right
else if(maze->getMazeArray()[xPos+1][yPos+steps] == 5)
{
lvlmanager->ui->ShowNextLevel();
steps+=1;
break;
}
steps+=1;


}
yPos += steps-1;
checkChest();
@@ -73,13 +77,7 @@ void Player::movePlayer(char direction)
Player::chestEvent();
break;
}
else if(maze->getMazeArray()[xPos-steps][yPos] == 5)
{
lvlmanager->ui->ShowNextLevel();
break;
}
steps+=1;

}
xPos -= steps-1;
checkChest();
@@ -103,10 +101,10 @@ void Player::movePlayer(char direction)
Player::chestEvent();
break;
}
//checking to see if the player is facing the exit
else if(maze->getMazeArray()[xPos+steps][yPos] == 5)
{
lvlmanager->ui->ShowNextLevel();

break;
}
steps+=1;
@@ -135,7 +133,7 @@ void Player::movePlayer(char direction)
}
else if(maze->getMazeArray()[xPos+1][yPos-steps] == 5)
{
lvlmanager->ui->ShowNextLevel();
steps+=1;
break;
}

@@ -183,7 +181,7 @@ void Player::chestEvent(void)
cout << row[0] << row[1] << endl;

//query for changing the value on the player's weapon
string saveWeapon = "UPDATE PlayerChar SET weapon_id=" + to_string(atoi(row[2])) + " WHERE char_id=" + to_string(pCharID);
string saveWeapon = SQLPrepare("UPDATE PlayerChar SET weapon_id= '%?' WHERE char_id= '%?'", atoi(row[2]), pCharID);

if (!mysql_query(connection, saveWeapon.c_str()))
cout << mysql_error(connection) << endl;
@@ -114,15 +114,12 @@ int ScoreTime::savehighscore(){

//we are inserting the values in the highscore so I used insert. so it will store customer id and highscore inside the highscore table.
//We are using values to tell what we need to store in the database. basically I needed to store playerID and the hScore from the game. So I put that in.
string data="insert into highscore(char_id, highscore, mazeid) values(" +
to_string(lvlManager->player->pCharID) + "', '"+to_string(hScore)+"', '" + to_string(lvlManager->maze->getSeed()) + "')";


string data= UIHelpers::SQLPrepare("insert into highscore(char_id, highscore, mazeid) values('%?', '%?', '%?')",lvlManager->player->pCharID, hScore, lvlManager->maze->getSeed());
int querystate = mysql_query(connection, data.c_str());
//Once it successful it will say saved successfull.
if(!querystate) {
cout<<"Saved...\n\n" << endl;
cout<<"Rank ID High Score"<<endl;
cout<<"Rank ID Character ID"<<endl;

} else {
//if not it will say failed to save and system will pause. It will wait user to put an input
@@ -147,15 +144,16 @@ int ScoreTime::makeHighscoreTable(){
//This will allow you to connect to the database.
mysql_real_connect(connection,"server1.jesseprescott.co.uk","jessepre","Mazeraider123?","jessepre_mazeraider",0,NULL,0);
//Now we are linking tables in the database.
string getData = "SELECT h.highscore, pc.name FROM highscore h, PlayerChar pc "
"WHERE h.char_id=pc.char_id AND h.mazeid=" + to_string(lvlManager->maze->getSeed()) + " ORDER BY h.highscore DESC LIMIT 10";
string getData = UIHelpers::SQLPrepare("SELECT h.highscore, pc.name FROM highscore h, PlayerChar pc "
"WHERE h.char_id=pc.char_id AND h.mazeid=%? ORDER BY h.highscore DESC LIMIT 10", lvlManager->maze->getSeed());

//this will allow get the data as a sting
query = mysql_query(connection, getData.c_str());
if(!query){
//this will allow you to show up the results
results = mysql_store_result(connection);
//this will allow to show the number of their rank.
int i=0;
int i=1;
//rows represent the actual able rows and we will cout them to show up in the actual game.
while((row = mysql_fetch_row(results)))
{
@@ -21,23 +21,25 @@ UI::UI(shared_ptr<LevelManager> lvlman)
//Show player character selection screen
void UI::ShowSelectionScreen()
{
bool selected = false;
if(shared_ptr<LevelManager> lvlman = lvlManager.lock())
{
lvlman->changeMusic(LevelManager::Music::SelectionScreen);

bool selected = false;

MYSQL *connection;
connection = mysql_init(0);
MYSQL_RES *result;

mysql_real_connect(connection, "server1.jesseprescott.co.uk", "jessepre", "Mazeraider123?", "jessepre_mazeraider", 0, NULL, 0);
if(!connection)
{
cout << "Failed to connect to the database." << endl;
exit(0);
}
MYSQL *connection;
connection = mysql_init(0);
MYSQL_RES *result;

while(!selected)
{
if(shared_ptr<LevelManager> lvlman = lvlManager.lock())
mysql_real_connect(connection, "server1.jesseprescott.co.uk", "jessepre", "Mazeraider123?", "jessepre_mazeraider", 0, NULL, 0);
if(!connection)
{
cout << "Failed to connect to the database." << endl;
exit(0);
}

while(!selected)
{
clearScreen();
cout << endl;
@@ -711,6 +713,7 @@ void UI::PrintUOptions()

void UI::ShowGameOver()
{
lvlManager.lock()->playEffect(LevelManager::Effect::LevelLost);
clearScreen();
PrintC("Game Over!");

@@ -756,8 +759,15 @@ void UI::ShowNextLevel()
{
lvlman->playEffect(LevelManager::Effect::LevelPassed);
clearScreen();

lvlman->scoretime->savehighscore();
lvlman->scoretime->makeHighscoreTable();

cout << endl;

PrintC("You've finished your level. Choose the difficulty for the next level OR computer can choose for you");
cout << endl;

PrintC(" Low: ");
PrintC("L", 15);
PrintC(" ");
@@ -157,6 +157,8 @@ void UIHelpers::buildPause(shared_ptr<LevelManager> lvlManager, int x, int y, bo
int hStdOut;
#endif // __linux__



int input;
string mute = "Mute ";
if(lvlManager->isMuted)
@@ -59,7 +59,6 @@ void loginUser() {

// TODO: Fix SQL Injection.
string query=SQLPrepare("select user_id from user_info where username = '%?' and password = '%?'", username, password);
//string query="select user_id from user_info where username='"+username+"' and password='"+password+"';";

int queryResult = mysql_query(connection, query.c_str());
MYSQL_RES *result = mysql_store_result(connection);
@@ -81,7 +80,8 @@ void registerUser() {
cout<<"Username: "; cin>>username;
cout<<"Password: "; cin>>password;

string register_users="insert into user_info(name,username,password) values('"+name+"','"+username+"','"+password+"')";
string register_users = SQLPrepare("insert into user_info(name,username,password) values('%?','%?','%?')", name, username, password);

int querystate = mysql_query(connection, register_users.c_str());

if(!querystate) {
@@ -102,6 +102,7 @@ int main() {

while (1) {
PlaySound(TEXT("sounds/musics/MainMenu.wav"),NULL, SND_FILENAME | SND_ASYNC | SND_LOOP);

clearScreen();
printLogo();
printMenu();

0 comments on commit bff0f46

Please sign in to comment.