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

first steps into Pratika 1, ask for character.move(), its confusing because we...

first steps into Pratika 1, ask for character.move(), its confusing because we have to do this in the UI and not in the character obj
parent 48e56c9f
# This file is used to ignore files which are generated
# ----------------------------------------------------------------------------
*~
*.autosave
*.a
*.core
*.moc
*.o
*.obj
*.orig
*.rej
*.so
*.so.*
*_pch.h.cpp
*_resource.rc
*.qm
.#*
*.*#
core
!core/
tags
.DS_Store
.directory
*.debug
Makefile*
*.prl
*.app
moc_*.cpp
ui_*.h
qrc_*.cpp
Thumbs.db
*.res
*.rc
/.qmake.cache
/.qmake.stash
# qtcreator generated files
*.pro.user*
# xemacs temporary files
*.flc
# Vim temporary files
.*.swp
# Visual Studio generated files
*.ib_pdb_index
*.idb
*.ilk
*.pdb
*.sln
*.suo
*.vcproj
*vcproj.*.*.user
*.ncb
*.sdf
*.opensdf
*.vcxproj
*vcxproj.*
# MinGW generated files
*.Debug
*.Release
# Python byte code
*.pyc
# Binaries
# --------
*.dll
*.exe
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += \
abstractui.cpp \
character.cpp \
dungeoncrawler.cpp \
floor.cpp \
level.cpp \
main.cpp \
portal.cpp \
position2D.cpp \
tile.cpp \
wall.cpp
HEADERS += \
abstractui.h \
character.h \
dungeoncrawler.h \
floor.h \
level.h \
portal.h \
position2D.h \
tile.h \
wall.h
#include "abstractui.h"
AbstractUI::AbstractUI()
{
}
#ifndef ABSTRACTUI_H
#define ABSTRACTUI_H
#pragma once
class AbstractUI
{
public:
AbstractUI();
};
#endif // ABSTRACTUI_H
#include "character.h"
Character::Character(std::string &texture)
:texture(texture)
{
}
Character::~Character()
{
if(currentTile){
currentTile = nullptr;
delete currentTile;
}
}
const std::string &Character::getTexture() const
{
return texture;
}
char Character::move()
{
}
void Character::setCurrentTile(Tile *newCurrentTile)
{
currentTile = newCurrentTile;
}
#ifndef CHARACTER_H
#define CHARACTER_H
#pragma once
#include "tile.h"
class Tile;
class Character
{
public:
Character(std::string& texture);
~Character();
const std::string &getTexture() const;
char move();
void setCurrentTile(Tile *newCurrentTile);
private:
Tile* currentTile;
std::string texture;
};
#endif // CHARACTER_H
#include "dungeoncrawler.h"
DungeonCrawler::DungeonCrawler()
{
}
#ifndef DUNGEONCRAWLER_H
#define DUNGEONCRAWLER_H
#pragma once
class DungeonCrawler
{
public:
DungeonCrawler();
};
#endif // DUNGEONCRAWLER_H
#include "floor.h"
Floor::Floor(std::string& texture,Position2D& position)
:Tile(texture,position)
{
}
Tile *Floor::onEnter(Tile *fromTile, Character *who)
{
return this;
}
Tile *Floor::onLeave(Tile *destTile, Character *who)
{
return this;
}
bool Floor::moveTo(Tile *destTile, Character *who)
{
if(destTile->getCurrentCharacter() == nullptr){
this->setCurrentCharacter(nullptr);
destTile->setCurrentCharacter(who);
return true;
}
else return false;
}
#ifndef FLOOR_H
#define FLOOR_H
#pragma once
#include "tile.h"
//NORMAL TILE NO EVENT WHEN ENTER OR LEAVE
class Floor : public Tile
{
public:
Floor(std::string& texture, class Position2D& position);
// Tile interface
public:
Tile *onEnter(Tile *fromTile, Character *who) override;
Tile *onLeave(Tile *destTile, Character *who) override;
bool moveTo(Tile *destTile, Character *who) override;
};
#endif // FLOOR_H
#include "level.h"
Level::Level(int height, int width)
:height(height),width(width)
{
}
Level::Level(Level &other)
:height(other.height),width(other.width),field(other.field)
{
}
Level::~Level()
{
for (auto& inner : field) {
for (auto& item : inner) {
item = nullptr;
delete item;
}
}
}
Tile *Level::getTile(Position2D &position) const
{
Tile* tilePointer = field.at(position.getRow()).at(position.getColumn());
return tilePointer;
}
void Level::placeCharacter(Character *character, Position2D &position)
{
Tile* index = field.at(position.getRow()).at(position.getColumn());
index->setCurrentCharacter(character);
}
#ifndef LEVEL_H
#define LEVEL_H
#pragma once
#include "character.h"
#include <vector>
class Level
{
public:
Level(int height,int width);
Level(Level& other);
~Level();
Tile* getTile(Position2D& position) const;
void placeCharacter(Character* character, Position2D& position);
private:
const int height;
const int width;
Character* character;
std::vector<std::vector<Tile*>> field;
};
#endif // LEVEL_H
#include <iostream>
#include "tile.h"
#include "wall.h"
#include "position2D.h"
using namespace std;
int main()
{
int pos = 1 ;
int pos2 = 2;
std::string wallmat = "#";
Position2D posM = Position2D(pos,pos2);
// Wall(wall,Position(pos,pos2));
Wall wal = Wall(wallmat,posM);
std::cout << wal.getCurrentCharacter();
cout << "Hello World!" << endl;
return 0;
}
#include "portal.h"
Portal::Portal(std::string &texture, Position2D &position, Tile* destination)
:Tile(texture,position),destination(destination)
{
}
Tile *Portal::getDestination() const
{
return destination;
}
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;
}
return nullptr;
}
Tile *Portal::onLeave(Tile *destTile, Character *who)
{
return this;
}
bool Portal::moveTo(Tile *destTile, Character *who)
{
}
#ifndef PORTAL_H
#define PORTAL_H
#pragma once
#include "tile.h"
//ALWAYS PAIR OF PORTALS
//WILL PORT THE CHARACTER TO THE OTHER PORTAL
class Portal: public Tile
{
public:
Portal(std::string& texture, class Position2D& position, Tile* destination);
Tile *getDestination() const;
// Tile interface
Tile *onEnter(Tile *fromTile, Character *who) override;
Tile *onLeave(Tile *destTile, Character *who)override;
bool moveTo(Tile *destTile, Character *who) override;
private:
Tile* destination;
};
#endif // PORTAL_H
#include "position2D.h"
Position2D::Position2D(int &row, int &column)
:row(row),column(column)
{
}
int Position2D::getRow() const
{
return row;
}
int Position2D::getColumn() const
{
return column;
}
#ifndef POSITION2D_H
#define POSITION2D_H
#pragma once
class Position2D
{
public:
Position2D(int& row, int& column);
int getRow() const;
int getColumn() const;
private:
int row;
int column;
};
#endif // POSITION_H
#include "tile.h"
Tile::Tile(std::string &texture, Position2D &position)
:currentCharacter(nullptr),texture(texture),position(position)
{
}
Tile::~Tile()
{
currentCharacter = nullptr;
delete currentCharacter;
//std::cout << "Object destroyed" << std::endl;
}
Character *Tile::getCurrentCharacter() const
{
return currentCharacter;
}
void Tile::setCurrentCharacter(Character *newCurrentCharacter)
{
currentCharacter = newCurrentCharacter;
}
bool Tile::hasCharacter() const
{
return currentCharacter;
}
const std::string &Tile::getTexture() const
{
return texture;
}
const Position2D &Tile::getPosition() const
{
return position;
}
#ifndef TILE_H
#define TILE_H
#pragma once
#include <iostream>
#include "position2D.h"
#include "character.h"
class Character;
//inheritants to WALL PORTAL and FLOOR
class Tile
{
public:
explicit Tile(std::string& texture, class Position2D& position);
virtual ~Tile();
//CHARACTER SPECIFIC
Character *getCurrentCharacter() const;
void setCurrentCharacter(Character *newCurrentCharacter);
bool hasCharacter() const;
//ENTER AND LEAVE TILE
virtual bool moveTo(Tile* destTile, Character* who) = 0;
virtual Tile* onEnter(Tile* fromTile, Character* who) = 0;
virtual Tile* onLeave(Tile* destTile, Character* who) = 0;
//TEXTURE AND POSITION SPECIFIC
const std::string &getTexture() const;
const Position2D &getPosition() const;
protected:
Character* currentCharacter;
std::string texture;
Position2D position;
};
#endif // TILE_H
#include "wall.h"
Wall::Wall(std::string &texture, Position2D &position)
:Tile(texture,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;
}
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