Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visualisation #2

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .idea/.gitignore

This file was deleted.

2 changes: 0 additions & 2 deletions .idea/Project.iml

This file was deleted.

4 changes: 0 additions & 4 deletions .idea/misc.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

118 changes: 118 additions & 0 deletions Button.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#include "Button.h"
#include "mutex"
#include "Global.h"
#include "sapper.h"

extern std::condition_variable cond;

QSize Button::sizeHint() const
{
QSize size = QToolButton::sizeHint();
size.rheight() += 20;
size.rwidth() = qMax(size.width(), size.height());
return size;
}

void Button::mineCheck() {
if (status_for_player != -1) {
win->left_decr();
}
status_for_player = -1;
setText(QString::fromStdString("*"));
win->check_win();
}

void Button::oncellClicked() {
if (win->get_first_move()) {
win->add_mines(win->get_mines(), x, y);
win->false_first_move();
}
if (status_for_player == -1) {
win->left_incr();
}
setText(QString::fromStdString(std::to_string(status)));
revealed = true;
if (status == -1) {
//cond.notify_all();
win->waiting_end();
}
if (status == 0)
win->check_zero(this->x, this->y);
status_for_player = status;
win->check_win();
}

void Button::cellClickedforrecursion() {
if (status_for_player == -1) {
win->left_incr();
}
setText(QString::fromStdString(std::to_string(status)));
revealed = true;
if (status == -1) {
win->waiting_end();
}
status_for_player = status;

win->check_win();
}

void Button::changeStatus(int new_st) {
status = new_st;
}

void Button::mousePressEvent(QMouseEvent *e) {
QString button = enumNameFromValue(e->button());
if (button == "LeftButton") {
oncellClicked();
}
else if (button == "RightButton") {
mineCheck();
}
}


int Button::get_status() {
return status;
}

int Button::get_status_for_player() {
return status_for_player;
}

bool Button::get_rev() {
return revealed;
}

QString Button::enumNameFromValue(const Qt::MouseButton button)
{
if (button == Qt::NoButton) return "NoButton";
if (button == Qt::LeftButton) return "LeftButton";
if (button == Qt::RightButton) return "RightButton";
if (button == Qt::MiddleButton) return "MiddleButton";
if (button == Qt::BackButton) return "BackButton";
if (button == Qt::ForwardButton) return "ForwardButton";
if (button == Qt::TaskButton) return "TaskButton";
if (button == Qt::ExtraButton4) return "ExtraButton4";
if (button == Qt::ExtraButton5) return "ExtraButton5";
if (button == Qt::ExtraButton6) return "ExtraButton6";
if (button == Qt::ExtraButton7) return "ExtraButton7";
if (button == Qt::ExtraButton8) return "ExtraButton8";
if (button == Qt::ExtraButton9) return "ExtraButton9";
if (button == Qt::ExtraButton10) return "ExtraButton10";
if (button == Qt::ExtraButton11) return "ExtraButton11";
if (button == Qt::ExtraButton12) return "ExtraButton12";
if (button == Qt::ExtraButton13) return "ExtraButton13";
if (button == Qt::ExtraButton14) return "ExtraButton14";
if (button == Qt::ExtraButton15) return "ExtraButton15";
if (button == Qt::ExtraButton16) return "ExtraButton16";
if (button == Qt::ExtraButton17) return "ExtraButton17";
if (button == Qt::ExtraButton18) return "ExtraButton18";
if (button == Qt::ExtraButton19) return "ExtraButton19";
if (button == Qt::ExtraButton20) return "ExtraButton20";
if (button == Qt::ExtraButton21) return "ExtraButton21";
if (button == Qt::ExtraButton22) return "ExtraButton22";
if (button == Qt::ExtraButton23) return "ExtraButton23";
if (button == Qt::ExtraButton24) return "ExtraButton24";
qDebug("QMouseShortcutEntry::addShortcut contained Invalid Qt::MouseButton value");
return "NoButton";
}
47 changes: 47 additions & 0 deletions Button.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#ifndef BUTTON_H
#define BUTTON_H

#include <QToolButton>
#include <QColor>
#include <QMouseEvent>
//#include "mainwindow.h"

class sapper;

class Button : public QToolButton
{
Q_OBJECT
int status = 0;
int status_for_player = 0;
int x = 0;
int y = 0;
bool revealed = false;
sapper* win =nullptr;
QColor num_colors[10];
protected:
void mousePressEvent(QMouseEvent *e) override;
QString enumNameFromValue(const Qt::MouseButton button);

public:
explicit Button(int st = 0, int x_ = 0, int y_ = 0, sapper *par_win = nullptr, QWidget *parent = nullptr)
: QToolButton(parent), win(par_win)
{
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
status = st;
x = x_;
y = y_;
//setText(text);
}

QSize sizeHint() const override;
void changeStatus(int new_st);
int get_status();
int get_status_for_player();
bool get_rev();
public slots:
void oncellClicked();
void mineCheck();
void cellClickedforrecursion();
};

#endif // BUTTON_H
27 changes: 0 additions & 27 deletions CMakeLists.txt

This file was deleted.

58 changes: 58 additions & 0 deletions GameWindow.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>GameWindow</class>
<widget class="QDialog" name="GameWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>493</width>
<height>391</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<widget class="QPushButton" name="YesButton">
<property name="geometry">
<rect>
<x>50</x>
<y>210</y>
<width>131</width>
<height>121</height>
</rect>
</property>
<property name="text">
<string>Agree</string>
</property>
</widget>
<widget class="QPushButton" name="NoButton">
<property name="geometry">
<rect>
<x>300</x>
<y>210</y>
<width>131</width>
<height>121</height>
</rect>
</property>
<property name="text">
<string>Disagree</string>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>50</x>
<y>20</y>
<width>441</width>
<height>151</height>
</rect>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>
1 change: 1 addition & 0 deletions Global.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "Global.h"
11 changes: 11 additions & 0 deletions Global.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef GLOBAL_H
#define GLOBAL_H

#include <mutex>
#include <condition_variable>

extern std::condition_variable cond;
extern int n;


#endif // GLOBAL_H
68 changes: 68 additions & 0 deletions Lastone.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

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=0x060000 # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
Button.cpp \
Global.cpp \
arithmetic_problem.cpp \
arithmeticwindow.cpp \
controller.cpp \
game.cpp \
gamewindow.cpp \
main.cpp \
mainwindow.cpp \
resultwindow.cpp \
sapermain.cpp \
saperwindow.cpp \
sapper.cpp \
second_main.cpp \
settingswindow.cpp \
uml.cpp \
view.cpp \
windowwithgame.cpp

HEADERS += \
Button.h \
Global.h \
arithmetic_problem.h \
arithmeticwindow.h \
controller.h \
game.h \
gamewindow.h \
global_struct_of_game.h \
json.hpp \
mainwindow.h \
resultwindow.h \
sapermain.h \
saperwindow.h \
sapper.h \
second_main.h \
settingswindow.h \
uml.h \
view.h \
windowwithgame.h

FORMS += \
arithmeticwindow.ui \
gamewindow.ui \
mainwindow.ui \
resultwindow.ui \
saperwindow.ui \
sapper.ui \
settingswindow.ui \
windowwithgame.ui

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

RESOURCES += \
resource.qrc
Loading