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
398c049f
Commit
398c049f
authored
May 19, 2022
by
Felix Huther
Browse files
Praktika1 Working
parent
735769a4
Changes
48
Hide whitespace changes
Inline
Side-by-side
Praktika/NEWpraktika1/.idea/.gitignore
0 → 100644
View file @
398c049f
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
Praktika/NEWpraktika1/.idea/NEWpraktika1.iml
0 → 100644
View file @
398c049f
<?xml version="1.0" encoding="UTF-8"?>
<module
classpath=
"CMake"
type=
"CPP_MODULE"
version=
"4"
/>
\ No newline at end of file
Praktika/NEWpraktika1/.idea/misc.xml
0 → 100644
View file @
398c049f
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"CMakeWorkspace"
PROJECT_DIR=
"$PROJECT_DIR$"
/>
</project>
\ No newline at end of file
Praktika/NEWpraktika1/.idea/modules.xml
0 → 100644
View file @
398c049f
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"ProjectModuleManager"
>
<modules>
<module
fileurl=
"file://$PROJECT_DIR$/.idea/NEWpraktika1.iml"
filepath=
"$PROJECT_DIR$/.idea/NEWpraktika1.iml"
/>
</modules>
</component>
</project>
\ No newline at end of file
Praktika/NEWpraktika1/.idea/vcs.xml
0 → 100644
View file @
398c049f
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"VcsDirectoryMappings"
>
<mapping
directory=
"$PROJECT_DIR$/../.."
vcs=
"Git"
/>
</component>
</project>
\ No newline at end of file
Praktika/NEWpraktika1/AbstractUI.cpp
0 → 100644
View file @
398c049f
//
// Created by felix on 19/05/2022.
//
#include
"AbstractUI.h"
AbstractUI
::
AbstractUI
(
Level
*
mCurrentLevel
)
:
mCurrentLevel
(
mCurrentLevel
)
{}
void
AbstractUI
::
draw
(
Level
*
pLevel
)
{
}
Praktika/NEWpraktika1/AbstractUI.h
0 → 100644
View file @
398c049f
//
// Created by felix on 19/05/2022.
//
#ifndef NEWPRAKTIKA1_ABSTRACTUI_H
#define NEWPRAKTIKA1_ABSTRACTUI_H
#include
"Level.h"
#include
<iostream>
class
AbstractUI
{
public:
AbstractUI
(
Level
*
mCurrentLevel
);
virtual
void
draw
(
Level
*
pLevel
)
=
0
;
virtual
char
askMoveFromUser
()
=
0
;
protected:
Level
*
mCurrentLevel
;
};
#endif //NEWPRAKTIKA1_ABSTRACTUI_H
Praktika/NEWpraktika1/CMakeLists.txt
0 → 100644
View file @
398c049f
cmake_minimum_required
(
VERSION 3.22
)
project
(
NEWpraktika1
)
set
(
CMAKE_CXX_STANDARD 17
)
add_executable
(
NEWpraktika1
main.cpp
Tile.cpp Tile.h
Floor.cpp Floor.h
Portal.cpp Portal.h
Wall.cpp Wall.h
Character.cpp Character.h
Level.cpp Level.h
DungeonCrawler.cpp DungeonCrawler.h
AbstractUI.cpp AbstractUI.h
Position2D.cpp Position2D.h TerminalUI.cpp TerminalUI.h
)
Praktika/NEWpraktika1/Character.cpp
0 → 100644
View file @
398c049f
//
// Created by felix on 19/05/2022.
//
#include
"Character.h"
Character
::
Character
(
std
::
string
texture
)
{}
const
std
::
string
&
Character
::
getTexture
()
const
{
return
texture
;
}
Tile
*
Character
::
getCurrentTile
()
const
{
return
currentTile
;
}
void
Character
::
setCurrentTile
(
Tile
*
currentTile
)
{
Character
::
currentTile
=
currentTile
;
}
Praktika/NEWpraktika1/Character.h
0 → 100644
View file @
398c049f
//
// Created by felix on 19/05/2022.
//
#ifndef NEWPRAKTIKA1_CHARACTER_H
#define NEWPRAKTIKA1_CHARACTER_H
#include
<string>
#include
"Tile.h"
class
Tile
;
class
Character
{
//CONSTRUCTOR
public:
Character
(
std
::
string
texture
);
//MEMBER VARIABLES
private:
std
::
string
texture
;
Tile
*
currentTile
;
//GETTER AND SETTER
public:
void
setCurrentTile
(
Tile
*
currentTile
);
Tile
*
getCurrentTile
()
const
;
const
std
::
string
&
getTexture
()
const
;
};
#endif //NEWPRAKTIKA1_CHARACTER_H
Praktika/NEWpraktika1/DungeonCrawler.cpp
0 → 100644
View file @
398c049f
//
// Created by felix on 19/05/2022.
//
#include
"DungeonCrawler.h"
DungeonCrawler
::
DungeonCrawler
(
Level
*
level
,
AbstractUI
*
UI
)
:
mCurrentLevel
(
level
),
mUserInterface
(
UI
){
}
void
DungeonCrawler
::
play
()
{
while
(
true
)
{
Character
*
currentChar
=
mCurrentLevel
->
getCharacter
();
mUserInterface
->
draw
(
mCurrentLevel
);
char
movingDirection
=
mUserInterface
->
askMoveFromUser
();
Tile
*
characterTile
=
currentChar
->
getCurrentTile
();
Position2D
characterPos
=
currentChar
->
getCurrentTile
()
->
getPosition
();
switch
(
movingDirection
)
{
case
'w'
:
{
int
oneRowUp
=
characterPos
.
getRow
()
-
1
;
int
sameColumn
=
characterPos
.
getColumn
();
Position2D
onePosUp
(
oneRowUp
,
sameColumn
);
Tile
*
oneTileUp
=
mCurrentLevel
->
getTileAtPos
(
onePosUp
);
bool
movPossible
=
oneTileUp
->
onEnter
(
characterTile
,
currentChar
);
if
(
movPossible
)
{
characterTile
->
moveTo
(
oneTileUp
,
currentChar
);
mCurrentLevel
->
placeCharacter
(
currentChar
,
onePosUp
);
}
break
;
}
case
'a'
:{
int
sameRow
=
characterPos
.
getRow
();
int
oneColumnLeft
=
characterPos
.
getColumn
()
-
1
;
Position2D
onePosRight
(
sameRow
,
oneColumnLeft
);
Tile
*
oneTileLeft
=
mCurrentLevel
->
getTileAtPos
(
onePosRight
);
bool
movPossible
=
oneTileLeft
->
onEnter
(
characterTile
,
currentChar
);
if
(
movPossible
){
characterTile
->
moveTo
(
oneTileLeft
,
currentChar
);
mCurrentLevel
->
placeCharacter
(
currentChar
,
onePosRight
);
}
break
;
}
case
's'
:{
int
oneRowDown
=
characterPos
.
getRow
()
+
1
;
int
sameColumn
=
characterPos
.
getColumn
();
Position2D
onePosRight
(
oneRowDown
,
sameColumn
);
Tile
*
oneTileDown
=
mCurrentLevel
->
getTileAtPos
(
onePosRight
);
bool
movPossible
=
oneTileDown
->
onEnter
(
characterTile
,
currentChar
);
if
(
movPossible
){
characterTile
->
moveTo
(
oneTileDown
,
currentChar
);
mCurrentLevel
->
placeCharacter
(
currentChar
,
onePosRight
);
}
break
;
}
case
'd'
:{
int
sameRow
=
characterPos
.
getRow
();
int
oneColumnRight
=
characterPos
.
getColumn
()
+
1
;
Position2D
onePosRight
(
sameRow
,
oneColumnRight
);
Tile
*
oneTileUp
=
mCurrentLevel
->
getTileAtPos
(
onePosRight
);
bool
movPossible
=
oneTileUp
->
onEnter
(
characterTile
,
currentChar
);
if
(
movPossible
)
{
characterTile
->
moveTo
(
oneTileUp
,
currentChar
);
mCurrentLevel
->
placeCharacter
(
currentChar
,
onePosRight
);
}
break
;
}
}
}
}
\ No newline at end of file
Praktika/NEWpraktika1/DungeonCrawler.h
0 → 100644
View file @
398c049f
//
// Created by felix on 19/05/2022.
//
#ifndef NEWPRAKTIKA1_DUNGEONCRAWLER_H
#define NEWPRAKTIKA1_DUNGEONCRAWLER_H
#include
"Level.h"
#include
"Character.h"
#include
"AbstractUI.h"
class
AbstractUI
;
class
DungeonCrawler
{
public:
DungeonCrawler
(
Level
*
level
,
AbstractUI
*
UI
);
void
play
();
private:
Level
*
mCurrentLevel
;
AbstractUI
*
mUserInterface
;
};
#endif //NEWPRAKTIKA1_DUNGEONCRAWLER_H
Praktika/NEWpraktika1/Floor.cpp
0 → 100644
View file @
398c049f
//
// Created by felix on 19/05/2022.
//
#include
"Floor.h"
Floor
::
Floor
(
const
std
::
string
&
texture
,
Character
*
currentCharacter
,
const
Position2D
&
position
)
:
Tile
(
texture
,
currentCharacter
,
position
)
{}
Tile
*
Floor
::
onEnter
(
Tile
*
fromTile
,
Character
*
who
)
{
return
this
;
}
bool
Floor
::
moveTo
(
Tile
*
destTile
,
Character
*
who
)
{
if
(
!
destTile
->
hasCharacter
()){
destTile
->
setCurrentCharacter
(
this
->
currentCharacter
);
this
->
setCurrentCharacter
(
nullptr
);
return
true
;
};
return
false
;
}
Tile
*
Floor
::
onLeave
(
Tile
*
destTile
,
Character
*
who
)
{
return
this
;
}
Praktika/NEWpraktika1/Floor.h
0 → 100644
View file @
398c049f
//
// Created by felix on 19/05/2022.
//
#ifndef NEWPRAKTIKA1_FLOOR_H
#define NEWPRAKTIKA1_FLOOR_H
#include
<string>
#include
"Tile.h"
class
Floor
:
public
Tile
{
public:
Floor
(
const
std
::
string
&
texture
,
Character
*
currentCharacter
,
const
Position2D
&
position
);
Tile
*
onEnter
(
Tile
*
fromTile
,
Character
*
who
)
override
;
bool
moveTo
(
Tile
*
destTile
,
Character
*
who
)
override
;
Tile
*
onLeave
(
Tile
*
destTile
,
Character
*
who
)
override
;
};
#endif //NEWPRAKTIKA1_FLOOR_H
Praktika/NEWpraktika1/Level.cpp
0 → 100644
View file @
398c049f
//
// Created by felix on 19/05/2022.
//
#include
"Level.h"
Level
::
Level
(
int
height
,
int
width
)
:
mheight
(
height
),
mwidth
(
width
)
{
setStructure
();
}
const
int
Level
::
getHeight
()
const
{
return
mheight
;
}
const
int
Level
::
getWidth
()
const
{
return
mwidth
;
}
Level
::~
Level
()
{
mcharacter
=
nullptr
;
for
(
auto
&
inner
:
mLevel
)
{
for
(
auto
&
item
:
inner
)
{
item
=
nullptr
;
delete
item
;
}
}
}
void
Level
::
placeCharacter
(
Character
*
character
,
Position2D
position
)
{
int
row
=
position
.
getRow
();
int
column
=
position
.
getColumn
();
mcharacter
=
character
;
mLevel
.
at
(
row
).
at
(
column
)
->
setCurrentCharacter
(
character
);
character
->
setCurrentTile
(
mLevel
.
at
(
row
).
at
(
column
));
}
Tile
*
Level
::
getTileAtPos
(
Position2D
position
)
{
int
row
=
position
.
getRow
();
int
column
=
position
.
getColumn
();
return
mLevel
.
at
(
row
).
at
(
column
);
}
const
Tile
*
Level
::
constGetTileAtPos
(
Position2D
position
)
{
int
row
=
position
.
getRow
();
int
column
=
position
.
getColumn
();
return
mLevel
.
at
(
row
).
at
(
column
);
}
const
std
::
vector
<
std
::
vector
<
Tile
*>>
&
Level
::
getMLevel
()
const
{
return
mLevel
;
}
Character
*
Level
::
getCharacter
()
const
{
return
mcharacter
;
}
Position2D
Level
::
getCharacterPosition
()
{
}
void
Level
::
setStructure
()
{
std
::
string
stwall
=
"wall"
;
std
::
string
stportal
=
"portal"
;
std
::
string
stfloor
=
"floor"
;
for
(
int
i
=
0
;
i
<
mheight
;
i
++
){
std
::
vector
<
Tile
*>
vec
;
mLevel
.
push_back
(
vec
);
for
(
int
j
=
0
;
j
<
mwidth
;
j
++
)
{
//draws wall arround the field
if
((
i
==
0
&&
j
<
mwidth
)
||
j
==
0
||
j
==
mwidth
-
1
||
i
==
mheight
-
1
){
Position2D
pos
=
Position2D
(
i
,
j
);
Wall
*
wallPointer
=
new
Wall
(
stwall
,
nullptr
,
pos
);
mLevel
.
at
(
i
).
push_back
(
wallPointer
);
}
//fills field with floor
else
{
Position2D
pos
=
Position2D
(
i
,
j
);
Floor
*
floorPointer
=
new
Floor
(
stfloor
,
nullptr
,
pos
);
mLevel
.
at
(
i
).
push_back
(
floorPointer
);
}
}
}
}
Praktika/NEWpraktika1/Level.h
0 → 100644
View file @
398c049f
//
// Created by felix on 19/05/2022.
//
#ifndef NEWPRAKTIKA1_LEVEL_H
#define NEWPRAKTIKA1_LEVEL_H
#include
<vector>
#include
"Tile.h"
#include
"Portal.h"
#include
"Wall.h"
#include
"Floor.h"
#include
"Position2D.h"
class
Level
{
//MEMBER VARIABLES
private:
const
int
mwidth
;
const
int
mheight
;
Character
*
mcharacter
;
std
::
vector
<
std
::
vector
<
Tile
*>>
mLevel
;
void
setStructure
();
//CONSTRUCTOR
public:
virtual
~
Level
();
explicit
Level
(
int
height
,
int
width
);
//GETTER AND SETTER
public:
[[
nodiscard
]]
const
int
getHeight
()
const
;
[[
nodiscard
]]
const
int
getWidth
()
const
;
Tile
*
getTileAtPos
(
Position2D
position
);
const
Tile
*
constGetTileAtPos
(
Position2D
position
);
Character
*
getCharacter
()
const
;
Position2D
getCharacterPosition
();
void
placeCharacter
(
Character
*
character
,
Position2D
position
);
const
std
::
vector
<
std
::
vector
<
Tile
*>>
&
getMLevel
()
const
;
};
#endif //NEWPRAKTIKA1_LEVEL_H
Praktika/NEWpraktika1/Portal.cpp
0 → 100644
View file @
398c049f
//
// Created by felix on 19/05/2022.
//
#include
"Portal.h"
Portal
::
Portal
(
const
std
::
string
&
texture
,
Character
*
currentCharacter
,
const
Position2D
&
position
,
Tile
*
destPortal
)
:
Tile
(
texture
,
currentCharacter
,
position
),
destPortal
(
destPortal
)
{}
Tile
*
Portal
::
onEnter
(
Tile
*
fromTile
,
Character
*
who
)
{
return
destPortal
;
}
bool
Portal
::
moveTo
(
Tile
*
destTile
,
Character
*
who
)
{
if
(
!
destTile
->
hasCharacter
()){
destPortal
->
setCurrentCharacter
(
who
);
who
->
setCurrentTile
(
destPortal
);
this
->
setCurrentCharacter
(
nullptr
);
return
true
;
}
else
return
false
;
}
Tile
*
Portal
::
onLeave
(
Tile
*
destTile
,
Character
*
who
)
{
return
this
;
}
Praktika/NEWpraktika1/Portal.h
0 → 100644
View file @
398c049f
//
// Created by felix on 19/05/2022.
//
#ifndef NEWPRAKTIKA1_PORTAL_H
#define NEWPRAKTIKA1_PORTAL_H
#include
<string>
#include
"Tile.h"
class
Portal
:
public
Tile
{
public:
Portal
(
const
std
::
string
&
texture
,
Character
*
currentCharacter
,
const
Position2D
&
position
,
Tile
*
destPortal
);
Tile
*
onEnter
(
Tile
*
fromTile
,
Character
*
who
)
override
;
bool
moveTo
(
Tile
*
destTile
,
Character
*
who
)
override
;
Tile
*
onLeave
(
Tile
*
destTile
,
Character
*
who
)
override
;
private:
Tile
*
destPortal
;
};
#endif //NEWPRAKTIKA1_PORTAL_H
Praktika/
P
ratika1/
DungeonCrawlerBase/p
osition2D.cpp
→
Praktika/
NEWp
ra
k
tika1/
P
osition2D.cpp
View file @
398c049f
#include
"position2D.h"
//
// Created by felix on 19/05/2022.
//
#include
"Position2D.h"
Position2D
::
Position2D
(
int
row
,
int
column
)
:
row
(
row
),
column
(
column
)
{
:
row
(
row
),
column
(
column
){}
}
int
Position2D
::
getRow
()
const
{
int
Position2D
::
getRow
()
const
{
return
row
;
}
int
Position2D
::
getColumn
()
const
{
int
Position2D
::
getColumn
()
const
{
return
column
;
}
Praktika/
P
ratika1/
DungeonCrawlerBase/p
osition2D.h
→
Praktika/
NEWp
ra
k
tika1/
P
osition2D.h
View file @
398c049f
#ifndef POSITION2D_H
#define POSITION2D_H
#pragma once
//
// Created by felix on 19/05/2022.
//
class
Position2D
{
public:
Position2D
(
int
row
,
int
column
);
#ifndef NEWPRAKTIKA1_POSITION2D_H
#define NEWPRAKTIKA1_POSITION2D_H
int
getRow
()
const
;
int
getColumn
()
const
;
class
Position2D
{
public:
Position2D
(
int
row
,
int
column
);
private:
int
row
;
int
column
;
public:
int
getRow
()
const
;
int
getColumn
()
const
;
};
#endif // POSITION_H
#endif //NEWPRAKTIKA1_POSITION2D_H
Prev
1
2
3
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