Commit c4974011 authored by Felix Huther's avatar Felix Huther
Browse files

small changes

parent 806a76a1
......@@ -25,7 +25,6 @@ int Character::move()
int direction = {};
std::cout << "What direction you want to move ?\n";
std::cin >> direction;
return direction;
}
......
#include "dungeoncrawler.h"
DungeonCrawler::DungeonCrawler(AbstractUI * abstractUi, Level* currentLevel)
:abstractUi(abstractUi),currentLevel(currentLevel)
:abstractUi(abstractUi)
{
this->levels.push_back(currentLevel);
}
void DungeonCrawler::play()
{
}
......@@ -12,7 +12,7 @@ public:
private:
AbstractUI* abstractUi;
Level* currentLevel;
std::vector<Level*> levels;
};
......
......@@ -7,19 +7,26 @@ Floor::Floor(std::string& texture,Position2D& position)
}
//checks out if its possilbe to enter
Tile *Floor::onEnter(Tile *fromTile, Character *who)
{
//checks if field and desination is empty
if(this->getTexture() == "wall"){
return nullptr;
}
return this;
}
//checks out if its possible to leave
Tile *Floor::onLeave(Tile *destTile, Character *who)
{
return this;
}
//actually moves the character
bool Floor::moveTo(Tile *destTile, Character *who)
{
if(destTile->getCurrentCharacter() == nullptr){
if(destTile != nullptr){
this->setCurrentCharacter(nullptr);
destTile->setCurrentCharacter(who);
return true;
......
......@@ -40,7 +40,7 @@ std::vector<std::vector<Tile *>> Level::getField() const
return field;
}
void Level::setLevel1()
void Level::setLevelStructure()
{
std::string wall = "wall";
std::string portal = "portal";
......@@ -51,11 +51,15 @@ void Level::setLevel1()
field.push_back(vec);
for(int j = 0 ; j < width;j++)
{
if(i == 0 && j < width){
//draws wall arround the field
if((i == 0 && j < width) ||
j == 0 || j == width-1 ||
i == height-1
){
Position2D pos = Position2D(i,j);
Wall* wallPointer = new Wall(wall,pos);
field.at(i).push_back(wallPointer);
}
} //fills field with floor
else {Position2D pos = Position2D(i,j);
Floor* floorPointer= new Floor(floor,pos);
field.at(i).push_back(floorPointer);
......
......@@ -19,9 +19,7 @@ public:
void placeCharacter(Character* character, Position2D& position);
std::vector<std::vector<Tile*>> getField() const;
void setLevel1();
void setLevelStructure();
int getHeight() const;
......
#include <iostream>
#include "level.h"
#include "terminalui.h"
#include "dungeoncrawler.h"
using namespace std;
int main()
{
TerminalUI* termUI = new TerminalUI();
Level* level = new Level(10,10);
level->setLevel1();
TerminalUI term;
term.draw(level);
level->setLevelStructure();
termUI->interface();
// DungeonCrawler* dungeonCraler = new DungeonCrawler(termUI,level);
termUI->draw(level);
return 0;
......
......@@ -11,24 +11,33 @@ Tile *Portal::getDestination() const
return destination;
}
//checks out if its possilbe to enter
Tile *Portal::onEnter(Tile *fromTile, Character *who)
{
//checks if field and desination is empty
if(!this->currentCharacter && !this->destination->getCurrentCharacter()){
this->destination->setCurrentCharacter(who);
fromTile->setCurrentCharacter(nullptr);
return this->destination;
if(this->getTexture() == "wall"){
return nullptr;
}
return nullptr;
return this->destination;
}
//checks out if its possible to leave
Tile *Portal::onLeave(Tile *destTile, Character *who)
{
return this;
}
//actually moves the character
bool Portal::moveTo(Tile *destTile, Character *who)
{
if(destTile != nullptr){
destTile->setCurrentCharacter(who);
this->setCurrentCharacter(nullptr);
return true;
}
return false;
}
#include "position2D.h"
Position2D::Position2D(int &row, int &column)
Position2D::Position2D(int row, int column)
:row(row),column(column)
{
......
......@@ -5,7 +5,7 @@
class Position2D
{
public:
Position2D(int& row, int& column);
Position2D(int row, int column);
......
#include "terminalui.h"
using namespace std;
TerminalUI::TerminalUI()
{
......@@ -13,12 +13,40 @@ void TerminalUI::draw(Level *lvl)
for (auto& item : inner) {
std::string texture = item->getTexture();
if(texture == "floor") std::cout << "." ;
if(item->getCurrentCharacter()) std::cout << "X";
else if(texture == "floor") std::cout << "." ;
else if(texture == "wall") std::cout << "#";
else if(texture == "portal")std::cout<< "O";
else std::cout << "X";
else std::cout << "something went wrong";
}
std::cout << std::endl;
}
}
void TerminalUI::interface()
{
cout << "Welcome to the DungeonCrawler Game\n";
while(true){
int UserOperation = {};
cout<<"Tell me your desires\n"
<< "1: Create a field\n"
<< "2: Enter the Dungeon\n"
<< "0: Exit\n";
cin >> UserOperation;
switch (UserOperation) {
case 1: int height,width;
cout << "height\n>";
cin >> height;
cout << "\n width\n>";
cin >> width;
std::cout << endl;
Level* level = new Level(height,width);
level->setLevelStructure();
}
}
}
......@@ -10,6 +10,8 @@ public:
// AbstractUI interface
void draw(Level *lvl) override;
void interface();
void levelInterface();
};
#endif // TERMINALUI_H
......@@ -11,6 +11,7 @@ class Tile
{
public:
explicit Tile(std::string& texture, Position2D& position);
Tile(Tile& tile);
virtual ~Tile();
//CHARACTER SPECIFIC
......
......@@ -8,17 +8,3 @@ Wall::Wall(std::string &texture, Position2D &position)
}
Tile *Wall::onEnter(Tile *fromTile, Character *who)
{
return nullptr;
}
Tile *Wall::onLeave(Tile *destTile, Character *who)
{
return nullptr;
}
bool Wall::moveTo(Tile *destTile, Character *who)
{
return false;
}
......@@ -12,10 +12,9 @@ public:
Wall(std::string& texture, Position2D& position);
// Tile interface
Tile *onEnter(Tile *fromTile, Character *who)override;
Tile *onLeave(Tile *destTile, Character *who)override;
bool moveTo(Tile *destTile, Character *who)override;
Tile *onEnter(Tile *fromTile, Character *who)override{return nullptr;};
Tile *onLeave(Tile *destTile, Character *who)override{return nullptr;};
bool moveTo(Tile *destTile, Character *who)override{return false;};
};
#endif // WALL_H
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