Skip to content
Snippets Groups Projects
Commit 2a9a4ea7 authored by Ori Almog's avatar Ori Almog
Browse files

makefile test

parent 32795dc4
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,8 @@
*.o
*.synctex.gz
.hiddenmv
# Editor files
*.swp
......@@ -24,3 +26,5 @@ src/boost_1_62_0/*
# Library files
src/*.so
src/temp/*
#!/bin/bash
if [ -d "temp" ]; then
rm -f *.cpp
cp temp/*.cpp .
rm -rf temp/
fi
......@@ -4,7 +4,7 @@
#include "include/armor.h"
#include "include/coord.h"
#include "include/item.h"
#include "include/random.h"
std::vector<ARMOR_TUPLE_TYPE > Armor::typeVector = {
ARMOR_TUPLE_TYPE {"Leather Armor", 3},
......@@ -17,13 +17,19 @@ std::vector<ARMOR_TUPLE_TYPE > Armor::typeVector = {
};
Armor::Armor(Coord location)
: Armor(location, Item::Context::FLOOR, rand() % Armor::typeVector.size()) {}
: Armor(location, Item::Context::FLOOR, Generator::intFromRange(0, Armor::typeVector.size() - 1)) {}
Armor::Armor(Coord location, Item::Context context, int type)
: Item(']', location, context, "Armor", std::get<0>(Armor::typeVector[type]), type, false, false),
rating(std::get<1>(Armor::typeVector[type])) {
int chance = Generator::intFromRange(1, 100);
this->enchantProtection = (rand() % 3) - 1;
if (chance <= 16) {
this->cursed = true;
this->enchantProtection -= Generator::intFromRange(0, 3);
} else if (chance <= 33) {
this->enchantProtection += Generator::intFromRange(0, 3);
}
}
int Armor::getRating() {
......
......@@ -4,6 +4,7 @@
#include <vector>
#include "include/item.h"
#include "include/random.h"
std::map<std::string, std::map<int, bool> > Item::identified;
......@@ -23,14 +24,7 @@ Item::Item(char symbol, Coord location, Item::Context context, std::string class
type(type) {}
Item::Item(char symbol, Coord location, Item::Context context, std::string className, std::string name, int type, bool canStack, bool canThrow)
: Feature(symbol, location),
canStack(canStack),
canThrow(canThrow),
className(className),
context(context),
name(name),
pseudoName(name),
type(type) {}
: Item(symbol, location, context, className, name, name, type, canStack, canThrow) {}
bool Item::operator==(const Item& other) const {
return this->name.compare(other.name) == 0;
......
......@@ -125,7 +125,7 @@ void Level::generate(PlayerChar player) {
bool dne = false;
//If room DNE, set its size to 1x1
if (gen() > ROOM_EXIST_CHANCE){
if (gen.rand() > ROOM_EXIST_CHANCE){
roomSize = Coord(1,1);
dne = true;
}
......
source: *.cpp
#Compiling...
#Setting up...
@cp ./libtcod/*.so .
......@@ -12,21 +12,23 @@ source: *.cpp
@cp test/*.cpp .
#Compiling...
@g++ -g -c *.cpp -I./libtcod/include -L. -ltcod -ltcodxx -Wl,-rpath=. -Wall -std=c++11
#Linking source...
@g++ -g -o RogueReborn.exe zz.*.o *.so -I./libtcod/include -L. -ltcod -ltcodxx -Wl,-rpath=. -Wall -std=c++11
@rm -f zz.main.o
#Linking tests...
@g++ -g -o Test.exe *.o *.so -I./libtcod/include -L. -ltcod -ltcodxx -Wl,-rpath=. -Wall -std=c++11
#Cleaning up...
@rm -f *.o *.cpp
@cp temp/*.cpp .
recall:
@rm -f *.cpp
@cp temp/*.cpp .
@rm -rf temp/
@bash .recall
clean:
@rm -f *.exe *.so *.o
......
......@@ -5,6 +5,7 @@
#include "include/coord.h"
#include "include/item.h"
#include "include/potion.h"
#include "include/random.h"
std::vector<std::string> Potion::nameVector = Item::shuffleNameVector({
"Blue Potion", "Red Potion", "Green Potion", "Grey Potion", "Brown Potion",
......@@ -30,7 +31,7 @@ std::vector<POTION_TUPLE_TYPE > Potion::typeVector = {
};
Potion::Potion(Coord location)
: Potion(location, Item::Context::FLOOR, rand() % Potion::typeVector.size()) {}
: Potion(location, Item::Context::FLOOR, Generator::intFromRange(0, Potion::typeVector.size() - 1)) {}
Potion::Potion(Coord location, Item::Context context, int type)
: Item('!', location, context, "Potion", std::get<0>(Potion::typeVector[type]), Potion::nameVector[type], type, true, true) {}
......
#include <random>
#include <algorithm>
#include "include/random.h"
#include <random>
#include "include/coord.h"
#include "include/random.h"
Generator::Generator() {
gen = std::mt19937(std::random_device()());
}
std::mt19937 Generator::gen = std::mt19937(std::random_device()());
//inclusive
int Generator::intFromRange(int lower, int upper) {
return std::uniform_int_distribution<>(lower, upper)(gen);
}
double Generator::operator()() {
double Generator::rand() {
return std::uniform_real_distribution<>(0, 1)(gen);
}
bool Generator::randBool() {
return rand() < 0.5;
}
Coord Generator::randPosition(Coord a, Coord b) {
return Coord(intFromRange(a[0], b[0]), intFromRange(a[1], b[1]));
}
void Generator::shuffle(std::vector<Coord>* s) {
std::random_shuffle(s->begin(), s->end());
}
\ No newline at end of file
}
......@@ -4,6 +4,7 @@
#include "include/coord.h"
#include "include/item.h"
#include "include/random.h"
#include "include/ring.h"
std::vector<std::string> Ring::nameVector = Item::shuffleNameVector({
......@@ -27,11 +28,11 @@ std::vector<RING_TUPLE_TYPE > Ring::typeVector = {
};
Ring::Ring(Coord location)
: Ring(location, Item::Context::FLOOR, rand() % Ring::typeVector.size()) {}
: Ring(location, Item::Context::FLOOR, Generator::intFromRange(0, Ring::typeVector.size() - 1)) {}
Ring::Ring(Coord location, Item::Context context, int type)
: Item('=', location, context, "Ring", std::get<0>(Ring::typeVector[type]), Ring::nameVector[type], type, true, true) {}
bool Ring::activate(Level* level) {
bool Ring::activate(Level* level) {
return false;
}
\ No newline at end of file
}
......@@ -4,6 +4,7 @@
#include "include/coord.h"
#include "include/item.h"
#include "include/random.h"
#include "include/scroll.h"
......@@ -40,12 +41,12 @@ std::vector<std::string> Scroll::initializeScrollNames() {
std::vector<std::string> nameVector;
for (int type = 0 ; type < static_cast<int>(Scroll::typeVector.size()) ; type++) {
std::string scrollName = "Scroll titled '";
scrollName += Scroll::syllableVector[rand() % Scroll::syllableVector.size()];
scrollName += Scroll::syllableVector[Generator::intFromRange(0, Scroll::syllableVector.size() - 1)];
int syllables = 1 + (rand() % 3);
int syllables = Generator::intFromRange(1, 3);
for (int syll = 0 ; syll < syllables ; syll++) {
scrollName += " " + Scroll::syllableVector[rand() % Scroll::syllableVector.size()];
scrollName += " " + Scroll::syllableVector[Generator::intFromRange(0, Scroll::syllableVector.size() - 1)];
}
scrollName += "'";
......@@ -56,7 +57,7 @@ std::vector<std::string> Scroll::initializeScrollNames() {
}
Scroll::Scroll(Coord location)
: Scroll(location, Item::Context::FLOOR, rand() % Scroll::typeVector.size()) {}
: Scroll(location, Item::Context::FLOOR, Generator::intFromRange(0, Scroll::typeVector.size() - 1)) {}
Scroll::Scroll(Coord location, Item::Context context, int type)
: Item('?', location, context, "Scroll", std::get<0>(Scroll::typeVector[type]), Scroll::nameVector[type], type, true, true) {}
......
......@@ -3,12 +3,16 @@
#include <iostream>
#include "include/armor.h"
#include "testable.test.cpp"
int test(){
class ArmorTest : public Testable {
public:
ArmorTest(){
std::cout << "Creating armor test" << std::endl;
}
Armor a = Armor(Coord(5,5));
std::cout << a.getRating() << std::endl;
return 0;
}
\ No newline at end of file
bool test(){
std::cout << "Testing armor!" << std::endl;
return true;
}
};
\ No newline at end of file
#include <string>
#include <vector>
#include <iostream>
#include "armor.test.cpp"
#include "testable.test.cpp"
int main(){
ArmorTest a = ArmorTest();
bool b = a.test();
return 0;
}
\ No newline at end of file
#include <string>
#include <vector>
#include <iostream>
class Testable {
public:
virtual bool test() = 0;
};
\ No newline at end of file
......@@ -4,6 +4,7 @@
#include "include/coord.h"
#include "include/item.h"
#include "include/random.h"
#include "include/wand.h"
std::vector<WAND_TUPLE_TYPE > Wand::typeVector = {
......@@ -31,11 +32,11 @@ std::vector<std::string> Wand::nameVector = Item::shuffleNameVector({
Wand::Wand(Coord location)
: Wand(location, Item::Context::FLOOR, rand() % Wand::typeVector.size()) {}
: Wand(location, Item::Context::FLOOR, Generator::intFromRange(0, Wand::typeVector.size() - 1)) {}
Wand::Wand(Coord location, Item::Context context, int type)
: Item('/', location, context, "Wand", std::get<0>(Wand::typeVector[type]), Wand::nameVector[type], type, false, false),
charges(3 + (rand() % 5)) {}
charges(Generator::intFromRange(3, 7)) {}
bool Wand::activate(Level* level) {
this->charges--;
......
......@@ -3,6 +3,7 @@
#include "include/coord.h"
#include "include/item.h"
#include "include/random.h"
#include "include/weapon.h"
std::vector<WEAPON_TUPLE_TYPE > Weapon::typeVector = {
......@@ -17,16 +18,29 @@ std::vector<WEAPON_TUPLE_TYPE > Weapon::typeVector = {
};
Weapon::Weapon(Coord location)
: Weapon(location, Item::Context::FLOOR, rand() % Weapon::typeVector.size()) {}
: Weapon(location, Item::Context::FLOOR, Generator::intFromRange(0, Weapon::typeVector.size() - 1)) {}
Weapon::Weapon(Coord location, Item::Context context, int type)
: Item(')', location, context, "Weapon", std::get<0>(Weapon::typeVector[type]), type, std::get<3>(Weapon::typeVector[type]), true),
damage(std::get<1>(Weapon::typeVector[type])),
melee (std::get<2>(Weapon::typeVector[type])) {
this->enchantDamage = (rand() % 3) - 1;
this->enchantHit = (rand() % 3) - 1;
int chance = Generator::intFromRange(1, 96);
int iterations = Generator::intFromRange(1, 3);
int increment = 0;
if (chance <= 16) {
increment = -1;
this->cursed = true;
} else if (chance <= 32) {
increment = 1;
}
for (int i = 0 ; i < iterations ; i ++) {
if (Generator::randBool()) this->enchantDamage += increment;
else this->enchantHit += increment;
}
}
int Weapon::getChance() {
return this->enchantHit;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment