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
f561c095
authored
May 01, 2024
by
grlabu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
83d22f76
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
92 additions
and
0 deletions
Source/mainmenu.cpp
Source/mainmenu.cpp
0 → 100644
View file @
f561c095
#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
();
}
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