Browse Source

finally got it working

master
myitinos 6 years ago
parent
commit
cf04b19940
20 changed files with 515 additions and 190 deletions
  1. +21
    -8
      Makefile
  2. +1
    -0
      flag.txt
  3. +0
    -58
      main001.cpp
  4. +135
    -0
      main002.cpp
  5. +6
    -23
      src/class/player.cpp
  6. +1
    -1
      src/class/player.hpp
  7. +89
    -0
      src/interface/battle.cpp
  8. +18
    -0
      src/interface/battle.hpp
  9. +0
    -37
      src/interface/battle0.cpp
  10. +0
    -11
      src/interface/battle0.hpp
  11. +102
    -22
      src/interface/creation.cpp
  12. +7
    -1
      src/interface/creation.hpp
  13. +4
    -4
      src/interface/info.cpp
  14. +4
    -24
      src/system/betatest.cpp
  15. +10
    -1
      src/system/betatest.hpp
  16. +34
    -0
      src/system/flag.cpp
  17. +16
    -0
      src/system/flag.hpp
  18. +53
    -0
      src/system/memory.cpp
  19. +14
    -0
      src/system/memory.hpp
  20. BIN
      version002

+ 21
- 8
Makefile View File

@ -1,7 +1,7 @@
COMPILER=g++
#FLAGS=-g -I. -pedantic -Wall -Wextra -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wformat=2 -Winit-self -Wlogical-op -Wmissing-declarations -Wmissing-include-dirs -Wnoexcept -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-conversion -Wsign-promo -Wstrict-null-sentinel -Wstrict-overflow=5 -Wswitch-default -Wundef -Werror -Wno-unused
FLAGS=-g -I. -pedantic -Wall -Wextra -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wformat="o">=2 -Winit-self -Wlogical-op -Wmissing-declarations -Wmissing-include-dirs -Wnoexcept -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-conversion -Wsign-promo -Wstrict-null-sentinel -Wstrict-overflow="o">=5 -Wswitch-default -Wundef -Werror -Wno-unused
#FLAGS=-g -I.
FLAGS=-I.
#FLAGS=-I.
O_DIR=obj
CLASS_DIR=src/class
@ -12,14 +12,15 @@ OBJ_CMD=$(COMPILER) $(FLAGS) -c $< -o $@
.PHONY : clean
version001 : main001.o character.o player.o monster.o creation.o info.o betatest.o
version002 : main002.o character.o player.o monster.o battle.o creation.o info.o betatest.o memory.o flag.o base64.o
$(COMPILER) $(FLAGS) -o $@ \
main001.o \
character.o player.o monster.o \
info.o creation.o \
betatest.o
main002.o \
character.o player.o monster.o \
info.o creation.o battle.o \
betatest.o flag.o memory.o \
base64.o
main001.o : main001.cpp $(CLASS_DIR)/player.hpp $(INTER_DIR)/creation.hpp $(INTER_DIR)/info.hpp $(SYS_DIR)/betatest.hpp
main002.o : main002.cpp $(CLASS_DIR)/player.hpp $(INTER_DIR)/creation.hpp $(INTER_DIR)/info.hpp $(SYS_DIR)/betatest.hpp
$(OBJ_CMD)
character.o : $(CLASS_DIR)/character.cpp $(CLASS_DIR)/character.hpp
@ -31,6 +32,9 @@ player.o : $(CLASS_DIR)/player.cpp $(CLASS_DIR)/player.hpp $(CLASS_DIR)/characte
monster.o : $(CLASS_DIR)/monster.cpp $(CLASS_DIR)/monster.hpp $(CLASS_DIR)/character.hpp
$(OBJ_CMD)
battle.o : $(INTER_DIR)/battle.cpp $(INTER_DIR)/battle.hpp $(CLASS_DIR)/monster.hpp $(CLASS_DIR)/character.hpp
$(OBJ_CMD)
creation.o : $(INTER_DIR)/creation.cpp $(INTER_DIR)/creation.hpp $(CLASS_DIR)/player.hpp $(INTER_DIR)/info.hpp
$(OBJ_CMD)
@ -40,5 +44,14 @@ info.o : $(INTER_DIR)/info.cpp $(INTER_DIR)/info.hpp $(CLASS_DIR)/player.hpp $(C
betatest.o : $(SYS_DIR)/betatest.cpp $(SYS_DIR)/betatest.hpp
$(OBJ_CMD)
flag.o : $(SYS_DIR)/flag.cpp $(SYS_DIR)/flag.hpp
$(OBJ_CMD)
memory.o : $(SYS_DIR)/memory.cpp $(SYS_DIR)/memory.hpp $(CLASS_DIR)/player.hpp cpp-base64/base64.h
$(OBJ_CMD)
base64.o : cpp-base64/base64.cpp cpp-base64/base64.h
$(COMPILER) -I. -c $< -o $@
clean :
rm -f *.o

+ 1
- 0
flag.txt View File

@ -0,0 +1 @@
GKSK{H0w_d1d_I_n0t_real1ze_such_4_s7up1d_m1sT4k3}

+ 0
- 58
main001.cpp View File

@ -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;
}
}

+ 135
- 0
main002.cpp View File

@ -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;
}
}

+ 6
- 23
src/class/player.cpp View File

@ -40,32 +40,15 @@ int Player::expToLevelUp()
bool Player::checkLevelup()
{
return expToLevelUp() < 0;
return (expToLevelUp() <= 0 && level < PLAYER_MAX_LEVEL);
}
bool Player::levelUp(int stat)
void Player::levelUp()
{
if (checkLevelup())
{
switch (stat)
{
case 1:
maxHP += 10;
restoreHP();
break;
case 2:
atk += 2;
break;
case 3:
def += 1;
break;
}
return true;
}
else
{
return false;
}
level += 1;
maxHP += 10;
atk += 2;
def += 1;
}
int Player::takeExperience(int bounty)

+ 1
- 1
src/class/player.hpp View File

@ -22,7 +22,7 @@ class Player : public Character
int takeExperience(int drop);
bool checkLevelup();
bool levelUp(int stat);
void levelUp();
};
#endif

+ 89
- 0
src/interface/battle.cpp View File

@ -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;
}
}

+ 18
- 0
src/interface/battle.hpp View File

@ -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

+ 0
- 37
src/interface/battle0.cpp View File

@ -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;
}
}

+ 0
- 11
src/interface/battle0.hpp View File

@ -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

+ 102
- 22
src/interface/creation.cpp View File

@ -3,41 +3,121 @@
#include <iostream>
Player *createCharacter()
Player *Creation::ofPlayer()
{
std::string name;
std::cout << "=== Welcome to Character Creation ===\n"
<< std::flush;
char choice;
Player *newPlayer = new Player("HackTheGame");
std::cout << "Welcome to character creation !!!" << std::endl;
do
while (true)
{
std::cout << "Please enter your character name: (Max 15 letters)\n"
<< "> " << std::flush;
std::cout << "Please enter your character name below\n"
<< ">" << std::flush;
std::string name;
std::cin >> name;
if (name.size() > 15)
{
std::cout << "Your name is too long!" << std::endl;
std::cout << "Your character name is too long!\n"
<< std::flush;
continue;
}
else
{
std::cout << "Creating your character...\n"
<< std::flush;
Player *newPlayer = new Player(name);
Info::ofPlayer(newPlayer);
std::cout << "Accept? [Y/n] \n"
<< ">" << std::flush;
char choice = 'Y';
std::cin >> choice;
if (choice == 'Y' || choice == 'y')
{
return newPlayer;
}
}
}
}
std::cout << "Creating your character..." << std::endl;
Monster *Creation::ofMonster()
{
delete newPlayer;
newPlayer = new Player(name);
const Monster monsterDen[] = {
Monster("Slime", 10, 1, 0, 1),
Monster("Goblin", 30, 2, 1, 2),
Monster("Wolf", 50, 3, 1, 3),
Monster("Zombie", 100, 4, 0, 4),
Monster("Zombie Knight", 200, 10, 7, 5),
Monster("Baby Dragon", 500, 20, 15, 10),
Monster("Dragon", 1000, 50, 20, 20)};
while (true)
{
int count = 0;
std::cout << "=== Welcome to Hunting Ground ===\n"
<< std::flush;
std::cout << "Done...\n"
<< "Character Info: " << std::endl;
for (Monster monster : monsterDen)
{
std::cout << "[" << ++count << "] " << monster.getName() << std::endl;
}
Info::ofCharacter(newPlayer);
std::cout << "[0] Exit\n"
<< ">" << std::flush;
std::cout << "Accept (y/N)?: " << std::flush;
std::cin >> choice;
} while (choice != 'Y' && choice != 'y');
char input;
std::cin >> input;
return newPlayer;
if (input <= ('0' + count) && input > '0')
{
char decision = 'Y';
Monster *summoned = new Monster(monsterDen[input - '1']);
Info::ofMonster(summoned);
std::cout << "Fight this monster? [Y/n]" << std::endl;
std::cout << ">" << std::flush;
std::cin >> decision;
if (decision == 'y' || decision == 'Y')
{
return summoned;
}
else
{
continue;
}
}
else if (input == '0')
{
return nullptr;
}
else
{
std::cout << "Monster not found!" << std::endl;
continue;
}
}
}
Monster *Creation::ofBoss()
{
Monster *boss = new Monster("Flag Guardian", 987654321, 123456789, 123456789, 0);
std::cout << "You are gonna fight the final boss:\n" << std::flush;
Info::ofMonster(boss);
std::cout << "Are you sure? [Y/n]\n"
<< "> " << std::flush;
char choice = 'Y';
std::cin >> choice;
if (choice == 'Y' || choice == 'y')
{
return boss;
}
else
{
return nullptr;
}
}

+ 7
- 1
src/interface/creation.hpp View File

@ -4,6 +4,12 @@
#include "src/class/player.hpp"
#include "src/class/monster.hpp"
Player *createCharacter();
class Creation
{
public:
static Player *ofPlayer();
static Monster *ofMonster();
static Monster *ofBoss();
};
#endif

+ 4
- 4
src/interface/info.cpp View File

@ -24,10 +24,10 @@ void Info::ofPlayer(Player *player)
void Info::ofMonster(Monster *monster)
{
std::cout << "Name: " << monster->getName() << "\n"
<< " HP : " << monster->getCurrentHP() << "/" << monster->getMaxHP() << "\n"
<< " Atk: " << monster->getAtk() << "\n"
<< " Def: " << monster->getDef() << "\n"
<< " Lvl: " << monster->getBounty() << std::endl;
<< " HP : " << monster->getCurrentHP() << "/" << monster->getMaxHP() << "\n"
<< " Atk : " << monster->getAtk() << "\n"
<< " Def : " << monster->getDef() << "\n"
<< " Drop: " << monster->getBounty() << std::endl;
}
void Info::ofApplication()

+ 4
- 24
src/system/betatest.cpp View File

@ -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;
}

+ 10
- 1
src/system/betatest.hpp View File

@ -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

+ 34
- 0
src/system/flag.cpp View File

@ -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;
}
}

+ 16
- 0
src/system/flag.hpp View File

@ -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

+ 53
- 0
src/system/memory.cpp View File

@ -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));
}

+ 14
- 0
src/system/memory.hpp View File

@ -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

BIN
version002 View File


Loading…
Cancel
Save