diff --git a/Track.wav b/Track.wav deleted file mode 100644 index a0cb24a..0000000 Binary files a/Track.wav and /dev/null differ diff --git a/include/LevelManager.h b/include/LevelManager.h index d4d413c..fe67320 100644 --- a/include/LevelManager.h +++ b/include/LevelManager.h @@ -2,6 +2,8 @@ #define LEVELMANAGER_H #include #include +#include +#include using namespace std; diff --git a/sounds/musics/MainMenu.wav b/sounds/musics/MainMenu.wav index 8f0e25c..a0cb24a 100644 Binary files a/sounds/musics/MainMenu.wav and b/sounds/musics/MainMenu.wav differ diff --git a/sounds/musics/Map_8.wav b/sounds/musics/Map_8.wav new file mode 100644 index 0000000..5b6c030 Binary files /dev/null and b/sounds/musics/Map_8.wav differ diff --git a/sounds/musics/SelectionScreen.wav b/sounds/musics/SelectionScreen.wav index 5b6c030..8f0e25c 100644 Binary files a/sounds/musics/SelectionScreen.wav and b/sounds/musics/SelectionScreen.wav differ diff --git a/src/BattleScene.cpp b/src/BattleScene.cpp index f489968..a9ab759 100644 --- a/src/BattleScene.cpp +++ b/src/BattleScene.cpp @@ -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) diff --git a/src/LevelManager.cpp b/src/LevelManager.cpp index c16a9a0..dac3ae4 100644 --- a/src/LevelManager.cpp +++ b/src/LevelManager.cpp @@ -31,10 +31,10 @@ void LevelManager::BuildLevel() enemyai = make_shared(shared_from_this()); ui = make_shared(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; diff --git a/src/Maze.cpp b/src/Maze.cpp index 999c8fc..8d7ee3f 100644 --- a/src/Maze.cpp +++ b/src/Maze.cpp @@ -6,8 +6,10 @@ #include #include #include +#include #include + /** * Constructor. * diff --git a/src/Player.cpp b/src/Player.cpp index 02e27c2..61b6bd2 100644 --- a/src/Player.cpp +++ b/src/Player.cpp @@ -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; diff --git a/src/ScoreTime.cpp b/src/ScoreTime.cpp index c6df51c..3fe3669 100644 --- a/src/ScoreTime.cpp +++ b/src/ScoreTime.cpp @@ -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"<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))) { diff --git a/src/UI.cpp b/src/UI.cpp index 604b70c..c881254 100644 --- a/src/UI.cpp +++ b/src/UI.cpp @@ -21,23 +21,25 @@ UI::UI(shared_ptr lvlman) //Show player character selection screen void UI::ShowSelectionScreen() { - bool selected = false; + if(shared_ptr 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 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(" "); diff --git a/src/UIHelpers.cpp b/src/UIHelpers.cpp index 31bafb0..460f97f 100644 --- a/src/UIHelpers.cpp +++ b/src/UIHelpers.cpp @@ -157,6 +157,8 @@ void UIHelpers::buildPause(shared_ptr lvlManager, int x, int y, bo int hStdOut; #endif // __linux__ + + int input; string mute = "Mute "; if(lvlManager->isMuted) diff --git a/src/main.cpp b/src/main.cpp index 61faf55..6d6751f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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();