Commit 09ba2eda by grlabu

Upload New File

parent b059b138
Showing with 96 additions and 0 deletions
// 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("\nSa 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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment