Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Felix Huther
Programmieren2
Commits
7daefb54
Commit
7daefb54
authored
Jun 20, 2022
by
Felix Huther
Browse files
portals work like they should
parent
044c72b2
Changes
22
Expand all
Hide whitespace changes
Inline
Side-by-side
DungeonCrawler/DungeonGame/abstractui.cpp
View file @
7daefb54
#include
"
A
bstract
UI
.h"
#include
"
a
bstract
ui
.h"
;
AbstractUI
::
AbstractUI
(
Level
*
mCurrentLevel
)
:
mCurrentLevel
(
mCurrentLevel
)
{}
:
mCurrentLevel
(
mCurrentLevel
)
{}
AbstractUI
::~
AbstractUI
()
{
mCurrentLevel
=
nullptr
;
delete
mCurrentLevel
;
}
void
AbstractUI
::
draw
(
Level
*
pLevel
)
{
}
...
...
DungeonCrawler/DungeonGame/abstractui.h
View file @
7daefb54
...
...
@@ -6,6 +6,8 @@
class
AbstractUI
{
public:
AbstractUI
(
Level
*
mCurrentLevel
);
virtual
~
AbstractUI
()
=
0
;
virtual
void
draw
(
Level
*
pLevel
)
=
0
;
virtual
char
askMoveFromUser
()
=
0
;
...
...
DungeonCrawler/DungeonGame/character.h
View file @
7daefb54
...
...
@@ -9,6 +9,7 @@ class Character {
//CONSTRUCTOR
public:
Character
(
std
::
string
texture
);
~
Character
()
=
default
;
//MEMBER VARIABLES
...
...
DungeonCrawler/DungeonGame/dungeoncrawler.cpp
View file @
7daefb54
...
...
@@ -6,19 +6,29 @@ DungeonCrawler::DungeonCrawler(Level *level, AbstractUI* UI)
}
DungeonCrawler
::~
DungeonCrawler
()
{
mCurrentLevel
=
nullptr
;
mUserInterface
=
nullptr
;
delete
mCurrentLevel
;
delete
mUserInterface
;
}
void
DungeonCrawler
::
play
()
{
while
(
true
)
{
bool
movPossible
;
char
movingDirection
;
Character
*
currentChar
=
mCurrentLevel
->
getCharacter
();
mUserInterface
->
draw
(
mCurrentLevel
);
char
movingDirection
=
mUserInterface
->
askMoveFromUser
();
Tile
*
characterTile
=
currentChar
->
getCurrentTile
();
Position2D
characterPos
=
currentChar
->
getCurrentTile
()
->
getPosition
();
system
(
"CLS"
);
mUserInterface
->
draw
(
mCurrentLevel
);
movingDirection
=
mUserInterface
->
askMoveFromUser
();
switch
(
movingDirection
)
{
case
'w'
:
{
int
oneRowUp
=
characterPos
.
getRow
()
-
1
;
...
...
@@ -38,6 +48,7 @@ void DungeonCrawler::play() {
}
movPossible
=
oneTileUp
->
onEnter
(
characterTile
,
currentChar
);
if
(
movPossible
)
{
characterTile
->
moveTo
(
oneTileUp
,
currentChar
);
}
...
...
DungeonCrawler/DungeonGame/dungeoncrawler.h
View file @
7daefb54
...
...
@@ -10,6 +10,7 @@ class DungeonCrawler {
public:
DungeonCrawler
(
Level
*
level
,
AbstractUI
*
UI
);
~
DungeonCrawler
();
void
play
();
private:
...
...
DungeonCrawler/DungeonGame/floor.cpp
View file @
7daefb54
#include
"floor.h"
Floor
::
Floor
(
const
std
::
string
&
texture
,
Character
*
currentCharacter
,
const
Position2D
&
position
)
:
Tile
(
texture
,
currentCharacter
,
position
)
{}
:
Tile
(
texture
,
currentCharacter
,
position
)
{}
Floor
::~
Floor
()
{
currentCharacter
=
nullptr
;
delete
currentCharacter
;
}
Tile
*
Floor
::
onEnter
(
Tile
*
fromTile
,
Character
*
who
)
{
return
this
;
...
...
DungeonCrawler/DungeonGame/floor.h
View file @
7daefb54
...
...
@@ -7,6 +7,7 @@
class
Floor
:
public
Tile
{
public:
Floor
(
const
std
::
string
&
texture
,
Character
*
currentCharacter
,
const
Position2D
&
position
);
~
Floor
();
Tile
*
onEnter
(
Tile
*
fromTile
,
Character
*
who
)
override
;
bool
moveTo
(
Tile
*
destTile
,
Character
*
who
)
override
;
...
...
DungeonCrawler/DungeonGame/level.cpp
View file @
7daefb54
...
...
@@ -75,10 +75,25 @@ void Level::setStructure() {
mLevel
.
at
(
i
).
push_back
(
wallpointer
);
}
//fills field with floor
else
if
(
i
==
4
&&
j
==
4
)
{
Tile
*
destPortal
=
new
Floor
(
stfloor
,
nullptr
,
Position2D
(
8
,
8
));
Tile
*
portalPointer
=
new
Portal
(
stportal
,
nullptr
,
pos
,
destPortal
);
mLevel
.
at
(
i
).
push_back
(
portalPointer
);
else
if
((
i
==
4
&&
j
==
4
)
||
(
i
==
8
&&
j
==
8
))
{
Tile
*
portalOne
;
Tile
*
portalTwo
;
if
(
i
==
4
)
{
portalOne
=
new
Portal
(
stfloor
,
nullptr
,
pos
,
nullptr
);
mLevel
.
at
(
i
).
push_back
(
portalOne
);
}
else
{
portalTwo
=
new
Portal
(
stportal
,
nullptr
,
pos
,
portalOne
);
Portal
*
portalPointer
=
static_cast
<
Portal
*>
(
portalOne
);
portalPointer
->
setDestPortal
(
portalTwo
);
mLevel
.
at
(
i
).
push_back
(
portalTwo
);
}
}
else
{
...
...
DungeonCrawler/DungeonGame/level.h
View file @
7daefb54
...
...
@@ -21,7 +21,7 @@ private:
//CONSTRUCTOR
public:
virtual
~
Level
();
~
Level
();
explicit
Level
(
int
height
,
int
width
);
//GETTER AND SETTER
...
...
DungeonCrawler/DungeonGame/portal.cpp
View file @
7daefb54
#include
"portal.h"
Portal
::
Portal
(
const
std
::
string
&
texture
,
Character
*
currentCharacter
,
const
Position2D
&
position
,
Tile
*
destPortal
)
:
Tile
(
texture
,
currentCharacter
,
position
),
destPortal
(
destPortal
)
{}
:
Tile
(
texture
,
currentCharacter
,
position
),
destPortal
(
destPortal
),
firstEnter
(
false
)
{}
Portal
::~
Portal
()
{
currentCharacter
=
nullptr
;
delete
currentCharacter
;
destPortal
=
nullptr
;
delete
destPortal
;
}
Tile
*
Portal
::
onEnter
(
Tile
*
fromTile
,
Character
*
who
)
{
return
destPortal
;
}
bool
Portal
::
moveTo
(
Tile
*
destTile
,
Character
*
who
)
{
if
(
!
destTile
->
hasCharac
ter
()
){
if
(
firstEn
ter
){
destPortal
->
setCurrentCharacter
(
who
);
destTile
->
setCurrentCharacter
(
nullptr
);
who
->
setCurrentTile
(
destPortal
);
this
->
setCurrentCharacter
(
nullptr
);
return
true
;
}
else
return
false
;
return
true
;
else
{
destTile
->
setCurrentCharacter
(
who
);
this
->
setCurrentCharacter
(
nullptr
);
who
->
setCurrentTile
(
destTile
);
return
true
;
}
}
...
...
@@ -23,8 +38,13 @@ Tile *Portal::onLeave(Tile *destTile, Character *who) {
return
this
;
}
Tile
*
Portal
::
getDestPortal
()
const
Tile
*
Portal
::
getDestPortal
()
{
return
destPortal
;
}
void
Portal
::
setDestPortal
(
Tile
*
newDestPortal
)
{
destPortal
=
newDestPortal
;
}
DungeonCrawler/DungeonGame/portal.h
View file @
7daefb54
...
...
@@ -9,6 +9,7 @@
class
Portal
:
public
Tile
{
public:
Portal
(
const
std
::
string
&
texture
,
Character
*
currentCharacter
,
const
Position2D
&
position
,
Tile
*
destPortal
);
~
Portal
();
Tile
*
onEnter
(
Tile
*
fromTile
,
Character
*
who
)
override
;
...
...
@@ -16,10 +17,17 @@ public:
Tile
*
onLeave
(
Tile
*
destTile
,
Character
*
who
)
override
;
Tile
*
getDestPortal
()
const
;
Tile
*
getDestPortal
();
void
setDestPortal
(
Tile
*
newDestPortal
);
void
setFirstEnter
(
bool
newFirstEnter
);
bool
getFirstEnter
()
const
;
private:
Tile
*
destPortal
;
bool
firstEnter
;
};
...
...
DungeonCrawler/DungeonGame/terminalui.cpp
View file @
7daefb54
...
...
@@ -6,6 +6,12 @@
TerminalUI
::
TerminalUI
(
Level
*
mCurrentLevel
)
:
AbstractUI
(
mCurrentLevel
)
{}
TerminalUI
::~
TerminalUI
()
{
mCurrentLevel
=
nullptr
;
delete
mCurrentLevel
;
}
void
TerminalUI
::
draw
(
Level
*
pLevel
)
{
std
::
vector
<
std
::
vector
<
Tile
*>>
field
=
mCurrentLevel
->
getMLevel
();
...
...
DungeonCrawler/DungeonGame/terminalui.h
View file @
7daefb54
...
...
@@ -6,6 +6,10 @@
class
TerminalUI
:
public
AbstractUI
{
public:
TerminalUI
(
Level
*
mCurrentLevel
);
~
TerminalUI
();
void
draw
(
Level
*
pLevel
)
override
;
char
askMoveFromUser
()
override
;
...
...
DungeonCrawler/DungeonGame/tile.cpp
View file @
7daefb54
...
...
@@ -3,7 +3,13 @@
#include
<string>
Tile
::
Tile
(
std
::
string
texture
,
Character
*
currentCharacter
,
Position2D
position
)
:
texture
(
texture
),
currentCharacter
(
currentCharacter
),
position
(
position
){}
:
texture
(
texture
),
currentCharacter
(
currentCharacter
),
position
(
position
){}
Tile
::~
Tile
()
{
currentCharacter
=
nullptr
;
delete
currentCharacter
;
}
const
std
::
string
&
Tile
::
getTexture
()
const
{
return
texture
;
...
...
@@ -21,3 +27,4 @@ bool Tile::hasCharacter() {
if
(
currentCharacter
==
nullptr
)
return
false
;
else
return
true
;
}
DungeonCrawler/DungeonGame/tile.h
View file @
7daefb54
...
...
@@ -10,6 +10,7 @@ class Character;
class
Tile
{
public:
Tile
(
std
::
string
texture
,
Character
*
currentCharacter
,
Position2D
position
);
virtual
~
Tile
();
protected:
std
::
string
texture
;
...
...
DungeonCrawler/DungeonGame/wall.cpp
View file @
7daefb54
...
...
@@ -2,7 +2,13 @@
#include
"wall.h"
Wall
::
Wall
(
const
std
::
string
&
texture
,
Character
*
currentCharacter
,
const
Position2D
&
position
)
:
Tile
(
texture
,
currentCharacter
,
position
)
{}
:
Tile
(
texture
,
currentCharacter
,
position
)
{}
Wall
::~
Wall
()
{
currentCharacter
=
nullptr
;
delete
currentCharacter
;
}
Tile
*
Wall
::
onLeave
(
Tile
*
destTile
,
Character
*
who
)
{
return
nullptr
;
...
...
DungeonCrawler/DungeonGame/wall.h
View file @
7daefb54
...
...
@@ -8,6 +8,7 @@
class
Wall
:
public
Tile
{
public:
Wall
(
const
std
::
string
&
texture
,
Character
*
currentCharacter
,
const
Position2D
&
position
);
~
Wall
();
Tile
*
onEnter
(
Tile
*
fromTile
,
Character
*
who
)
override
;
bool
moveTo
(
Tile
*
destTile
,
Character
*
who
)
override
;
...
...
HoersaalUebungen/29.04.2022_Ref_Hoersaal/Hoersaal/Hoersaal.pro.user
View file @
7daefb54
This diff is collapsed.
Click to expand it.
HoersaalUebungen/29.04.2022_Ref_Hoersaal/Hoersaal/main.cpp
View file @
7daefb54
...
...
@@ -19,6 +19,5 @@ int main()
for
(
auto
members
:
hoersaal
){
members
->
PrintName
();
}
return
0
;
}
HoersaalUebungenRoth/UebungFussballSpieler/Sportler/consoleui.h
View file @
7daefb54
...
...
@@ -16,6 +16,7 @@ public:
private:
const
Sportverein
mSportverein
;
mutable
int
mutableInt
;
// AbstractUI interface
...
...
Prev
1
2
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment