Browse Source

first commit

master
myitinos 4 years ago
parent
commit
65578983c9
11 changed files with 618 additions and 0 deletions
  1. +24
    -0
      Makefile
  2. +1
    -0
      flag.txt
  3. +29
    -0
      lib/BattleInterface.hpp
  4. +147
    -0
      lib/Character.cpp
  5. +54
    -0
      lib/Character.hpp
  6. +42
    -0
      lib/Spell.cpp
  7. +28
    -0
      lib/Spell.hpp
  8. +194
    -0
      lib/UserInterface.cpp
  9. +50
    -0
      lib/UserInterface.hpp
  10. BIN
      main
  11. +49
    -0
      main.cpp

+ 24
- 0
Makefile View File

@ -0,0 +1,24 @@
CC = g++
UserInterface.o: lib/UserInterface.cpp lib/UserInterface.hpp
g++ -c lib/UserInterface.cpp -o UserInterface.o
BattleInterface.o: lib/BattleInterface.cpp lib/BattleInterface.hpp
g++ -c lib/BattleInterface.cpp -o BattleInterface.o
Spell.o: lib/Spell.cpp lib/Spell.hpp
g++ -c lib/Spell.cpp -o Spell.o
Character.o: lib/Character.cpp lib/Character.hpp
g++ -c lib/Character.cpp -o Character.o
main: Spell.o Character.o UserInterface.o main.cpp
g++ main.cpp -o main Spell.o Character.o UserInterface.o
clean: Spell.o Character.o UserInterface.o
rm Spell.o Character.o UserInterface.o
striped: Spell.o Character.o main.cpp
g++ -s main.cpp -o main Spell.o Character.o UserInterface.o
all: Spell.o Character.o main

+ 1
- 0
flag.txt View File

@ -0,0 +1 @@
slashroot{dummy}

+ 29
- 0
lib/BattleInterface.hpp View File

@ -0,0 +1,29 @@
#ifndef SPELL_WARZ_BATTLEINTERFACE_HPP
#define SPELL_WARZ_BATTLEINTERFACE_HPP 1
#include <iostream>
#include <thread>
#include <chrono>
#include "Character.hpp"
#include "Spell.hpp"
#include "UserInterface.hpp"
class BattleInterface
{
protected:
static const int maxTurn = 100;
static int turn;
Character *player1;
Character *player2;
public:
void battleStartAnnounce();
void battleEndAnnouce();
void start();
Character *getWinner();
};
#endif

+ 147
- 0
lib/Character.cpp View File

@ -0,0 +1,147 @@
#include "Character.hpp"
#include <cstring>
Character::Character(char *n, int l, int e, int h, int m, int a, int d)
{
strcpy(this->name, n);
this->level = l;
this->experience = e;
this->maxHP = h;
this->curHP = maxHP;
this->maxMP = m;
this->curMP = maxMP;
this->atk = a;
this->def = d;
}
char *Character::getName()
{
return this->name;
}
int Character::getLevel()
{
return this->level;
}
int Character::getExperience()
{
return this->experience;
}
int Character::getMaxHP()
{
return this->maxHP;
}
int Character::getCurHP()
{
return this->curHP;
}
int Character::getMaxMP()
{
return this->maxMP;
}
int Character::getCurMP()
{
return this->curMP;
}
int Character::getAtk()
{
return this->atk;
}
int Character::getDef()
{
return this->def;
}
void Character::levelUp()
{
if ((this->level <= maxLevel) && this->readytoLevelUp())
{
this->level++;
this->maxHP += 10;
this->maxMP += 5;
}
this->curHP = this->maxHP;
this->curMP = this->maxMP;
}
void Character::restoreHP(int n)
{
this->curHP += n;
if (this->curHP > this->maxHP)
{
this->curHP = this->maxHP;
}
}
void Character::restoreMP(int n)
{
this->curMP += n;
if (this->curMP > this->maxMP)
{
this->curMP = this->maxMP;
}
}
void Character::reduceHP(int n)
{
this->curHP -= n;
}
void Character::reduceMP(int n)
{
this->curMP -= n;
}
bool Character::isAlive()
{
return this->curHP > 0;
}
int Character::toNextLevel()
{
return (this->level <= maxLevel) ? ((this->level + 1) * (this->level + 1)) - this->getExperience() : 999999;
}
bool Character::readytoLevelUp()
{
return (this->toNextLevel() <= 0);
}
void Character::increaseExperience(int n)
{
this->experience += n;
if (this->experience > maxEperience)
{
this->experience = maxEperience;
}
}
bool Character::canCastSpell(Spell *s)
{
return this->curMP >= s->getCost();
}
void Character::castSpell(Spell *s, Character *t)
{
this->reduceMP(s->getCost());
t->reduceHP(s->getAmount());
}
void Character::rest()
{
this->curHP = this->maxHP;
this->curMP = this->maxMP;
}
void Character::suicide()
{
this->curHP = 0;
}

+ 54
- 0
lib/Character.hpp View File

@ -0,0 +1,54 @@
#ifndef SPELL_WARZ_CHARACTER_HPP
#define SPELL_WARZ_CHARACTER_HPP 1
#include <vector>
#include "Spell.hpp"
class Character
{
protected:
static const int maxLevel = 100;
static const int maxEperience = 999999999;
char name[16];
int level;
int experience;
int maxHP;
int curHP;
int maxMP;
int curMP;
int atk;
int def;
void restoreHP(int);
void restoreMP(int);
void reduceHP(int);
void reduceMP(int);
public:
Character(char *, int, int, int, int, int, int);
void castSpell(Spell *, Character *);
bool canCastSpell(Spell *);
char *getName();
int getLevel();
int getExperience();
int getMaxHP();
int getCurHP();
int getMaxMP();
int getCurMP();
int getAtk();
int getDef();
int toNextLevel();
bool readytoLevelUp();
bool isAlive();
void levelUp();
void suicide();
void rest();
void increaseExperience(int n);
};
#endif

+ 42
- 0
lib/Spell.cpp View File

@ -0,0 +1,42 @@
#include "Spell.hpp"
Spell::Spell(std::string n, int t, int a, int c)
{
this->name = std::string(n);
this->type = t;
this->amount = a;
this->cost = c;
}
int Spell::getType()
{
return this->type;
}
int Spell::getAmount()
{
return this->amount;
}
int Spell::getCost()
{
return this->cost;
}
std::string Spell::getName()
{
return this->name;
}
std::vector<Spell *> Spell::Book = {
new Spell("Napalm Beat", 1, 4, 1),
new Spell("Fire Ball", 1, 6, 2),
new Spell("Cold Bolt", 1, 8, 3),
new Spell("Stone curse", 1, 10, 4),
new Spell("Lightning Bolt", 1, 12, 5),
new Spell("Soul Strike", 1, 14, 6),
new Spell("Fire Wall", 1, 16, 7),
new Spell("Frost Diver", 1, 18, 8),
new Spell("Lighting Storm", 1, 20, 9),
new Spell("Asura's Strike", 1, 50, 10),
};

+ 28
- 0
lib/Spell.hpp View File

@ -0,0 +1,28 @@
#ifndef SPELL_WARZ_SPELL_CPP
#define SPELL_WARZ_SPELL_CPP 1
#include <vector>
#include <string>
class Spell
{
protected:
std::string name;
int type;
int amount;
int cost;
public:
int TYPE_RESTORATION = 0;
int TYPE_DESTRUCTION = 1;
static std::vector<Spell *> Book;
Spell(std::string, int, int, int);
int getType();
int getAmount();
int getCost();
std::string getName();
};
#endif

+ 194
- 0
lib/UserInterface.cpp View File

@ -0,0 +1,194 @@
#include "UserInterface.hpp"
const int UserInterface::interval = 1000; // in ms
const int UserInterface::miniInterval = 50; // in ms
const int UserInterface::maxDay = 28;
const int UserInterface::maxMonth = 4;
const int UserInterface::maxYear = 100;
int UserInterface::day = 1;
int UserInterface::month = 1;
int UserInterface::year = 90;
bool UserInterface::gameOver = false;
std::vector<std::string> UserInterface::dayName = {
"Morndas",
"Tirdas",
"Middas",
"Turdas",
"Fredas",
"Loredas",
"Sundas",
};
std::vector<std::string> UserInterface::monthName = {
"Morning Star",
"Sun's Dawn'",
"First Seed",
"Rain's Hand",
"Second Seed",
"Mid Year",
"Sun's Height",
"Last Seed",
"Hearthfire",
"Frostfall",
"Sun's Dusk",
"Evening Star",
};
void UserInterface::print(std::string msg)
{
std::cout << msg << std::flush;
std::this_thread::sleep_for(std::chrono::milliseconds(UserInterface::interval));
}
void UserInterface::print(char *msg)
{
std::cout << msg << std::flush;
std::this_thread::sleep_for(std::chrono::milliseconds(UserInterface::interval));
}
void UserInterface::print(const char *msg)
{
std::cout << msg << std::flush;
std::this_thread::sleep_for(std::chrono::milliseconds(UserInterface::interval));
}
void UserInterface::printByChar(const char *msg)
{
int len = strlen(msg);
for (size_t i = 0; i < len; i++)
{
std::cout << msg[i] << std::flush;
std::this_thread::sleep_for(std::chrono::milliseconds(UserInterface::miniInterval));
}
}
void UserInterface::welcomeMessage()
{
std::cout << "+++++++++++++++++++++++++++++++++++\n"
<< "+ Welcome to Spell-Warz-Again !!! +\n"
<< "+++++++++++++++++++++++++++++++++++\n"
<< std::flush;
}
Character *UserInterface::characterCreation()
{
char buffer[128] = {0};
char choice = 0;
while (choice != 'y' && choice != 'Y')
{
std::cout << "Who should we call you?\n"
<< ">" << std::flush;
std::cin >> buffer;
std::cout << "So you are a young mage named \"" << buffer << "\" correct? (y/N)\n"
<< ">";
std::cin >> choice;
}
return new Character(
buffer, 1, 0, 10, 10, 5, 5);
}
void UserInterface::epilogue()
{
UserInterface::printByChar(
"You are just a young mage in a mage school,\n"
"When you witnessed your arch-mage got killed by your senior...\n"
"The killer was mumbling about some flag inside a scroll,\n"
"he constantly mentioned something about a competition called CTF...\n"
"You thought to yourself: \"What the f*ck is a CTF?\"\n"
"Nevertheless, you want that scroll, you want that flag!\n"
"Defeat the new arch-mage that was once your senior to get a glimpse of that scroll!\n"
"Note: You need to do this in 10 year of in-game, otherwise you would graduate first...\n");
}
std::string UserInterface::dateString()
{
char date[5] = {0};
if (UserInterface::day < 21)
{
switch (UserInterface::day)
{
case 1:
sprintf(date, "1st");
break;
case 2:
sprintf(date, "2nd");
break;
case 3:
sprintf(date, "3rd");
break;
default:
sprintf(date, "%dth", UserInterface::day);
break;
}
}
else
{
switch (UserInterface::day % 10)
{
case 1:
sprintf(date, "%dst", UserInterface::day);
break;
case 2:
sprintf(date, "%dnd", UserInterface::day);
break;
case 3:
sprintf(date, "%drd", UserInterface::day);
break;
default:
sprintf(date, "%dth", UserInterface::day);
break;
}
}
return std::string(
UserInterface::dayName.at((UserInterface::day % 7) - 1) + ", " +
date + " of " + UserInterface::monthName.at(UserInterface::month - 1) +
", Year " + std::to_string(UserInterface::year));
}
void UserInterface::menu()
{
std::cout << UserInterface::dateString() << "\n"
<< "Available action:\n"
<< "[1] Take a rest\n"
<< "[2] Practice magic\n"
<< "[3] Spar against classmate\n"
<< "[4] Challenge the new Arch-Mage\n"
<< "[5] Gather info about the new Arch-Mage\n"
<< "[6] Meditate to your inner-self\n"
<< "[0] Commit sudoku\n"
<< std::flush;
}
int UserInterface::getNumber(std::string msg, int min, int max)
{
int buffer = max + 1;
while (!(buffer <= max && buffer >= min))
{
std::cout << msg << std::flush;
std::cin >> buffer;
}
return buffer;
}
void UserInterface::nextDay()
{
if (UserInterface::day++ >= UserInterface::maxDay)
{
if (UserInterface::month++ >= UserInterface::maxMonth)
{
if (UserInterface::year++ >= UserInterface::maxYear)
{
UserInterface::gameOver = true;
}
}
}
}
bool UserInterface::isGameOver()
{
return gameOver;
}

+ 50
- 0
lib/UserInterface.hpp View File

@ -0,0 +1,50 @@
#ifndef SPELL_WARZ_USER_INTERFACE_HPP
#define SPELL_WARZ_USER_INTERFACE_HPP 1
#include <iostream>
#include <thread>
#include <chrono>
#include <string>
#include <cstring>
#include "Character.hpp"
#include "Spell.hpp"
class UserInterface
{
protected:
static const int interval; // in ms
static const int miniInterval; // in ms
static const int maxDay;
static const int maxMonth;
static const int maxYear;
static std::vector<std::string> dayName;
static std::vector<std::string> monthName;
static int day;
static int month;
static int year;
static bool gameOver;
public:
static void print(std::string);
static void print(const char *);
static void print(char *);
static void printByChar(std::string);
static void printByChar(const char *);
static void printByChar(char *);
static void welcomeMessage();
static void epilogue();
static void menu();
static void nextDay();
static std::string dateString();
static int getNumber(std::string, int, int);
static Character *characterCreation();
static bool isGameOver();
};
#endif

BIN
main View File


+ 49
- 0
main.cpp View File

@ -0,0 +1,49 @@
#include <iostream>
#include <thread>
#include <chrono>
#include <random>
#include <fstream>
#include "lib/Character.hpp"
#include "lib/Spell.hpp"
#include "lib/UserInterface.hpp"
// #include "lib/BattleInterface.hpp"
std::string loadFlag()
{
return "";
}
int main()
{
std::string flag;
Character *player;
flag = loadFlag();
srand(time(0));
UserInterface::welcomeMessage();
UserInterface::epilogue();
player = UserInterface::characterCreation();
while (player->isAlive() && !UserInterface::isGameOver())
{
int choice;
UserInterface::menu();
choice = UserInterface::getNumber(
"What are you gonna do today?\n>",
0, 0);
switch (choice)
{
case 0:
UserInterface::print("You commit sudoku...\n");
UserInterface::print("Was it supposed to be seppuku?\n");
UserInterface::print("Nevermind, you killed yourself.\n");
player->suicide();
break;
default:
break;
}
}
}

Loading…
Cancel
Save