Commit 11d3724d authored by Felix Huther's avatar Felix Huther
Browse files

pit and ramp

parent a7005a2f
......@@ -12,8 +12,10 @@ SOURCES += \
level.cpp \
main.cpp \
observerpassive.cpp \
pit.cpp \
portal.cpp \
position2d.cpp \
ramp.cpp \
subjectactiv.cpp \
switch.cpp \
terminalui.cpp \
......@@ -28,8 +30,10 @@ HEADERS += \
floor.h \
level.h \
observerpassive.h \
pit.h \
portal.h \
position2d.h \
ramp.h \
subjectactiv.h \
switch.h \
terminalui.h \
......
......@@ -120,7 +120,13 @@ void DungeonCrawler::play() {
ifPortalDestPortalLogic(oneTileRight,onePosRight);
if(typeid(*characterTile) == typeid(Pit)){
}
movPossible = oneTileRight->onEnter(characterTile, currentChar);
if (movPossible) {
characterTile->moveTo(oneTileRight, currentChar);
ifSubjectNotify(oneTileRight);
......
......@@ -16,8 +16,6 @@ public:
void ifSubjectNotify(Tile* tile);
void ifPortalDestPortalLogic(Tile*& tile, Position2D& pos);
private:
......
......@@ -10,7 +10,12 @@ Floor::~Floor()
}
Tile *Floor::onEnter(Tile *fromTile, Character *who) {
return this;
if(typeid(*fromTile) == typeid(Pit))
{
return nullptr;
}
else return this;
}
bool Floor::moveTo(Tile *destTile, Character *who) {
......
......@@ -3,6 +3,7 @@
#include <string>
#include "tile.h"
#include "pit.h"
class Floor : public Tile{
public:
......
......@@ -61,6 +61,8 @@ void Level::setStructure() {
std::string stfloor = "floor";
std::string stSwitch = "switch";
std::string stDoor = "door";
std::string stpit = "pit";
std::string stramp = "ramp";
Door* doorPointer;
Switch* switchPointer;
......@@ -87,6 +89,7 @@ void Level::setStructure() {
{
doorPointer = new Door(stDoor,nullptr,pos);
mLevel.at(i).push_back(doorPointer);
}
else
{
......@@ -94,6 +97,19 @@ void Level::setStructure() {
mLevel.at(i).push_back(wallpointer);
}
}// PUT PITS WITH A TWO RAMPS
else if(j == 25 || j == 26 || j == 27 || j == 28 || j == 29 || j == 30)
{
if((i == 2 && j == 25) || (i == 8 && j == 30))
{
Tile* rampPointer = new Ramp(stramp,nullptr,pos);
mLevel.at(i).push_back(rampPointer);
}
else{
Tile* pitPointer = new Pit(stpit,nullptr,pos);
mLevel.at(i).push_back(pitPointer);
}
}
// PLACE A SWITCH
else if(i == 8 && j == 15)
......
#ifndef LEVEL_H
#define LEVEL_H
#include <vector>
#include "typeinfo"
#include "tile.h"
......@@ -9,6 +8,8 @@
#include "floor.h"
#include "switch.h"
#include "door.h"
#include "ramp.h"
#include "pit.h"
#include "position2d.h"
class Level {
......
......@@ -4,7 +4,7 @@
#include "dungeoncrawler.h"
int main() {
Level* level = new Level(10,30);
Level* level = new Level(10,40);
Character* myCharacter = new Character("metal");
level->placeCharacter(myCharacter,Position2D(2,2));
......
#include "pit.h"
Pit::Pit(const std::string &texture, Character *currentCharacter, const Position2D &position)
: Tile(texture, currentCharacter, position)
{}
Tile *Pit::onEnter(Tile *fromTile, Character *who)
{
return this;
if(typeid(*fromTile) == typeid(Pit))
{
}
}
bool Pit::moveTo(Tile *destTile, Character *who)
{
if(!destTile->hasCharacter()){
destTile->setCurrentCharacter(this->currentCharacter);
currentCharacter->setCurrentTile(destTile);
this->setCurrentCharacter(nullptr);
return true;
};
return false;
}
Tile *Pit::onLeave(Tile *destTile, Character *who)
{
return this;
}
#ifndef PIT_H
#define PIT_H
#include "tile.h"
class Pit : public Tile
{
public:
Pit(const std::string &texture, Character *currentCharacter, const Position2D &position);
// Tile interface
public:
Tile *onEnter(Tile *fromTile, Character *who) override;
bool moveTo(Tile *destTile, Character *who) override;
Tile *onLeave(Tile *destTile, Character *who) override;
};
#endif // PIT_H
#include "ramp.h"
Ramp::Ramp(const std::string &texture, Character *currentCharacter, const Position2D &position)
: Tile(texture, currentCharacter, position)
{}
Tile *Ramp::onEnter(Tile *fromTile, Character *who)
{
return this;
}
bool Ramp::moveTo(Tile *destTile, Character *who)
{
if(!destTile->hasCharacter()){
destTile->setCurrentCharacter(this->currentCharacter);
currentCharacter->setCurrentTile(destTile);
this->setCurrentCharacter(nullptr);
return true;
};
return false;
}
Tile *Ramp::onLeave(Tile *destTile, Character *who)
{
return this;
}
#ifndef RAMP_H
#define RAMP_H
#include "tile.h"
class Ramp : public Tile
{
public:
//CONSTRUCTORS
Ramp(const std::string &texture, Character *currentCharacter, const Position2D &position);
// Tile interface
public:
Tile *onEnter(Tile *fromTile, Character *who) override;
bool moveTo(Tile *destTile, Character *who) override;
Tile *onLeave(Tile *destTile, Character *who) override;
};
#endif // RAMP_H
......@@ -22,6 +22,9 @@ void TerminalUI::draw(Level *pLevel) {
else if(typeid(*item) == typeid(Floor)) std::cout << "." ;
else if(typeid(*item) == typeid(Portal))std::cout<< "O";
else if(typeid(*item) == typeid(Switch))std::cout <<"?";
else if(typeid(*item) == typeid(Ramp))std::cout <<"*";
else if(typeid(*item) == typeid(Pit))std::cout <<"_";
else if(typeid(*item) == typeid(Door)){
Door* doorPointer = dynamic_cast<Door*>(item);
bool isCLosed = doorPointer->getIsClosed();
......
#ifndef TILE_H
#define TILE_H
#include <typeinfo>
#include "position2d.h"
#include "character.h"
#include <string>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment