Commit f561c095 by grlabu

Upload New File

parent 83d22f76
Showing with 92 additions and 0 deletions
#include "mainmenu.h"
#include "gameengine.h"
#include "rules.h"
#include "ui_mainmenu.h"
#include "mainwindow.h"
#include <QFile>
#include <QDebug>
#include <QPixmap>
mainmenu::mainmenu(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::mainmenu)
{
ui->setupUi(this);
setCentralWidget(ui->centralwidget);
}
//C:\Users\labun\Downloads\mainmenuback.png
mainmenu::~mainmenu()
{
delete ui;
}
void mainmenu::on_Playbutton_clicked()
{
MainWindow *mainWindowInstance = new MainWindow();
mainWindowInstance->show();
this->close();
}
void mainmenu::on_Rulesbutton_clicked()
{
rules *rulesWindow = new rules(this);
rulesWindow->show();
}
void mainmenu::on_Exitbutton_clicked()
{
this->close();
}
void mainmenu::on_LoadLastGame_clicked()
{
// Open the file in read-only mode
QFile file(MainWindow_NS::GAME_SAVES_FILENAME);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
qDebug() << "Failed to open file for reading:" << file.errorString();
return;
}
// Create a QTextStream object to read from the file
QTextStream in(&file);
Player *p = new Player;
int enemiesDefeated = 0;
// Read the player's data and number of enemies defeated
QString line;
if (in.readLineInto(&line))
{
QStringList values = line.split(" ");
if (values.size() == 4)
{
p->health = values[0].toInt();
p->attack = values[1].toInt();
p->potionCount = values[2].toInt();
enemiesDefeated = values[3].toInt();
}
else
{
qDebug() << "Invalid data format in file";
file.close();
return;
}
}
else
{
qDebug() << "Failed to read player data";
file.close();
return;
}
// Close the file
file.close();
MainWindow *mainWindowInstance = new MainWindow(nullptr, p, enemiesDefeated);
mainWindowInstance->show();
this->close();
}
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