| @ -0,0 +1 @@ | |||
| GKSK{H0w_d1d_I_n0t_real1ze_such_4_s7up1d_m1sT4k3} | |||
| @ -1,58 +0,0 @@ | |||
| #include "src/class/player.hpp" | |||
| #include "src/interface/creation.hpp" | |||
| #include "src/interface/info.hpp" | |||
| #include "src/system/betatest.hpp" | |||
| #include <iostream> | |||
| int main(int argc, char const *argv[]) | |||
| { | |||
| Player *player = nullptr; | |||
| if (checkBetaTest()) | |||
| { | |||
| int choice; | |||
| do | |||
| { | |||
| printf("===== HackTheGame v0.0.1 (Beta) =====\n"); | |||
| printf("[1] Create new Character\n"); | |||
| printf("[2] Character Info\n"); | |||
| printf("[9] Credits\n"); | |||
| printf("[0] Exit\n"); | |||
| printf(">"); | |||
| scanf("%d", &choice); | |||
| switch (choice) | |||
| { | |||
| case 1: | |||
| player = createCharacter(); | |||
| break; | |||
| case 2: | |||
| if (player == nullptr) | |||
| { | |||
| std::cout << "Please create a character first!" << std::endl; | |||
| } | |||
| else | |||
| { | |||
| Info::ofPlayer(player); | |||
| } | |||
| break; | |||
| case 9: | |||
| Info::ofApplication(); | |||
| break; | |||
| case 0: | |||
| break; | |||
| default: | |||
| printf("Not Implemented...\n"); | |||
| } | |||
| } while (choice != 0); | |||
| } | |||
| else | |||
| { | |||
| printf("Please get a beta.test key from one of our developer to get access to beta test...\n"); | |||
| return 0; | |||
| } | |||
| } | |||
| @ -0,0 +1,135 @@ | |||
| #include "src/class/player.hpp" | |||
| #include "src/class/monster.hpp" | |||
| #include "src/interface/battle.hpp" | |||
| #include "src/interface/creation.hpp" | |||
| #include "src/interface/info.hpp" | |||
| #include "src/system/betatest.hpp" | |||
| #include "src/system/memory.hpp" | |||
| #include "src/system/flag.hpp" | |||
| #include <iostream> | |||
| void printMenu(); | |||
| void printMenu() | |||
| { | |||
| printf("===== HackTheGame v0.0.1 (Beta) =====\n"); | |||
| printf("[1] Create new Character\n"); | |||
| printf("[2] Character Info\n"); | |||
| printf("[9] Credits\n"); | |||
| printf("[0] Exit\n"); | |||
| printf(">"); | |||
| } | |||
| int main(int argc, char const *argv[]) | |||
| { | |||
| Player *player; | |||
| Monster *enemy; | |||
| std::cout << "This game is still in closed beta\n" | |||
| << "Please input your beta test code\n" | |||
| << ">" << std::flush; | |||
| std::string betaCode; | |||
| std::cin >> betaCode; | |||
| if (BetaTest::check(betaCode)) | |||
| { | |||
| std::cout << "Welcome back tester!\n" | |||
| << "do you have your character backup code?\n" | |||
| << "[y/N] " << std::flush; | |||
| char choice = 'n'; | |||
| std::cin >> choice; | |||
| if (choice == 'Y' || choice == 'y') | |||
| { | |||
| std::cout << "Please input your backup code\n" | |||
| << "> " << std::flush; | |||
| std::string code; | |||
| std::cin >> code; | |||
| player = Memory::loadFromCode(code); | |||
| if (player == nullptr) | |||
| { | |||
| std::cout << "Your backup code is invalid, please try again..." << std::endl; | |||
| return 1; | |||
| } | |||
| } | |||
| else | |||
| { | |||
| player = Creation::ofPlayer(); | |||
| } | |||
| do | |||
| { | |||
| std::cout << "====== HackTheGame v0.0.2 (Closed Beta) =====\n" | |||
| << "[1] Character Info\n" | |||
| << "[2] Hunt Monster\n" | |||
| << "[3] Fight Boss\n" | |||
| << "[4] Rest\n" | |||
| << "[9] Credits\n" | |||
| << "[0] Exit\n" | |||
| << ">" << std::flush; | |||
| choice = '0'; | |||
| std::cin >> choice; | |||
| switch (choice) | |||
| { | |||
| case '1': | |||
| Info::ofPlayer(player); | |||
| break; | |||
| case '2': | |||
| enemy = Creation::ofMonster(); | |||
| if (enemy != nullptr) | |||
| { | |||
| Battle::Start(player, enemy); | |||
| if (Battle::Lose()) | |||
| { | |||
| std::cout << "GAME OVER !!!!" << std::endl; | |||
| return 0; | |||
| } | |||
| } | |||
| break; | |||
| case '3': | |||
| enemy = Creation::ofBoss(); | |||
| if (enemy != nullptr) | |||
| { | |||
| Battle::Start(player, enemy); | |||
| if (Battle::Won()) | |||
| { | |||
| Flag::Print(); | |||
| } | |||
| else | |||
| { | |||
| std::cout << "GAME OVER !!!!" << std::endl; | |||
| return 0; | |||
| } | |||
| } | |||
| break; | |||
| case '4': | |||
| std::cout << "You take a rest at nearby Inn...\n" | |||
| << "You wrote your journey to a diary in some cryptic language...\n" | |||
| << Memory::saveToCode(player) << "\n" | |||
| << "You woke up feeling resfreshed...\n" | |||
| << std::flush; | |||
| player->restoreHP(); | |||
| break; | |||
| case '9': | |||
| Info::ofApplication(); | |||
| break; | |||
| case '0': | |||
| return 0; | |||
| break; | |||
| default: | |||
| printf("Not Implemented...\n"); | |||
| } | |||
| } while (choice != 0); | |||
| } | |||
| else | |||
| { | |||
| std::cout << "Invalid code, exiting..." << std::endl; | |||
| return 0; | |||
| } | |||
| } | |||
| @ -0,0 +1,89 @@ | |||
| #include "src/interface/battle.hpp" | |||
| #include <iostream> | |||
| #include <unistd.h> | |||
| bool Battle::win = false; | |||
| bool Battle::Won() | |||
| { | |||
| return win; | |||
| } | |||
| bool Battle::Lose() | |||
| { | |||
| return !win; | |||
| } | |||
| void Battle::Start(Player *player, Monster *monster) | |||
| { | |||
| std::cout << " ===== BATTLE INFO ===== \n" | |||
| << player->getName() << " Lv." << player->getLevel() << ":\n" | |||
| << " HP : " << player->getCurrentHP() << "/" << player->getMaxHP() << "\n" | |||
| << " Atk : " << player->getAtk() << "\n" | |||
| << " Def : " << player->getDef() << "\n" | |||
| << " VS \n" | |||
| << monster->getName() << "\n" | |||
| << " HP : " << monster->getCurrentHP() << "/" << monster->getMaxHP() << "\n" | |||
| << " Atk : " << monster->getAtk() << "\n" | |||
| << " Def : " << monster->getDef() << "\n" | |||
| << " Drop: " << monster->getBounty() << "\n" | |||
| << std::endl; | |||
| std::cout << " ===== BATTLE START ===== " << std::endl; | |||
| while (player->isAlive() && monster->isAlive()) | |||
| { | |||
| std::cout << player->getName() << " attacked " << monster->getName() << "!" << std::endl; | |||
| usleep(200000); | |||
| int monsterDmg = monster->defend(player->getAtk()); | |||
| if (monsterDmg > 0) | |||
| { | |||
| std::cout << monster->getName() << " got hit by " << monsterDmg << " points!" << std::endl; | |||
| } | |||
| else | |||
| { | |||
| std::cout << monster->getName() << " blocked the attack!" << std::endl; | |||
| } | |||
| usleep(200000); | |||
| if (monster->isAlive()) | |||
| { | |||
| std::cout << monster->getName() << " attacked " << player->getName() << "!" << std::endl; | |||
| usleep(200000); | |||
| int playerDmg = player->defend(monster->getAtk()); | |||
| if (playerDmg > 0) | |||
| { | |||
| std::cout << player->getName() << " got hit by " << playerDmg << " points!" << std::endl; | |||
| } | |||
| else | |||
| { | |||
| std::cout << player->getName() << " blocked the attack!" << std::endl; | |||
| } | |||
| usleep(200000); | |||
| } | |||
| } | |||
| if (player->isAlive()) | |||
| { | |||
| std::cout << "YOU WIN !!!\n" | |||
| << "Got " << monster->getBounty() << " points of experience.\n" | |||
| << std::flush; | |||
| player->takeExperience(monster->getBounty()); | |||
| if (player->checkLevelup()) | |||
| { | |||
| std::cout << "You leveled up!" << std::endl; | |||
| player->levelUp(); | |||
| } | |||
| else | |||
| { | |||
| std::cout << player->expToLevelUp() << " points left to level up.\n" | |||
| << std::flush; | |||
| } | |||
| win = true; | |||
| } | |||
| else | |||
| { | |||
| std::cout << "YOU LOSE !!!!!" << std::endl; | |||
| win = false; | |||
| } | |||
| } | |||
| @ -0,0 +1,18 @@ | |||
| #ifndef HACKTHEGAME_BATTLESYSTEM_VERSION_000_HPP | |||
| #define HACKTHEGAME_BATTLESYSTEM_VERSION_000_HPP | |||
| #include "src/class/monster.hpp" | |||
| #include "src/class/player.hpp" | |||
| class Battle | |||
| { | |||
| private: | |||
| static bool win; | |||
| public: | |||
| static bool Won(); | |||
| static bool Lose(); | |||
| static void Start(Player *player, Monster *monster); | |||
| }; | |||
| #endif | |||
| @ -1,37 +0,0 @@ | |||
| #include "src/interface/battle0.hpp" | |||
| int startBattle(Player *player, Monster *monster) | |||
| { | |||
| printf(" ===== BATTLE INFO ===== \n"); | |||
| printf("%15s (Lv.%n):\n", player->getName(), player->getLevel()); | |||
| printf(" HP : %n/%n\n", player->getCurrentHP(), player->getMaxHP()); | |||
| printf(" Att: %n\n", player->getAtt()); | |||
| printf(" Def: %n\n", player->getDef()); | |||
| printf("%15s:\n", monster->getName()); | |||
| printf(" HP : %n/%n\n", monster->getCurrentHP(), monster->getMaxHP()); | |||
| printf(" Att: %n\n", monster->getAtt()); | |||
| printf(" Def: %n\n", monster->getDef()); | |||
| printf(" ===== BATTLE START ===== \n"); | |||
| while (player->isAlive() && monster->isAlive()) | |||
| { | |||
| printf("%15s and %15s attacked each other !!!\n", player->getName(), monster->getName()); | |||
| printf("%15s lose %d HP...\n", player->getName(), player->defend(monster->getAtt())); | |||
| printf("%15s lose %d HP...\n", monster->getName(), monster->defend(player->getAtt())); | |||
| } | |||
| printf(" ===== BATTLE END ===== \n"); | |||
| if (player->isAlive()) | |||
| { | |||
| player->restoreHP(); | |||
| printf("YOU WIN !!!\n"); | |||
| return 1; | |||
| } | |||
| else | |||
| { | |||
| printf("YOU LOSE !!!\n"); | |||
| return 0; | |||
| } | |||
| } | |||
| @ -1,11 +0,0 @@ | |||
| #ifndef HACKTHEGAME_BATTLESYSTEM_VERSION_000_HPP | |||
| #define HACKTHEGAME_BATTLESYSTEM_VERSION_000_HPP | |||
| #include "src/class/monster.hpp" | |||
| #include "src/class/player.hpp" | |||
| #include <cstdio> | |||
| int startBattle(Player *player, Monster *monster); | |||
| #endif | |||
| @ -1,29 +1,9 @@ | |||
| #include "src/system/betatest.hpp" | |||
| #include <fstream> | |||
| #include <string> | |||
| bool checkBetaTest() | |||
| { | |||
| std::string betaFlag = "4re_Y0u_53ri0usly_checking_f0r_b3t4_t3sT?"; | |||
| std::string tmp; | |||
| int result = -1; | |||
| try | |||
| { | |||
| std::fstream betaFile("beta.test"); | |||
| if (betaFile) { | |||
| betaFile >> tmp; | |||
| std::string BetaTest::betaFlag = "4re_Y0u_53ri0usly_checking_f0r_b3t4_t3sT?"; | |||
| result = tmp.compare("GKSK{" + betaFlag + "}"); | |||
| } | |||
| } | |||
| catch(...) | |||
| { | |||
| return false; | |||
| } | |||
| return result == 0; | |||
| bool BetaTest::check(std::string input) | |||
| { | |||
| return input.compare("GKSK{" + betaFlag + "}") == 0; | |||
| } | |||
| @ -1,6 +1,15 @@ | |||
| #ifndef HACKTHEGAME_BETATEST_HPP | |||
| #define HACKTHEGAME_BETATEST_HPP | |||
| bool checkBetaTest(); | |||
| #include <string> | |||
| class BetaTest | |||
| { | |||
| private: | |||
| static std::string betaFlag; | |||
| public: | |||
| static bool check(std::string input); | |||
| }; | |||
| #endif | |||
| @ -0,0 +1,34 @@ | |||
| #include "flag.hpp" | |||
| #include <fstream> | |||
| #include <iostream> | |||
| std::string Flag::flag = ""; | |||
| bool Flag::Load() | |||
| { | |||
| std::ifstream file("flag.txt"); | |||
| if (file.good()) | |||
| { | |||
| file >> flag; | |||
| return true; | |||
| } | |||
| else | |||
| { | |||
| return false; | |||
| } | |||
| } | |||
| void Flag::Print() | |||
| { | |||
| if (Load()) | |||
| { | |||
| std::cout << flag << std::endl; | |||
| } | |||
| else | |||
| { | |||
| std::cout << "Something went wrong on the server\n" | |||
| << "Please contact the administrator...\n" | |||
| << std::endl; | |||
| } | |||
| } | |||
| @ -0,0 +1,16 @@ | |||
| #ifndef FLAG_HACKTHEGAME_HPP | |||
| #define FLAG_HACKTHEGAME_HPP | |||
| #include <string> | |||
| class Flag | |||
| { | |||
| private: | |||
| static std::string flag; | |||
| static bool Load(); | |||
| public: | |||
| static void Print(); | |||
| }; | |||
| #endif | |||
| @ -0,0 +1,53 @@ | |||
| #include "memory.hpp" | |||
| #include "cpp-base64/base64.h" | |||
| #include <string> | |||
| #include <cstring> | |||
| Player *Memory::loadFromCode(std::string code) | |||
| { | |||
| code = base64_decode(code); | |||
| char playerName[16] = {0}; | |||
| int playerHP = 0; | |||
| int playerAtk = 0; | |||
| int playerDef = 0; | |||
| int playerLevel = 0; | |||
| int playerExp = 0; | |||
| int result = sscanf(code.c_str(), | |||
| "PlayerLevel=%d;PlayerExp=%d;PlayerHP=%d;PlayerAtk=%d;PlayerDef=%d;PlayerName=%15s", | |||
| &playerLevel, | |||
| &playerExp, | |||
| &playerHP, | |||
| &playerAtk, | |||
| &playerDef, | |||
| playerName); | |||
| std::string playerTrueName = playerName; | |||
| if (result == 6) | |||
| { | |||
| return new Player(playerTrueName, playerHP, playerAtk, playerDef, playerLevel, playerExp); | |||
| } | |||
| else | |||
| { | |||
| return nullptr; | |||
| } | |||
| } | |||
| std::string Memory::saveToCode(Player *player) | |||
| { | |||
| char code[256]; | |||
| snprintf(code, sizeof(code), | |||
| "PlayerLevel=%d;PlayerExp=%d;PlayerHP=%d;PlayerAtk=%d;PlayerDef=%d;PlayerName=%s", | |||
| player->getLevel(), | |||
| player->getExp(), | |||
| player->getMaxHP(), | |||
| player->getAtk(), | |||
| player->getDef(), | |||
| player->getName().c_str()); | |||
| return base64_encode(reinterpret_cast<unsigned char *>(code), | |||
| strlen(code)); | |||
| } | |||
| @ -0,0 +1,14 @@ | |||
| #ifndef HACKTHEGAME_SAVELOAD_HPP | |||
| #define HACKTHEGAME_SAVELOAD_HPP | |||
| #include "src/class/player.hpp" | |||
| #include <fstream> | |||
| class Memory | |||
| { | |||
| public: | |||
| static Player *loadFromCode(std::string); | |||
| static std::string saveToCode(Player *); | |||
| }; | |||
| #endif | |||