Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
krkane
/
Rüütli Vaev
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
1
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
09ba2eda
authored
May 01, 2024
by
grlabu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
b059b138
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
96 additions
and
0 deletions
Source/gamescreen.cpp
Source/gamescreen.cpp
0 → 100644
View file @
09ba2eda
// gamescreen.cpp
#include "Header.h"
#include "gameengine.h" // Include gameengine.h instead of gameengine.cpp
#include "gamescreen.h"
#include "ui_gamescreen.h"
#include <QDebug>
#include <QRandomGenerator>
// Rest of the implementation remains the same...
gamescreen
::
gamescreen
(
QWidget
*
parent
)
:
QMainWindow
(
parent
),
ui
(
new
Ui
::
gamescreen
)
{
int
randomIndex
=
QRandomGenerator
::
global
()
->
bounded
(
2
);
// Select a value based on the random number
if
(
randomIndex
==
0
)
{
correctChoice
=
TRAP_SCENARIO
;
}
else
{
correctChoice
=
POTION
;
}
ui
->
setupUi
(
this
);
ui
->
Outputtxt
->
setText
(
"
\n
Sa seisad koopas, kust avanevad kaks pimedat käiku. Üks"
" süngem kui teine.
\n
"
"Süda puperdades mõtled, millisesse neist suunduda.
\n\n
"
);
}
gamescreen
::~
gamescreen
()
{
delete
ui
;
}
void
gamescreen
::
on_Leftbutton_clicked
()
{
int
result
=
Move
(
correctChoice
);
handleMoveResult
(
result
);
emit
onGameFinished
();
}
void
gamescreen
::
on_Rightbutton_clicked
()
{
int
result
=
Move
(
correctChoice
);
// Pass correctChoice to Move function
handleMoveResult
(
result
);
emit
onGameFinished
();
}
void
gamescreen
::
handleMoveResult
(
int
result
)
{
if
(
result
==
LOSE_HP
)
{
ui
->
Outputtxt
->
setText
(
"Oops! Sa kukkusid lõksu ja kiskudes välja sellest kaotasid elusid"
);
emit
onTrap
();
}
else
if
(
result
==
GAIN_POTION
)
{
ui
->
Outputtxt
->
setText
(
"Sa leidsid endale lisa võlujoogi!"
);
emit
onPotionGain
();
}
else
if
(
result
==
SAVE_GAME
)
{
ui
->
Outputtxt
->
setText
(
"Game saved! Exiting..."
);
// Implement logic to save the game
}
else
{
ui
->
Outputtxt
->
setText
(
"Liikusid uude asukohta"
);
// Implement logic to move to a new location
}
}
void
gamescreen
::
handleTrap
()
{
playerHp
-=
LOSE_HP
;
// mainWindowInstance->setPlayerHp(mainWindowInstance->getPlayerHp() - LOSE_HP);
if
(
playerHp
<=
0
)
{
ui
->
Outputtxt
->
setText
(
"Mäng läbi! Kaotasid kahjuks kõik enda elud"
);
// Implement logic to end the game or display game over screen
}
else
{
ui
->
Outputtxt
->
append
(
QString
(
"Sinul on %1 elusid alles."
).
arg
(
playerHp
));
}
}
void
gamescreen
::
handlePotion
()
{
potionCount
+=
GAIN_POTION_COUNT
;
}
Write
Preview
Markdown
is supported
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