Browse Source

finally got it working

pull/1/head
myitinos 1 year ago
parent
commit
cf04b19940

+ 21
- 8
Makefile View File

@@ -1,7 +1,7 @@
1 1
 COMPILER=g++
2
-#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
2
+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
3 3
 #FLAGS=-g -I.
4
-FLAGS=-I.
4
+#FLAGS=-I.
5 5
 O_DIR=obj
6 6
 
7 7
 CLASS_DIR=src/class
@@ -12,14 +12,15 @@ OBJ_CMD=$(COMPILER) $(FLAGS) -c $< -o $@
12 12
 
13 13
 .PHONY : clean
14 14
 
15
-version001 : main001.o character.o player.o monster.o creation.o info.o betatest.o
15
+version002 : main002.o character.o player.o monster.o battle.o creation.o info.o betatest.o memory.o flag.o base64.o
16 16
 	$(COMPILER) $(FLAGS) -o $@ \
17
-		main001.o \
18
-		character.o player.o   monster.o \
19
-		info.o      creation.o \
20
-		betatest.o
17
+		main002.o \
18
+		character.o player.o monster.o \
19
+		info.o creation.o battle.o \
20
+		betatest.o flag.o memory.o \
21
+		base64.o
21 22
 
22
-main001.o : main001.cpp $(CLASS_DIR)/player.hpp $(INTER_DIR)/creation.hpp $(INTER_DIR)/info.hpp $(SYS_DIR)/betatest.hpp 
23
+main002.o : main002.cpp $(CLASS_DIR)/player.hpp $(INTER_DIR)/creation.hpp $(INTER_DIR)/info.hpp $(SYS_DIR)/betatest.hpp 
23 24
 	$(OBJ_CMD)
24 25
 
25 26
 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
31 32
 monster.o : $(CLASS_DIR)/monster.cpp $(CLASS_DIR)/monster.hpp $(CLASS_DIR)/character.hpp
32 33
 	$(OBJ_CMD)
33 34
 
35
+battle.o : $(INTER_DIR)/battle.cpp $(INTER_DIR)/battle.hpp $(CLASS_DIR)/monster.hpp $(CLASS_DIR)/character.hpp
36
+	$(OBJ_CMD)
37
+
34 38
 creation.o : $(INTER_DIR)/creation.cpp $(INTER_DIR)/creation.hpp $(CLASS_DIR)/player.hpp $(INTER_DIR)/info.hpp
35 39
 	$(OBJ_CMD)
36 40
 
@@ -40,5 +44,14 @@ info.o : $(INTER_DIR)/info.cpp $(INTER_DIR)/info.hpp $(CLASS_DIR)/player.hpp $(C
40 44
 betatest.o : $(SYS_DIR)/betatest.cpp $(SYS_DIR)/betatest.hpp
41 45
 	$(OBJ_CMD)
42 46
 
47
+flag.o : $(SYS_DIR)/flag.cpp $(SYS_DIR)/flag.hpp
48
+	$(OBJ_CMD)
49
+
50
+memory.o : $(SYS_DIR)/memory.cpp $(SYS_DIR)/memory.hpp $(CLASS_DIR)/player.hpp cpp-base64/base64.h
51
+	$(OBJ_CMD)
52
+
53
+base64.o : cpp-base64/base64.cpp cpp-base64/base64.h
54
+	$(COMPILER) -I. -c $< -o $@
55
+
43 56
 clean :
44 57
 	rm -f *.o

+ 1
- 0
flag.txt View File

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

+ 0
- 58
main001.cpp View File

@@ -1,58 +0,0 @@
1
-#include "src/class/player.hpp"
2
-#include "src/interface/creation.hpp"
3
-#include "src/interface/info.hpp"
4
-#include "src/system/betatest.hpp"
5
-
6
-#include <iostream>
7
-
8
-int main(int argc, char const *argv[])
9
-{
10
-    Player *player = nullptr;
11
-
12
-    if (checkBetaTest())
13
-    {
14
-        int choice;
15
-
16
-        do
17
-        {
18
-            printf("===== HackTheGame v0.0.1 (Beta) =====\n");
19
-            printf("[1] Create new Character\n");
20
-            printf("[2] Character Info\n");
21
-            printf("[9] Credits\n");
22
-            printf("[0] Exit\n");
23
-            printf(">");
24
-
25
-            scanf("%d", &choice);
26
-
27
-            switch (choice)
28
-            {
29
-            case 1:
30
-                player = createCharacter();
31
-                break;
32
-            case 2:
33
-                if (player == nullptr)
34
-                {
35
-                    std::cout << "Please create a character first!" << std::endl;
36
-                }
37
-                else
38
-                {
39
-                    Info::ofPlayer(player);
40
-                }
41
-                break;
42
-            case 9:
43
-                Info::ofApplication();
44
-                break;
45
-            case 0:
46
-                break;
47
-            default:
48
-                printf("Not Implemented...\n");
49
-            }
50
-
51
-        } while (choice != 0);
52
-    }
53
-    else
54
-    {
55
-        printf("Please get a beta.test key from one of our developer to get access to beta test...\n");
56
-        return 0;
57
-    }
58
-}

+ 135
- 0
main002.cpp View File

@@ -0,0 +1,135 @@
1
+#include "src/class/player.hpp"
2
+#include "src/class/monster.hpp"
3
+#include "src/interface/battle.hpp"
4
+#include "src/interface/creation.hpp"
5
+#include "src/interface/info.hpp"
6
+#include "src/system/betatest.hpp"
7
+#include "src/system/memory.hpp"
8
+#include "src/system/flag.hpp"
9
+
10
+#include <iostream>
11
+
12
+void printMenu();
13
+
14
+void printMenu()
15
+{
16
+    printf("===== HackTheGame v0.0.1 (Beta) =====\n");
17
+    printf("[1] Create new Character\n");
18
+    printf("[2] Character Info\n");
19
+    printf("[9] Credits\n");
20
+    printf("[0] Exit\n");
21
+    printf(">");
22
+}
23
+
24
+int main(int argc, char const *argv[])
25
+{
26
+    Player *player;
27
+    Monster *enemy;
28
+    std::cout << "This game is still in closed beta\n"
29
+              << "Please input your beta test code\n"
30
+              << ">" << std::flush;
31
+
32
+    std::string betaCode;
33
+    std::cin >> betaCode;
34
+
35
+    if (BetaTest::check(betaCode))
36
+    {
37
+        std::cout << "Welcome back tester!\n"
38
+                  << "do you have your character backup code?\n"
39
+                  << "[y/N] " << std::flush;
40
+
41
+        char choice = 'n';
42
+        std::cin >> choice;
43
+
44
+        if (choice == 'Y' || choice == 'y')
45
+        {
46
+            std::cout << "Please input your backup code\n"
47
+                      << "> " << std::flush;
48
+
49
+            std::string code;
50
+            std::cin >> code;
51
+
52
+            player = Memory::loadFromCode(code);
53
+            if (player == nullptr)
54
+            {
55
+                std::cout << "Your backup code is invalid, please try again..." << std::endl;
56
+                return 1;
57
+            }
58
+        }
59
+        else
60
+        {
61
+            player = Creation::ofPlayer();
62
+        }
63
+
64
+        do
65
+        {
66
+            std::cout << "====== HackTheGame v0.0.2 (Closed Beta) =====\n"
67
+                      << "[1] Character Info\n"
68
+                      << "[2] Hunt Monster\n"
69
+                      << "[3] Fight Boss\n"
70
+                      << "[4] Rest\n"
71
+                      << "[9] Credits\n"
72
+                      << "[0] Exit\n"
73
+                      << ">" << std::flush;
74
+
75
+            choice = '0';
76
+            std::cin >> choice;
77
+            switch (choice)
78
+            {
79
+            case '1':
80
+                Info::ofPlayer(player);
81
+                break;
82
+            case '2':
83
+                enemy = Creation::ofMonster();
84
+                if (enemy != nullptr)
85
+                {
86
+                    Battle::Start(player, enemy);
87
+                    if (Battle::Lose())
88
+                    {
89
+                        std::cout << "GAME OVER !!!!" << std::endl;
90
+                        return 0;
91
+                    }
92
+                }
93
+                break;
94
+            case '3':
95
+                enemy = Creation::ofBoss();
96
+                if (enemy != nullptr)
97
+                {
98
+                    Battle::Start(player, enemy);
99
+                    if (Battle::Won())
100
+                    {
101
+                        Flag::Print();
102
+                    }
103
+                    else
104
+                    {
105
+                        std::cout << "GAME OVER !!!!" << std::endl;
106
+                        return 0;
107
+                    }
108
+                }
109
+                break;
110
+            case '4':
111
+                std::cout << "You take a rest at nearby Inn...\n"
112
+                          << "You wrote your journey to a diary in some cryptic language...\n"
113
+                          << Memory::saveToCode(player) << "\n"
114
+                          << "You woke up feeling resfreshed...\n"
115
+                          << std::flush;
116
+                player->restoreHP();
117
+                break;
118
+            case '9':
119
+                Info::ofApplication();
120
+                break;
121
+            case '0':
122
+                return 0;
123
+                break;
124
+            default:
125
+                printf("Not Implemented...\n");
126
+            }
127
+
128
+        } while (choice != 0);
129
+    }
130
+    else
131
+    {
132
+        std::cout << "Invalid code, exiting..." << std::endl;
133
+        return 0;
134
+    }
135
+}

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

@@ -40,32 +40,15 @@ int Player::expToLevelUp()
40 40
 
41 41
 bool Player::checkLevelup()
42 42
 {
43
-    return expToLevelUp() < 0;
43
+    return (expToLevelUp() <= 0 && level < PLAYER_MAX_LEVEL);
44 44
 }
45 45
 
46
-bool Player::levelUp(int stat)
46
+void Player::levelUp()
47 47
 {
48
-    if (checkLevelup())
49
-    {
50
-        switch (stat)
51
-        {
52
-        case 1:
53
-            maxHP += 10;
54
-            restoreHP();
55
-            break;
56
-        case 2:
57
-            atk += 2;
58
-            break;
59
-        case 3:
60
-            def += 1;
61
-            break;
62
-        }
63
-        return true;
64
-    }
65
-    else
66
-    {
67
-        return false;
68
-    }
48
+    level += 1;
49
+    maxHP += 10;
50
+    atk += 2;
51
+    def += 1;
69 52
 }
70 53
 
71 54
 int Player::takeExperience(int bounty)

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

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

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

@@ -0,0 +1,89 @@
1
+#include "src/interface/battle.hpp"
2
+
3
+#include <iostream>
4
+#include <unistd.h>
5
+
6
+bool Battle::win = false;
7
+
8
+bool Battle::Won()
9
+{
10
+    return win;
11
+}
12
+
13
+bool Battle::Lose()
14
+{
15
+    return !win;
16
+}
17
+
18
+void Battle::Start(Player *player, Monster *monster)
19
+{
20
+    std::cout << " ===== BATTLE INFO ===== \n"
21
+              << player->getName() << " Lv." << player->getLevel() << ":\n"
22
+              << "  HP  : " << player->getCurrentHP() << "/" << player->getMaxHP() << "\n"
23
+              << "  Atk : " << player->getAtk() << "\n"
24
+              << "  Def : " << player->getDef() << "\n"
25
+              << "            VS           \n"
26
+              << monster->getName() << "\n"
27
+              << "  HP  : " << monster->getCurrentHP() << "/" << monster->getMaxHP() << "\n"
28
+              << "  Atk : " << monster->getAtk() << "\n"
29
+              << "  Def : " << monster->getDef() << "\n"
30
+              << "  Drop: " << monster->getBounty() << "\n"
31
+              << std::endl;
32
+
33
+    std::cout << " ===== BATTLE START ===== " << std::endl;
34
+    while (player->isAlive() && monster->isAlive())
35
+    {
36
+        std::cout << player->getName() << " attacked " << monster->getName() << "!" << std::endl;
37
+        usleep(200000);
38
+        int monsterDmg = monster->defend(player->getAtk());
39
+        if (monsterDmg > 0)
40
+        {
41
+            std::cout << monster->getName() << " got hit by " << monsterDmg << " points!" << std::endl;
42
+        }
43
+        else
44
+        {
45
+            std::cout << monster->getName() << " blocked the attack!" << std::endl;
46
+        }
47
+        usleep(200000);
48
+
49
+        if (monster->isAlive())
50
+        {
51
+            std::cout << monster->getName() << " attacked " << player->getName() << "!" << std::endl;
52
+            usleep(200000);
53
+            int playerDmg = player->defend(monster->getAtk());
54
+            if (playerDmg > 0)
55
+            {
56
+                std::cout << player->getName() << " got hit by " << playerDmg << " points!" << std::endl;
57
+            }
58
+            else
59
+            {
60
+                std::cout << player->getName() << " blocked the attack!" << std::endl;
61
+            }
62
+            usleep(200000);
63
+        }
64
+    }
65
+
66
+    if (player->isAlive())
67
+    {
68
+        std::cout << "YOU WIN !!!\n"
69
+                  << "Got " << monster->getBounty() << " points of experience.\n"
70
+                  << std::flush;
71
+        player->takeExperience(monster->getBounty());
72
+        if (player->checkLevelup())
73
+        {
74
+            std::cout << "You leveled up!" << std::endl;
75
+            player->levelUp();
76
+        }
77
+        else
78
+        {
79
+            std::cout << player->expToLevelUp() << " points left to level up.\n"
80
+                      << std::flush;
81
+        }
82
+        win = true;
83
+    }
84
+    else
85
+    {
86
+        std::cout << "YOU LOSE !!!!!" << std::endl;
87
+        win = false;
88
+    }
89
+}

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

@@ -0,0 +1,18 @@
1
+#ifndef HACKTHEGAME_BATTLESYSTEM_VERSION_000_HPP
2
+#define HACKTHEGAME_BATTLESYSTEM_VERSION_000_HPP
3
+
4
+#include "src/class/monster.hpp"
5
+#include "src/class/player.hpp"
6
+
7
+class Battle
8
+{
9
+  private:
10
+    static bool win;
11
+
12
+  public:
13
+    static bool Won();
14
+    static bool Lose();
15
+    static void Start(Player *player, Monster *monster);
16
+};
17
+
18
+#endif

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

@@ -1,37 +0,0 @@
1
-#include "src/interface/battle0.hpp"
2
-
3
-int startBattle(Player *player, Monster *monster)
4
-{
5
-    printf(" ===== BATTLE INFO  ===== \n");
6
-
7
-    printf("%15s (Lv.%n):\n", player->getName(), player->getLevel());
8
-    printf("  HP : %n/%n\n", player->getCurrentHP(), player->getMaxHP());
9
-    printf("  Att: %n\n", player->getAtt());
10
-    printf("  Def: %n\n", player->getDef());
11
-
12
-    printf("%15s:\n", monster->getName());
13
-    printf("  HP : %n/%n\n", monster->getCurrentHP(), monster->getMaxHP());
14
-    printf("  Att: %n\n", monster->getAtt());
15
-    printf("  Def: %n\n", monster->getDef());
16
-
17
-    printf(" ===== BATTLE START ===== \n");
18
-    while (player->isAlive() && monster->isAlive())
19
-    {
20
-        printf("%15s and %15s attacked each other !!!\n", player->getName(), monster->getName());
21
-        printf("%15s lose %d HP...\n", player->getName(), player->defend(monster->getAtt()));
22
-        printf("%15s lose %d HP...\n", monster->getName(), monster->defend(player->getAtt()));
23
-    }
24
-
25
-    printf(" ===== BATTLE  END  ===== \n");
26
-    if (player->isAlive())
27
-    {
28
-        player->restoreHP();
29
-        printf("YOU WIN !!!\n");
30
-        return 1;
31
-    }
32
-    else
33
-    {
34
-        printf("YOU LOSE !!!\n");
35
-        return 0;
36
-    }
37
-}

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

@@ -1,11 +0,0 @@
1
-#ifndef HACKTHEGAME_BATTLESYSTEM_VERSION_000_HPP
2
-#define HACKTHEGAME_BATTLESYSTEM_VERSION_000_HPP
3
-
4
-#include "src/class/monster.hpp"
5
-#include "src/class/player.hpp"
6
-
7
-#include <cstdio>
8
-
9
-int startBattle(Player *player, Monster *monster);
10
-
11
-#endif

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

@@ -3,41 +3,121 @@
3 3
 
4 4
 #include <iostream>
5 5
 
6
-Player *createCharacter()
6
+Player *Creation::ofPlayer()
7 7
 {
8
-    std::string name;
8
+    std::cout << "=== Welcome to Character Creation ===\n"
9
+              << std::flush;
9 10
 
10
-    char choice;
11
-
12
-    Player *newPlayer = new Player("HackTheGame");
13
-
14
-    std::cout << "Welcome to character creation !!!" << std::endl;
15
-
16
-    do
11
+    while (true)
17 12
     {
18
-        std::cout << "Please enter your character name: (Max 15 letters)\n"
19
-                  << "> " << std::flush;
13
+        std::cout << "Please enter your character name below\n"
14
+                  << ">" << std::flush;
20 15
 
16
+        std::string name;
21 17
         std::cin >> name;
18
+
22 19
         if (name.size() > 15)
23 20
         {
24
-            std::cout << "Your name is too long!" << std::endl;
21
+            std::cout << "Your character name is too long!\n"
22
+                      << std::flush;
25 23
             continue;
26 24
         }
25
+        else
26
+        {
27
+            std::cout << "Creating your character...\n"
28
+                      << std::flush;
29
+
30
+            Player *newPlayer = new Player(name);
31
+            Info::ofPlayer(newPlayer);
32
+
33
+            std::cout << "Accept? [Y/n] \n"
34
+                      << ">" << std::flush;
35
+            char choice = 'Y';
36
+            std::cin >> choice;
37
+
38
+            if (choice == 'Y' || choice == 'y')
39
+            {
40
+                return newPlayer;
41
+            }
42
+        }
43
+    }
44
+}
27 45
 
28
-        std::cout << "Creating your character..." << std::endl;
46
+Monster *Creation::ofMonster()
47
+{
29 48
 
30
-        delete newPlayer;
31
-        newPlayer = new Player(name);
49
+    const Monster monsterDen[] = {
50
+        Monster("Slime", 10, 1, 0, 1),
51
+        Monster("Goblin", 30, 2, 1, 2),
52
+        Monster("Wolf", 50, 3, 1, 3),
53
+        Monster("Zombie", 100, 4, 0, 4),
54
+        Monster("Zombie Knight", 200, 10, 7, 5),
55
+        Monster("Baby Dragon", 500, 20, 15, 10),
56
+        Monster("Dragon", 1000, 50, 20, 20)};
57
+    while (true)
58
+    {
59
+        int count = 0;
60
+        std::cout << "=== Welcome to Hunting Ground ===\n"
61
+                  << std::flush;
32 62
 
33
-        std::cout << "Done...\n"
34
-                  << "Character Info: " << std::endl;
63
+        for (Monster monster : monsterDen)
64
+        {
65
+            std::cout << "[" << ++count << "] " << monster.getName() << std::endl;
66
+        }
35 67
 
36
-        Info::ofCharacter(newPlayer);
68
+        std::cout << "[0] Exit\n"
69
+                  << ">" << std::flush;
37 70
 
38
-        std::cout << "Accept (y/N)?: " << std::flush;
39
-        std::cin >> choice;
40
-    } while (choice != 'Y' && choice != 'y');
71
+        char input;
72
+        std::cin >> input;
41 73
 
42
-    return newPlayer;
74
+        if (input <= ('0' + count) && input > '0')
75
+        {
76
+            char decision = 'Y';
77
+            Monster *summoned = new Monster(monsterDen[input - '1']);
78
+            Info::ofMonster(summoned);
79
+            std::cout << "Fight this monster? [Y/n]" << std::endl;
80
+            std::cout << ">" << std::flush;
81
+            std::cin >> decision;
82
+
83
+            if (decision == 'y' || decision == 'Y')
84
+            {
85
+                return summoned;
86
+            }
87
+            else
88
+            {
89
+                continue;
90
+            }
91
+        }
92
+        else if (input == '0')
93
+        {
94
+            return nullptr;
95
+        }
96
+        else
97
+        {
98
+            std::cout << "Monster not found!" << std::endl;
99
+            continue;
100
+        }
101
+    }
102
+}
103
+
104
+Monster *Creation::ofBoss()
105
+{
106
+    Monster *boss = new Monster("Flag Guardian", 987654321, 123456789, 123456789, 0);
107
+    std::cout << "You are gonna fight the final boss:\n" << std::flush;
108
+    Info::ofMonster(boss);
109
+    std::cout << "Are you sure? [Y/n]\n"
110
+              << "> " << std::flush;
111
+
112
+    char choice = 'Y';
113
+    std::cin >> choice;
114
+
115
+    if (choice == 'Y' || choice == 'y')
116
+    {
117
+        return boss;
118
+    }
119
+    else
120
+    {
121
+        return nullptr;
122
+    }
43 123
 }

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

@@ -4,6 +4,12 @@
4 4
 #include "src/class/player.hpp"
5 5
 #include "src/class/monster.hpp"
6 6
 
7
-Player *createCharacter();
7
+class Creation
8
+{
9
+public:
10
+  static Player *ofPlayer();
11
+  static Monster *ofMonster();
12
+  static Monster *ofBoss();
13
+};
8 14
 
9 15
 #endif

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

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

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

@@ -1,29 +1,9 @@
1 1
 #include "src/system/betatest.hpp"
2 2
 
3
-#include <fstream>
4
-#include <string>
5 3
 
6
-bool checkBetaTest()
7
-{
8
-    std::string betaFlag = "4re_Y0u_53ri0usly_checking_f0r_b3t4_t3sT?";
9
-    std::string tmp;
10
-
11
-    int result = -1;
12
-    
13
-    try
14
-    {
15
-        std::fstream betaFile("beta.test");
16
-
17
-        if (betaFile) {
18
-            betaFile >> tmp;
4
+std::string BetaTest::betaFlag = "4re_Y0u_53ri0usly_checking_f0r_b3t4_t3sT?";
19 5
 
20
-            result = tmp.compare("GKSK{" + betaFlag + "}");
21
-        }
22
-    }
23
-    catch(...)
24
-    {
25
-        return false;
26
-    }
27
-
28
-    return result == 0;
6
+bool BetaTest::check(std::string input)
7
+{
8
+    return input.compare("GKSK{" + betaFlag + "}") == 0;
29 9
 }

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

@@ -1,6 +1,15 @@
1 1
 #ifndef HACKTHEGAME_BETATEST_HPP
2 2
 #define HACKTHEGAME_BETATEST_HPP
3 3
 
4
-bool checkBetaTest();
4
+#include <string>
5
+
6
+class BetaTest
7
+{
8
+  private:
9
+    static std::string betaFlag;
10
+
11
+  public:
12
+    static bool check(std::string input);
13
+};
5 14
 
6 15
 #endif

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

@@ -0,0 +1,34 @@
1
+#include "flag.hpp"
2
+
3
+#include <fstream>
4
+#include <iostream>
5
+
6
+std::string Flag::flag = "";
7
+
8
+bool Flag::Load()
9
+{
10
+    std::ifstream file("flag.txt");
11
+    if (file.good())
12
+    {
13
+        file >> flag;
14
+        return true;
15
+    }
16
+    else
17
+    {
18
+        return false;
19
+    }
20
+}
21
+
22
+void Flag::Print()
23
+{
24
+    if (Load())
25
+    {
26
+        std::cout << flag << std::endl;
27
+    }
28
+    else
29
+    {
30
+        std::cout << "Something went wrong on the server\n"
31
+                  << "Please contact the administrator...\n"
32
+                  << std::endl;
33
+    }
34
+}

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

@@ -0,0 +1,16 @@
1
+#ifndef FLAG_HACKTHEGAME_HPP
2
+#define FLAG_HACKTHEGAME_HPP
3
+
4
+#include <string>
5
+
6
+class Flag
7
+{
8
+  private:
9
+    static std::string flag;
10
+    static bool Load();
11
+
12
+  public:
13
+    static void Print();
14
+};
15
+
16
+#endif

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

@@ -0,0 +1,53 @@
1
+#include "memory.hpp"
2
+
3
+#include "cpp-base64/base64.h"
4
+
5
+#include <string>
6
+#include <cstring>
7
+
8
+Player *Memory::loadFromCode(std::string code)
9
+{
10
+    code = base64_decode(code);
11
+    char playerName[16] = {0};
12
+    int playerHP = 0;
13
+    int playerAtk = 0;
14
+    int playerDef = 0;
15
+    int playerLevel = 0;
16
+    int playerExp = 0;
17
+
18
+    int result = sscanf(code.c_str(),
19
+                        "PlayerLevel=%d;PlayerExp=%d;PlayerHP=%d;PlayerAtk=%d;PlayerDef=%d;PlayerName=%15s",
20
+                        &playerLevel,
21
+                        &playerExp,
22
+                        &playerHP,
23
+                        &playerAtk,
24
+                        &playerDef,
25
+                        playerName);
26
+
27
+    std::string playerTrueName = playerName;
28
+
29
+    if (result == 6)
30
+    {
31
+        return new Player(playerTrueName, playerHP, playerAtk, playerDef, playerLevel, playerExp);
32
+    }
33
+    else
34
+    {
35
+        return nullptr;
36
+    }
37
+}
38
+
39
+std::string Memory::saveToCode(Player *player)
40
+{
41
+    char code[256];
42
+    snprintf(code, sizeof(code),
43
+             "PlayerLevel=%d;PlayerExp=%d;PlayerHP=%d;PlayerAtk=%d;PlayerDef=%d;PlayerName=%s",
44
+             player->getLevel(),
45
+             player->getExp(),
46
+             player->getMaxHP(),
47
+             player->getAtk(),
48
+             player->getDef(),
49
+             player->getName().c_str());
50
+
51
+    return base64_encode(reinterpret_cast<unsigned char *>(code),
52
+                         strlen(code));
53
+}

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

@@ -0,0 +1,14 @@
1
+#ifndef HACKTHEGAME_SAVELOAD_HPP
2
+#define HACKTHEGAME_SAVELOAD_HPP
3
+
4
+#include "src/class/player.hpp"
5
+#include <fstream>
6
+
7
+class Memory
8
+{
9
+public:
10
+  static Player *loadFromCode(std::string);
11
+  static std::string saveToCode(Player *);
12
+};
13
+
14
+#endif

BIN
version002 View File


Loading…
Cancel
Save