Skip to content

Commit

Permalink
Major change since last update
Browse files Browse the repository at this point in the history
Added MongoDB C++ Driver
Ported to 64-bit due to ease to use mongocxx
Removed nlohmann/json
A MongoDBInstance Singleton Class is created
Config File is added for mongoDB URI(not in public repo)
Leadershipboard now shows Top Ten Players having highest Scores
Email Validation is implemented using Regex
  • Loading branch information
abhayMore committed Jun 2, 2023
1 parent ced930d commit 9a86f3d
Show file tree
Hide file tree
Showing 22 changed files with 454 additions and 343 deletions.
34 changes: 26 additions & 8 deletions AMMPED-UP/AMMPED-UP.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<ClCompile Include="Source\AudioManager.cpp" />
<ClCompile Include="Source\Bomb.cpp" />
<ClCompile Include="Source\Coin.cpp" />
<ClCompile Include="Source\Config.cpp" />
<ClCompile Include="Source\Enemy.cpp" />
<ClCompile Include="Source\ExitState.cpp" />
<ClCompile Include="Source\Game.cpp" />
Expand All @@ -34,6 +35,8 @@
<ClCompile Include="Source\LoginState.cpp" />
<ClCompile Include="Source\main.cpp" />
<ClCompile Include="Source\MainMenu.cpp" />
<ClCompile Include="Source\MongoDB.cpp" />
<ClCompile Include="Source\MongoInstanceManager.cpp" />
<ClCompile Include="Source\OptionsState.cpp" />
<ClCompile Include="Source\PauseGame.cpp" />
<ClCompile Include="Source\PlayerEntity.cpp" />
Expand All @@ -52,6 +55,7 @@
<ClInclude Include="Header Files\Bomb.h" />
<ClInclude Include="Header Files\Button.h" />
<ClInclude Include="Header Files\Coin.h" />
<ClInclude Include="Header Files\Config.h" />
<ClInclude Include="Header Files\Enemy.h" />
<ClInclude Include="Header Files\ExitState.h" />
<ClInclude Include="Header Files\Game.h" />
Expand All @@ -61,6 +65,8 @@
<ClInclude Include="Header Files\LoginPageState.h" />
<ClInclude Include="Header Files\LoginState.h" />
<ClInclude Include="Header Files\MainMenu.h" />
<ClInclude Include="Header Files\MongoDB.h" />
<ClInclude Include="Header Files\MongoInstanceManager.h" />
<ClInclude Include="Header Files\OptionsState.h" />
<ClInclude Include="Header Files\PauseGame.h" />
<ClInclude Include="Header Files\PlayerEntity.h" />
Expand Down Expand Up @@ -146,14 +152,16 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
<AdditionalIncludeDirectories>$(SolutionDir)AMMPED-UP\Dependencies\TGUI\include;$(SolutionDir)AMMPED-UP\Dependencies\json-3.11.2\include;$(SolutionDir)AMMPED-UP\Dependencies\SFML\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp17</LanguageStandard>
<AdditionalIncludeDirectories>$(SolutionDir)AMMPED-UP\Dependencies\TGUI\include;$(SolutionDir)AMMPED-UP\Dependencies\json-3.11.2\include;$(SolutionDir)AMMPED-UP\Dependencies\SFML\include;$(SolutionDir)AMMPED-UP\Dependencies\mongo-c-driver\include\libmongoc-1.0;$(SolutionDir)AMMPED-UP\Dependencies\mongo-c-driver\include\libbson-1.0;$(SolutionDir)AMMPED-UP\Dependencies\mongo-cxx-driver-r3.7.1\include\bsoncxx\v_noabi;$(SolutionDir)AMMPED-UP\Dependencies\mongo-cxx-driver-r3.7.1\include\mongocxx\v_noabi;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions>/Zc:__cplusplus %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(SolutionDir)AMMPED-UP\Dependencies\TGUI\lib;$(SolutionDir)AMMPED-UP\Dependencies\SFML\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>sfml-system-d.lib;sfml-graphics-d.lib;sfml-audio-d.lib;sfml-window-d.lib;sfml-network-d.lib;tgui-d.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(SolutionDir)AMMPED-UP\Dependencies\TGUI\lib;$(SolutionDir)AMMPED-UP\Dependencies\SFML\lib;$(SolutionDir)AMMPED-UP\Dependencies\mongo-cxx-driver-r3.7.1\lib;$(SolutionDir)AMMPED-UP\Dependencies\mongo-c-driver\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>sfml-system-d.lib;sfml-graphics-d.lib;sfml-audio-d.lib;sfml-window-d.lib;sfml-network-d.lib;tgui-d.lib;bson-1.0.lib;mongoc-1.0.lib;bsoncxx.lib;mongocxx.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalOptions>/Zc:__cplusplus %(AdditionalOptions)</AdditionalOptions>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
Expand All @@ -164,16 +172,17 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
<AdditionalIncludeDirectories>$(SolutionDir)AMMPED-UP\Dependencies\TGUI\include;$(SolutionDir)AMMPED-UP\Dependencies\json-3.11.2\include;$(SolutionDir)AMMPED-UP\Dependencies\SFML\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp17</LanguageStandard>
<AdditionalIncludeDirectories>$(SolutionDir)AMMPED-UP\Dependencies\TGUI\include;$(SolutionDir)AMMPED-UP\Dependencies\json-3.11.2\include;$(SolutionDir)AMMPED-UP\Dependencies\SFML\include;$(SolutionDir)AMMPED-UP\Dependencies\mongo-cxx-driver-r3.7.1\include\mongocxx\v_noabi;$(SolutionDir)AMMPED-UP\Dependencies\mongo-cxx-driver-r3.7.1\include\bsoncxx\v_noabi;$(SolutionDir)AMMPED-UP\Dependencies\mongo-c-driver\include\libbson-1.0;$(SolutionDir)AMMPED-UP\Dependencies\mongo-c-driver\include\libmongoc-1.0;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions>/Zc:__cplusplus %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(SolutionDir)AMMPED-UP\Dependencies\TGUI\lib;$(SolutionDir)AMMPED-UP\Dependencies\SFML\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>sfml-system.lib;sfml-graphics.lib;sfml-audio.lib;sfml-window.lib;sfml-network.lib;tgui.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(SolutionDir)AMMPED-UP\Dependencies\TGUI\lib;$(SolutionDir)AMMPED-UP\Dependencies\SFML\lib;$(SolutionDir)AMMPED-UP\Dependencies\mongo-c-driver\lib;$(SolutionDir)AMMPED-UP\Dependencies\mongo-cxx-driver-r3.7.1\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>sfml-system.lib;sfml-graphics.lib;sfml-audio.lib;sfml-window.lib;sfml-network.lib;tgui.lib;bson-1.0.lib;mongoc-1.0.lib;bsoncxx.lib;mongocxx.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
Expand All @@ -182,10 +191,14 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(SolutionDir)AMMPED-UP\Dependencies\TGUI\include;$(SolutionDir)AMMPED-UP\Dependencies\json-3.11.2\include;$(SolutionDir)AMMPED-UP\Dependencies\SFML\include;$(SolutionDir)AMMPED-UP\Dependencies\mongo-c-driver\include\libmongoc-1.0;$(SolutionDir)AMMPED-UP\Dependencies\mongo-c-driver\include\libbson-1.0;$(SolutionDir)AMMPED-UP\Dependencies\mongo-cxx-driver-r3.7.1\include\bsoncxx\v_noabi;$(SolutionDir)AMMPED-UP\Dependencies\mongo-cxx-driver-r3.7.1\include\mongocxx\v_noabi;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(SolutionDir)AMMPED-UP\Dependencies\TGUI\lib;$(SolutionDir)AMMPED-UP\Dependencies\SFML\lib;$(SolutionDir)AMMPED-UP\Dependencies\mongo-c-driver\lib;$(SolutionDir)AMMPED-UP\Dependencies\mongo-cxx-driver-r3.7.1\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>sfml-system-d.lib;sfml-graphics-d.lib;sfml-audio-d.lib;sfml-window-d.lib;sfml-network-d.lib;tgui-d.lib;bson-1.0.lib;mongoc-1.0.lib;bsoncxx.lib;mongocxx.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand All @@ -196,12 +209,17 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(SolutionDir)AMMPED-UP\Dependencies\TGUI\include;$(SolutionDir)AMMPED-UP\Dependencies\json-3.11.2\include;$(SolutionDir)AMMPED-UP\Dependencies\SFML\include;D:\WorkSpace\VisualStudio2017\Projects\AbhayMore\Github\AMMPED-UP\AMMPED-UP\AMMPED-UP\Dependencies\mongo-cxx-driver-r3.7.1\include\mongocxx\v_noabi;D:\WorkSpace\VisualStudio2017\Projects\AbhayMore\Github\AMMPED-UP\AMMPED-UP\AMMPED-UP\Dependencies\mongo-cxx-driver-r3.7.1\include\bsoncxx\v_noabi;D:\WorkSpace\VisualStudio2017\Projects\AbhayMore\Github\AMMPED-UP\AMMPED-UP\AMMPED-UP\Dependencies\mongo-c-driver\include\libmongoc-1.0;D:\WorkSpace\VisualStudio2017\Projects\AbhayMore\Github\AMMPED-UP\AMMPED-UP\AMMPED-UP\Dependencies\mongo-c-driver\include\libbson-1.0;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp17</LanguageStandard>
<AdditionalOptions>/Zc:__cplusplus %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(SolutionDir)AMMPED-UP\Dependencies\TGUI\lib;$(SolutionDir)AMMPED-UP\Dependencies\SFML\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>sfml-system.lib;sfml-graphics.lib;sfml-audio.lib;sfml-window.lib;sfml-network.lib;tgui.lib;D:\WorkSpace\VisualStudio2017\Projects\AbhayMore\Github\AMMPED-UP\AMMPED-UP\AMMPED-UP\Dependencies\mongo-c-driver\lib\bson-1.0.lib;D:\WorkSpace\VisualStudio2017\Projects\AbhayMore\Github\AMMPED-UP\AMMPED-UP\AMMPED-UP\Dependencies\mongo-c-driver\lib\mongoc-1.0.lib;D:\WorkSpace\VisualStudio2017\Projects\AbhayMore\Github\AMMPED-UP\AMMPED-UP\AMMPED-UP\Dependencies\mongo-cxx-driver-r3.7.1\lib\bsoncxx.lib;D:\WorkSpace\VisualStudio2017\Projects\AbhayMore\Github\AMMPED-UP\AMMPED-UP\AMMPED-UP\Dependencies\mongo-cxx-driver-r3.7.1\lib\mongocxx.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
Expand Down
18 changes: 18 additions & 0 deletions AMMPED-UP/AMMPED-UP.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@
<ClCompile Include="Source\AudioManager.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Source\MongoDB.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Source\MongoInstanceManager.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Source\Config.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Header Files\Animation.h">
Expand Down Expand Up @@ -173,5 +182,14 @@
<ClInclude Include="Header Files\AudioManager.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Header Files\MongoDB.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Header Files\Config.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Header Files\MongoInstanceManager.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
15 changes: 7 additions & 8 deletions AMMPED-UP/Header Files/GameOver.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#pragma once
#include <fstream>
#include "SFML/Graphics/Text.hpp"
#include "SFML/Graphics/Sprite.hpp"
#include "SFML/Audio/Sound.hpp"
#include "nlohmann/json.hpp"
#include "MongoDB.h"
#include "MongoInstanceManager.h"
#include "State.h"
#include "Game.h"
#include "ScoreManager.h"
Expand Down Expand Up @@ -37,11 +37,11 @@ class GameOver : public am::State

//FILE SYSTEM FOR SCORE SAVING
UserNameManager* m_userName;
std::ifstream inputFile;
std::ofstream outputFile;
nlohmann::json jsonFile;
bool isInputFileEmpty = false;
bool foundPlayerData = false;


//MONGODB
mongocxx::instance& instance;
learning::MongoDB m;

public:
GameOver(std::shared_ptr<Context>& context, std::string currentState);
Expand All @@ -53,5 +53,4 @@ class GameOver : public am::State
void draw() override;
void start() override;

void writeToFile();
};
18 changes: 10 additions & 8 deletions AMMPED-UP/Header Files/LeaderBoard.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once
#include <memory>
#include <fstream>
#include "SFML/Graphics/Sprite.hpp"
#include "nlohmann/json.hpp"
#include "MongoDB.h"
#include "MongoInstanceManager.h"

#include "SFML/Graphics/Text.hpp"
#include "State.h"
Expand All @@ -26,13 +26,15 @@ class Leaderboard : public am::State

UserNameManager* username;

//TOP PLAYERS
sf::Text m_TopTenPlayerNames[10];
sf::Text m_TopTenPlayerScores[10];

std::ifstream inputFile;
std::ofstream outputFile;
nlohmann::json jsonFile;
bool isInputFileEmpty = false;
bool foundPlayerData = false;

//MONGODB
mongocxx::instance& instance;
learning::MongoDB m;
std::vector<std::pair<std::string, int>> m_TopTenScores;
public:
Leaderboard(std::shared_ptr<Context>& context);
~Leaderboard();
Expand All @@ -45,6 +47,6 @@ class Leaderboard : public am::State
void start();
void pause();

void writeToFile();

};

28 changes: 7 additions & 21 deletions AMMPED-UP/Header Files/LoginPageState.h
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
#pragma once
#include "SFML/Graphics/Sprite.hpp"
#include <fstream>
#include "SFML/Graphics/Text.hpp"
#include "State.h"
#include "Game.h"
#include "Button.h"
#include "TextBox.h"
#include "UserNameManager.h"
#include "nlohmann/json.hpp"

struct account
{
std::string email;
std::string password;
};

struct loginInfo
{
bool email = false;
bool password = false;
};
#include "MongoInstanceManager.h"
#include "MongoDB.h"

class LoginPageState : public am::State
{
Expand All @@ -36,26 +24,25 @@ class LoginPageState : public am::State

//TEXTBOXES
Textbox m_allTextBoxes[2]; //Username, EmailID, Password

sf::Text m_errorPrompt;


//SIGN IN BUTTON
Button m_signInButton;
Button m_backButton;

bool m_isSignInButtonPressed = false;
bool m_isBackButtonPressed = false;
//FILE SYSTEM
std::ifstream inputFile;
std::ofstream outputFile;
bool fileEmpty = false;
nlohmann::json jsonFile;


bool verified = false;

UserNameManager* m_username;

//MONGODB
mongocxx::instance& instance;
learning::MongoDB m;

public:
LoginPageState(std::shared_ptr<Context>& context);
~LoginPageState();
Expand All @@ -68,5 +55,4 @@ class LoginPageState : public am::State
void start();
void pause();

void writeToFile();
};
36 changes: 36 additions & 0 deletions AMMPED-UP/Header Files/MongoDB.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#pragma once

#include <cstdint>
#include <string>
#include <iostream>
#include "../Header Files/Config.h"

#include "bsoncxx/builder/stream/document.hpp"
#include "bsoncxx/json.hpp"
#include "bsoncxx/oid.hpp"
#include "mongocxx/client.hpp"
#include "mongocxx/database.hpp"
#include "mongocxx/uri.hpp"
#include <mongocxx/exception/operation_exception.hpp>

namespace learning {
const mongocxx::uri mongoURI(mongodb_uri);
const std::string dbName = databaseName;
const std::string collName = colectionName;
class MongoDB {
public:
MongoDB();
void insertDocument(const bsoncxx::document::value document);
std::tuple<std::string, std::string, std::string> findDocument(const std::string& value);
bool isDataPresent(const std::string& key, const std::string& value);
int findScore(const std::string& value);
void updateDocument(const std::string& key, const int& value, const std::string& newKey, const int& newValue);
std::vector<std::pair<std::string, int>> getTopScores(int limit);
private:
mongocxx::options::client client_options;
mongocxx::options::server_api api;
mongocxx::client conn;
mongocxx::v_noabi::database ammpedUPDB;
mongocxx::v_noabi::collection loginInfoCollection;
};
}
12 changes: 12 additions & 0 deletions AMMPED-UP/Header Files/MongoInstanceManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once
#include <mongocxx/instance.hpp>

class MongoInstance {
private:
static mongocxx::instance instance; // Private static member variable

public:
static mongocxx::instance& getInstance() {
return instance;
}
};
15 changes: 7 additions & 8 deletions AMMPED-UP/Header Files/OptionsState.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#pragma once
#include <memory>
#include <fstream>
#include "SFML/Graphics/Sprite.hpp"
#include "TGUI/TGUI.hpp"
#include "SFML/Graphics/Text.hpp"
#include "State.h"
#include "Game.h"
#include "AudioManager.h"
#include "UsernameManager.h"
#include "nlohmann/json.hpp"
#include "MongoDB.h"
#include "MongoInstanceManager.h"
#include "TGUI/TGUI.hpp"

class OptionsState : public am::State
Expand Down Expand Up @@ -50,13 +50,13 @@ class OptionsState : public am::State

//Reset Highscore
UserNameManager* username;
std::ifstream inputFile;
std::ofstream outputFile;
nlohmann::json jsonFile;
bool isInputFileEmpty = false;
bool foundPlayerData = false;

sf::Time m_elapsedTime;

//MONGODB
mongocxx::instance& instance;
learning::MongoDB m;

public:
OptionsState(std::shared_ptr<Context>& context);
~OptionsState();
Expand All @@ -69,6 +69,5 @@ class OptionsState : public am::State
void start();
void pause();

void writeToFile();
};

Loading

0 comments on commit 9a86f3d

Please sign in to comment.