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
de8e8116
Commit
de8e8116
authored
Jun 21, 2022
by
Felix Huther
Browse files
Ui works so far
parent
fecf7083
Changes
44
Hide whitespace changes
Inline
Side-by-side
DungeonCrawler/DungeonGame/main.cpp
View file @
de8e8116
...
...
@@ -4,7 +4,7 @@
#include
"dungeoncrawler.h"
int
main
()
{
Level
*
level
=
new
Level
(
10
,
40
);
Level
*
level
=
new
Level
(
10
,
35
);
Character
*
myCharacter
=
new
Character
(
"metal"
);
level
->
placeCharacter
(
myCharacter
,
Position2D
(
2
,
2
));
...
...
FooDungeonCrawler/FooDungeonCrawler/FooDungeonCrawler.pro
View file @
de8e8116
QT
+=
core
gui
QT
+=
core
gui
QT
+=
testlib
greaterThan
(
QT_MAJOR_VERSION
,
4
)
:
QT
+=
widgets
CONFIG
+=
c
++
17
CONFIG
+=
c
++
11
#
You
can
make
your
code
fail
to
compile
if
it
uses
deprecated
APIs
.
#
In
order
to
do
so
,
uncomment
the
following
line
.
#
DEFINES
+=
QT_DISABLE_DEPRECATED_BEFORE
=
0
x060000
#
disables
all
the
APIs
deprecated
before
Qt
6.0
.
0
SOURCES
+=
\
..
/../
DungeonCrawler
/
DungeonGame
/
abstractui
.
cpp
\
..
/../
DungeonCrawler
/
DungeonGame
/
character
.
cpp
\
..
/../
DungeonCrawler
/
DungeonGame
/
controller
.
cpp
\
..
/../
DungeonCrawler
/
DungeonGame
/
door
.
cpp
\
..
/../
DungeonCrawler
/
DungeonGame
/
dungeoncrawler
.
cpp
\
..
/../
DungeonCrawler
/
DungeonGame
/
floor
.
cpp
\
..
/../
DungeonCrawler
/
DungeonGame
/
graphicalui
.
cpp
\
abstractui
.
cpp
\
character
.
cpp
\
controller
.
cpp
\
door
.
cpp
\
dungeoncrawler
.
cpp
\
floor
.
cpp
\
graphicalui
.
cpp
\
level
.
cpp
\
..
/../
DungeonCrawler
/
DungeonGame
/
main
.
cpp
\
..
/../
DungeonCrawler
/
DungeonGame
/
observerpassive
.
cpp
\
..
/../
DungeonCrawler
/
DungeonGame
/
pit
.
cpp
\
..
/../
DungeonCrawler
/
DungeonGame
/
portal
.
cpp
\
..
/../
DungeonCrawler
/
DungeonGame
/
position2d
.
cpp
\
..
/../
DungeonCrawler
/
DungeonGame
/
ramp
.
cpp
\
..
/../
DungeonCrawler
/
DungeonGame
/
subjectactiv
.
cpp
\
..
/../
DungeonCrawler
/
DungeonGame
/
switch
.
cpp
\
..
/../
DungeonCrawler
/
DungeonGame
/
terminalui
.
cpp
\
..
/../
DungeonCrawler
/
DungeonGame
/
testklasse
.
cpp
\
..
/../
DungeonCrawler
/
DungeonGame
/
tile
.
cpp
\
..
/../
DungeonCrawler
/
DungeonGame
/
wall
.
cpp
\
dialog
.
cpp
\
main
.
cpp
\
observerpassive
.
cpp
\
pit
.
cpp
\
portal
.
cpp
\
position2d
.
cpp
\
ramp
.
cpp
\
subjectactiv
.
cpp
\
switch
.
cpp
\
terminalui
.
cpp
\
tile
.
cpp
\
wall
.
cpp
\
dialog
.
cpp
\
mainwindow
.
cpp
HEADERS
+=
\
..
/../
DungeonCrawler
/
DungeonGame
/
abstractui
.
h
\
..
/../
DungeonCrawler
/
DungeonGame
/
character
.
h
\
..
/../
DungeonCrawler
/
DungeonGame
/
controller
.
h
\
..
/../
DungeonCrawler
/
DungeonGame
/
door
.
h
\
..
/../
DungeonCrawler
/
DungeonGame
/
dungeoncrawler
.
h
\
..
/../
DungeonCrawler
/
DungeonGame
/
floor
.
h
\
..
/../
DungeonCrawler
/
DungeonGame
/
graphicalui
.
h
\
abstractui
.
h
\
character
.
h
\
controller
.
h
\
door
.
h
\
dungeoncrawler
.
h
\
floor
.
h
\
graphicalui
.
h
\
level
.
h
\
..
/../
DungeonCrawler
/
DungeonGame
/
observerpassive
.
h
\
..
/../
DungeonCrawler
/
DungeonGame
/
pit
.
h
\
..
/../
DungeonCrawler
/
DungeonGame
/
portal
.
h
\
..
/../
DungeonCrawler
/
DungeonGame
/
position2d
.
h
\
..
/../
DungeonCrawler
/
DungeonGame
/
ramp
.
h
\
..
/../
DungeonCrawler
/
DungeonGame
/
subjectactiv
.
h
\
..
/../
DungeonCrawler
/
DungeonGame
/
switch
.
h
\
..
/../
DungeonCrawler
/
DungeonGame
/
terminalui
.
h
\
..
/../
DungeonCrawler
/
DungeonGame
/
testklasse
.
h
\
..
/../
DungeonCrawler
/
DungeonGame
/
tile
.
h
\
..
/../
DungeonCrawler
/
DungeonGame
/
wall
.
h
\
observerpassive
.
h
\
pit
.
h
\
portal
.
h
\
position2d
.
h
\
ramp
.
h
\
subjectactiv
.
h
\
switch
.
h
\
terminalui
.
h
\
tile
.
h
\
wall
.
h
\
dialog
.
h
\
mainwindow
.
h
...
...
FooDungeonCrawler/FooDungeonCrawler/abstractui.cpp
0 → 100644
View file @
de8e8116
#include
"abstractui.h"
;
AbstractUI
::
AbstractUI
(
Level
*
mCurrentLevel
)
:
mCurrentLevel
(
mCurrentLevel
)
{}
AbstractUI
::~
AbstractUI
()
{
mCurrentLevel
=
nullptr
;
delete
mCurrentLevel
;
}
void
AbstractUI
::
draw
(
Level
*
pLevel
)
{
}
FooDungeonCrawler/FooDungeonCrawler/abstractui.h
0 → 100644
View file @
de8e8116
#ifndef ABSTRACTUI_H
#define ABSTRACTUI_H
#include
"level.h"
#include
<iostream>
class
AbstractUI
{
public:
AbstractUI
(
Level
*
mCurrentLevel
);
virtual
~
AbstractUI
()
=
0
;
virtual
void
draw
(
Level
*
pLevel
)
=
0
;
protected:
Level
*
mCurrentLevel
;
};
#endif // ABSTRACTUI_H
FooDungeonCrawler/FooDungeonCrawler/character.cpp
0 → 100644
View file @
de8e8116
#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
;
}
FooDungeonCrawler/FooDungeonCrawler/character.h
0 → 100644
View file @
de8e8116
#ifndef CHARACTER_H
#define CHARACTER_H
#include
<string>
class
Tile
;
class
Character
{
//CONSTRUCTOR
public:
Character
(
std
::
string
texture
);
~
Character
()
=
default
;
//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 // CHARACTER_H
FooDungeonCrawler/FooDungeonCrawler/controller.cpp
0 → 100644
View file @
de8e8116
#include
"controller.h"
Controller
::
Controller
()
{
}
FooDungeonCrawler/FooDungeonCrawler/controller.h
0 → 100644
View file @
de8e8116
#ifndef CONTROLLER_H
#define CONTROLLER_H
class
Controller
{
public:
Controller
();
virtual
char
askMoveFromUser
()
=
0
;
};
#endif // CONTROLLER_H
FooDungeonCrawler/FooDungeonCrawler/dialog.cpp
View file @
de8e8116
#include
<QLabel>
#include
"dialog.h"
#include
"ui_dialog.h"
#include
<QLabel>
Dialog
::
Dialog
(
QWidget
*
parent
)
:
QDialog
(
parent
),
ui
(
new
Ui
::
Dialog
)
{
ui
->
setupUi
(
this
);
/*
ui->setupUi(this);
this->setStyleSheet("background-color: black;");
mEnterButton.load("../src/new_game_button.png");
mStartHintergrund.load("../src/startscreen.png");
...
...
@@ -24,7 +23,7 @@ Dialog::Dialog(QWidget *parent) :
//int width = mStartHintergrund.width();
//int height = mStartHintergrund.height();
//startBackground->setPixmap(mStartHintergrund.scaled(width,height,Qt::KeepAspectRatio));
*/
}
Dialog
::~
Dialog
()
...
...
@@ -34,8 +33,45 @@ Dialog::~Dialog()
void
Dialog
::
switchWindow
()
{
this
->
hide
();
mW
->
show
();
}
void
Dialog
::
setStartHintergrund
(
const
QPixmap
&
newStartHintergrund
)
{
mStartHintergrund
=
newStartHintergrund
;
}
void
Dialog
::
setEnterButton
(
const
QPixmap
&
newEnterButton
)
{
mEnterButton
=
newEnterButton
;
}
Ui
::
Dialog
*
Dialog
::
getUi
()
const
{
return
ui
;
}
QPixmap
&
Dialog
::
enterButton
()
{
return
mEnterButton
;
}
QPixmap
&
Dialog
::
startHintergrund
()
{
return
mStartHintergrund
;
}
void
Dialog
::
on_NeuesSpiel_clicked
()
{
this
->
hide
();
mW
->
show
();
}
void
Dialog
::
setMainWindow
(
MainWindow
*
newW
)
{
mW
=
newW
;
}
FooDungeonCrawler/FooDungeonCrawler/dialog.h
View file @
de8e8116
#ifndef DIALOG_H
#define DIALOG_H
#include
<QDialog>
#include
"mainwindow.h"
namespace
Ui
{
class
Dialog
;
...
...
@@ -16,14 +15,28 @@ public:
explicit
Dialog
(
QWidget
*
parent
=
nullptr
);
~
Dialog
();
bool
getButtonPressed
()
const
;
Ui
::
Dialog
*
getUi
()
const
;
QPixmap
&
enterButton
()
;
QPixmap
&
startHintergrund
();
void
setEnterButton
(
const
QPixmap
&
newEnterButton
);
void
setStartHintergrund
(
const
QPixmap
&
newStartHintergrund
);
void
setMainWindow
(
MainWindow
*
newW
);
private
slots
:
void
switchWindow
();
void
on_NeuesSpiel_clicked
();
private:
Ui
::
Dialog
*
ui
;
MainWindow
*
mW
;
QPixmap
mEnterButton
;
QPixmap
mStartHintergrund
;
...
...
FooDungeonCrawler/FooDungeonCrawler/dialog.ui
View file @
de8e8116
...
...
@@ -6,8 +6,8 @@
<rect>
<x>
0
</x>
<y>
0
</y>
<width>
12
56
</width>
<height>
7
92
</height>
<width>
12
00
</width>
<height>
7
00
</height>
</rect>
</property>
<property
name=
"windowTitle"
>
...
...
@@ -16,8 +16,8 @@
<widget
class=
"QPushButton"
name=
"NeuesSpiel"
>
<property
name=
"geometry"
>
<rect>
<x>
4
8
0
</x>
<y>
5
9
0
</y>
<x>
4
7
0
</x>
<y>
5
0
0
</y>
<width>
270
</width>
<height>
200
</height>
</rect>
...
...
@@ -29,7 +29,7 @@
<widget
class=
"QGraphicsView"
name=
"StartBild"
>
<property
name=
"geometry"
>
<rect>
<x>
2
0
</x>
<x>
0
</x>
<y>
0
</y>
<width>
1200
</width>
<height>
700
</height>
...
...
FooDungeonCrawler/FooDungeonCrawler/door.cpp
0 → 100644
View file @
de8e8116
#include
"door.h"
Door
::
Door
(
const
std
::
string
&
texture
,
Character
*
currentCharacter
,
const
Position2D
&
position
)
:
Tile
(
texture
,
currentCharacter
,
position
),
isClosed
(
true
)
{}
void
Door
::
update
()
{
if
(
isClosed
)
isClosed
=
false
;
}
Tile
*
Door
::
onEnter
(
Tile
*
fromTile
,
Character
*
who
)
{
if
(
this
->
getIsClosed
())
return
nullptr
;
else
return
this
;
}
bool
Door
::
moveTo
(
Tile
*
destTile
,
Character
*
who
)
{
if
(
isClosed
)
return
false
;
else
if
(
!
destTile
->
hasCharacter
()){
destTile
->
setCurrentCharacter
(
this
->
currentCharacter
);
currentCharacter
->
setCurrentTile
(
destTile
);
this
->
setCurrentCharacter
(
nullptr
);
return
true
;
};
return
false
;
}
Tile
*
Door
::
onLeave
(
Tile
*
destTile
,
Character
*
who
)
{
return
nullptr
;
}
bool
Door
::
getIsClosed
()
const
{
return
isClosed
;
}
FooDungeonCrawler/FooDungeonCrawler/door.h
0 → 100644
View file @
de8e8116
#ifndef DOOR_H
#define DOOR_H
#include
"tile.h"
#include
"observerpassive.h"
class
Door
:
public
Tile
,
public
ObserverPassive
{
public:
//CONSTRUCTOR AND DESTRUCTOR
Door
(
const
std
::
string
&
texture
,
Character
*
currentCharacter
,
const
Position2D
&
position
);
~
Door
()
=
default
;
// ObserverPassive interface
public:
void
update
()
override
;
// Tile interface
public:
Tile
*
onEnter
(
Tile
*
fromTile
,
Character
*
who
)
override
;
bool
moveTo
(
Tile
*
destTile
,
Character
*
who
)
override
;
Tile
*
onLeave
(
Tile
*
destTile
,
Character
*
who
)
override
;
bool
getIsClosed
()
const
;
private:
bool
isClosed
;
};
#endif // DOOR_H
FooDungeonCrawler/FooDungeonCrawler/dungeoncrawler.cpp
0 → 100644
View file @
de8e8116
#include
"dungeoncrawler.h"
#include
"graphicalui.h"
#include
<iostream>
DungeonCrawler
::
DungeonCrawler
(
Level
*
level
,
AbstractUI
*
UI
)
:
mCurrentLevel
(
level
),
mUserInterface
(
UI
){
}
DungeonCrawler
::~
DungeonCrawler
()
{
mCurrentLevel
=
nullptr
;
mUserInterface
=
nullptr
;
delete
mCurrentLevel
;
delete
mUserInterface
;
}
void
DungeonCrawler
::
ifSubjectNotify
(
Tile
*
tile
)
{
if
(
typeid
(
*
tile
)
==
typeid
(
Switch
)){
Switch
*
pSwitch
=
static_cast
<
Switch
*>
(
tile
);
pSwitch
->
notify
();
}
}
void
DungeonCrawler
::
ifPortalDestPortalLogic
(
Tile
*&
tile
,
Position2D
&
pos
)
{
if
(
typeid
(
*
tile
)
==
typeid
(
Portal
)){
Portal
*
portal
=
static_cast
<
Portal
*>
(
tile
);
tile
=
portal
->
getDestPortal
();
pos
=
tile
->
getPosition
();
tile
=
mCurrentLevel
->
getTileAtPos
(
pos
);
}
}
void
DungeonCrawler
::
play
()
{
while
(
true
)
{
bool
movPossible
;
char
movingDirection
;
Character
*
currentChar
=
mCurrentLevel
->
getCharacter
();
Tile
*
characterTile
=
currentChar
->
getCurrentTile
();
Position2D
characterPos
=
currentChar
->
getCurrentTile
()
->
getPosition
();
system
(
"CLS"
);
mUserInterface
->
draw
(
mCurrentLevel
);
GraphicalUi
*
graphUI
=
static_cast
<
GraphicalUi
*>
(
mUserInterface
);
movingDirection
=
graphUI
->
askMoveFromUser
();
switch
(
movingDirection
)
{
case
'w'
:
{
int
oneRowUp
=
characterPos
.
getRow
()
-
1
;
int
sameColumn
=
characterPos
.
getColumn
();
Position2D
onePosUp
(
oneRowUp
,
sameColumn
);
Tile
*
oneTileUp
=
mCurrentLevel
->
getTileAtPos
(
onePosUp
);
ifPortalDestPortalLogic
(
oneTileUp
,
onePosUp
);
movPossible
=
oneTileUp
->
onEnter
(
characterTile
,
currentChar
);
if
(
movPossible
)
{
characterTile
->
moveTo
(
oneTileUp
,
currentChar
);
ifSubjectNotify
(
oneTileUp
);
}
break
;
}
case
'a'
:{
int
sameRow
=
characterPos
.
getRow
();
int
oneColumnLeft
=
characterPos
.
getColumn
()
-
1
;
Position2D
onePosLeft
(
sameRow
,
oneColumnLeft
);
Tile
*
oneTileLeft
=
mCurrentLevel
->
getTileAtPos
(
onePosLeft
);
ifPortalDestPortalLogic
(
oneTileLeft
,
onePosLeft
);
movPossible
=
oneTileLeft
->
onEnter
(
characterTile
,
currentChar
);
if
(
movPossible
){
characterTile
->
moveTo
(
oneTileLeft
,
currentChar
);
ifSubjectNotify
(
oneTileLeft
);
}
break
;
}
case
's'
:{
int
oneRowDown
=
characterPos
.
getRow
()
+
1
;
int
sameColumn
=
characterPos
.
getColumn
();
Position2D
onePosDown
(
oneRowDown
,
sameColumn
);
Tile
*
oneTileDown
=
mCurrentLevel
->
getTileAtPos
(
onePosDown
);
ifPortalDestPortalLogic
(
oneTileDown
,
onePosDown
);
movPossible
=
oneTileDown
->
onEnter
(
characterTile
,
currentChar
);
if
(
movPossible
){
characterTile
->
moveTo
(
oneTileDown
,
currentChar
);
ifSubjectNotify
(
oneTileDown
);
}
break
;
}
case
'd'
:{
int
sameRow
=
characterPos
.
getRow
();
int
oneColumnRight
=
characterPos
.
getColumn
()
+
1
;
Position2D
onePosRight
(
sameRow
,
oneColumnRight
);
Tile
*
oneTileRight
=
mCurrentLevel
->
getTileAtPos
(
onePosRight
);
ifPortalDestPortalLogic
(
oneTileRight
,
onePosRight
);
if
(
typeid
(
*
characterTile
)
==
typeid
(
Pit
)){
}
movPossible
=
oneTileRight
->
onEnter
(
characterTile
,
currentChar
);
if
(
movPossible
)
{
characterTile
->
moveTo
(
oneTileRight
,
currentChar
);
ifSubjectNotify
(
oneTileRight
);
}
break
;
}
}
}
}
FooDungeonCrawler/FooDungeonCrawler/dungeoncrawler.h
0 → 100644
View file @
de8e8116
#ifndef DUNGEONCRAWLER_H
#define DUNGEONCRAWLER_H
#include
"level.h"
#include
"character.h"
#include
"abstractui.h"
#include
"terminalui.h"
class
AbstractUI
;
class
DungeonCrawler
{
public:
DungeonCrawler
(
Level
*
level
,
AbstractUI
*
UI
);
~
DungeonCrawler
();
void
play
();
void
ifSubjectNotify
(
Tile
*
tile
);
void
ifPortalDestPortalLogic
(
Tile
*&
tile
,
Position2D
&
pos
);