├── Resources ├── music │ ├── game.mp3 │ └── home.mp3 └── images │ ├── bomb.png │ ├── brick.png │ ├── icon.png │ ├── menu.png │ ├── wall.png │ ├── button.png │ ├── ground.png │ ├── player1.png │ ├── player2.png │ └── result.png ├── src ├── views │ ├── block.cpp │ ├── block.h │ ├── Label.h │ ├── wall.h │ ├── Label.cpp │ ├── Brick.h │ ├── Brick.cpp │ ├── wall.cpp │ ├── TextField.h │ ├── Button.h │ ├── Button.cpp │ └── TextField.cpp ├── Home │ ├── Result.h │ ├── Home.h │ ├── Game.h │ ├── Result.cpp │ ├── Home.cpp │ └── Game.cpp └── Player │ ├── Player.h │ ├── Bomb.h │ ├── Player.cpp │ └── Bomb.cpp ├── main.cpp ├── resources.qrc ├── README.md ├── CMakeLists.txt └── .gitignore /Resources/music/game.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArmanTaheriGhaleTaki/playing-with-fire2/HEAD/Resources/music/game.mp3 -------------------------------------------------------------------------------- /Resources/music/home.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArmanTaheriGhaleTaki/playing-with-fire2/HEAD/Resources/music/home.mp3 -------------------------------------------------------------------------------- /Resources/images/bomb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArmanTaheriGhaleTaki/playing-with-fire2/HEAD/Resources/images/bomb.png -------------------------------------------------------------------------------- /Resources/images/brick.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArmanTaheriGhaleTaki/playing-with-fire2/HEAD/Resources/images/brick.png -------------------------------------------------------------------------------- /Resources/images/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArmanTaheriGhaleTaki/playing-with-fire2/HEAD/Resources/images/icon.png -------------------------------------------------------------------------------- /Resources/images/menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArmanTaheriGhaleTaki/playing-with-fire2/HEAD/Resources/images/menu.png -------------------------------------------------------------------------------- /Resources/images/wall.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArmanTaheriGhaleTaki/playing-with-fire2/HEAD/Resources/images/wall.png -------------------------------------------------------------------------------- /src/views/block.cpp: -------------------------------------------------------------------------------- 1 | #include "block.h" 2 | 3 | Block::Block(int width , int height):QGraphicsPixmapItem() 4 | { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /Resources/images/button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArmanTaheriGhaleTaki/playing-with-fire2/HEAD/Resources/images/button.png -------------------------------------------------------------------------------- /Resources/images/ground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArmanTaheriGhaleTaki/playing-with-fire2/HEAD/Resources/images/ground.png -------------------------------------------------------------------------------- /Resources/images/player1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArmanTaheriGhaleTaki/playing-with-fire2/HEAD/Resources/images/player1.png -------------------------------------------------------------------------------- /Resources/images/player2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArmanTaheriGhaleTaki/playing-with-fire2/HEAD/Resources/images/player2.png -------------------------------------------------------------------------------- /Resources/images/result.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArmanTaheriGhaleTaki/playing-with-fire2/HEAD/Resources/images/result.png -------------------------------------------------------------------------------- /src/views/block.h: -------------------------------------------------------------------------------- 1 | #ifndef BLOCK_H 2 | #define BLOCK_H 3 | 4 | #include 5 | 6 | class Block: public QGraphicsPixmapItem{ 7 | 8 | public: 9 | Block(int width , int height); 10 | }; 11 | 12 | #endif // BLOCK_H 13 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "src/Home/Home.h" 4 | 5 | int main(int argc, char *argv[]) { 6 | QApplication a(argc, argv); 7 | (new Home())->show(); 8 | return QApplication::exec(); 9 | } 10 | -------------------------------------------------------------------------------- /src/views/Label.h: -------------------------------------------------------------------------------- 1 | #ifndef RESOURCES_QRC_LABEL_H 2 | #define RESOURCES_QRC_LABEL_H 3 | 4 | #include 5 | class Label: public QGraphicsTextItem { 6 | public: 7 | Label(int fontSize,const char* color); 8 | }; 9 | 10 | 11 | #endif //RESOURCES_QRC_LABEL_H 12 | -------------------------------------------------------------------------------- /src/views/wall.h: -------------------------------------------------------------------------------- 1 | #ifndef WALL_H 2 | #define WALL_H 3 | 4 | #include"block.h" 5 | 6 | class Wall:public Block 7 | { 8 | private: 9 | int width{}; 10 | int height{}; 11 | public: 12 | Wall(int width , int height); 13 | 14 | QRectF boundingRect() const override; 15 | }; 16 | 17 | #endif // WALL_H 18 | -------------------------------------------------------------------------------- /src/Home/Result.h: -------------------------------------------------------------------------------- 1 | #ifndef PLYING_WITH_FIRE2_RESULT_H 2 | #define PLYING_WITH_FIRE2_RESULT_H 3 | 4 | #include 5 | 6 | 7 | class Result : public QGraphicsView 8 | { 9 | public: 10 | 11 | Result(QString winner,int scoreOfPlayer1,int scoreOfPlayer2); 12 | }; 13 | 14 | 15 | #endif //PLYING_WITH_FIRE2_RESULT_H 16 | -------------------------------------------------------------------------------- /src/views/Label.cpp: -------------------------------------------------------------------------------- 1 | #include "Label.h" 2 | #include 3 | #include 4 | Label::Label(int fontSize,const char* color) { 5 | 6 | 7 | setDefaultTextColor(QColor(color)); 8 | QFont font; 9 | font.setPixelSize(fontSize); 10 | font.setBold(true); 11 | setFont(font); 12 | 13 | 14 | document()->setDocumentMargin(4); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/views/Brick.h: -------------------------------------------------------------------------------- 1 | #ifndef PLYING_WITH_FIRE2_BRICK_H 2 | #define PLYING_WITH_FIRE2_BRICK_H 3 | 4 | 5 | #include "block.h" 6 | 7 | class Brick: public Block 8 | { 9 | private: 10 | int width{}; 11 | int height{}; 12 | public: 13 | Brick(int width,int height); 14 | 15 | QRectF boundingRect() const override; 16 | }; 17 | 18 | 19 | #endif //PLYING_WITH_FIRE2_BRICK_H 20 | -------------------------------------------------------------------------------- /src/views/Brick.cpp: -------------------------------------------------------------------------------- 1 | #include "Brick.h" 2 | 3 | Brick::Brick(int width, int height) :width{width},height{height},Block(width, height) 4 | { 5 | QPixmap pixmap(":/images/brick"); 6 | pixmap = pixmap.scaled(width,height); 7 | setPixmap(pixmap); 8 | } 9 | 10 | QRectF Brick::boundingRect() const { 11 | auto brick = QGraphicsPixmapItem::boundingRect(); 12 | brick.setWidth(width); 13 | brick.setHeight(height); 14 | return QGraphicsPixmapItem::boundingRect(); 15 | } 16 | -------------------------------------------------------------------------------- /src/views/wall.cpp: -------------------------------------------------------------------------------- 1 | #include "wall.h" 2 | 3 | Wall::Wall(int width , int height):width{width},height{height},Block(width , height) 4 | { 5 | QPixmap pixmap(":/images/wall"); 6 | pixmap = pixmap.scaled(width,height); 7 | setPixmap(pixmap); 8 | } 9 | 10 | QRectF Wall::boundingRect() const { 11 | 12 | auto wall = QGraphicsPixmapItem::boundingRect(); 13 | wall.setWidth(width); 14 | wall.setHeight(height); 15 | return QGraphicsPixmapItem::boundingRect(); 16 | } 17 | -------------------------------------------------------------------------------- /src/Home/Home.h: -------------------------------------------------------------------------------- 1 | #ifndef PLYING_WITH_FIRE2_HOME_H 2 | #define PLYING_WITH_FIRE2_HOME_H 3 | 4 | #include 5 | #include "../views/TextField.h" 6 | #include 7 | 8 | class Home : public QGraphicsView { 9 | 10 | Q_OBJECT 11 | private: 12 | TextField *textField_player1; 13 | TextField *textField_player2; 14 | TextField *textField_hp; 15 | public: 16 | Home(); 17 | 18 | public slots: 19 | void onGameStart(); 20 | 21 | }; 22 | 23 | 24 | #endif //PLYING_WITH_FIRE2_HOME_H 25 | -------------------------------------------------------------------------------- /src/views/TextField.h: -------------------------------------------------------------------------------- 1 | #ifndef PLYING_WITH_FIRE2_TEXTFIELD_H 2 | #define PLYING_WITH_FIRE2_TEXTFIELD_H 3 | 4 | 5 | #include 6 | 7 | class TextField : public QGraphicsTextItem { 8 | 9 | private: 10 | int width{}; 11 | int height{}; 12 | public: 13 | TextField(int width, int height); 14 | 15 | QRectF boundingRect() const override; 16 | 17 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; 18 | 19 | }; 20 | 21 | 22 | 23 | #endif //PLYING_WITH_FIRE2_TEXTFIELD_H 24 | -------------------------------------------------------------------------------- /src/views/Button.h: -------------------------------------------------------------------------------- 1 | #ifndef RESOURCES_QRC_BUTTON_H 2 | #define RESOURCES_QRC_BUTTON_H 3 | 4 | #include 5 | 6 | class Button: public QGraphicsTextItem { 7 | Q_OBJECT 8 | 9 | private: 10 | int width{}; 11 | int height{}; 12 | public: 13 | Button(int width,int height); 14 | 15 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; 16 | 17 | protected: 18 | void mousePressEvent(QGraphicsSceneMouseEvent *event) override; 19 | 20 | signals: 21 | void onPress(); 22 | 23 | }; 24 | 25 | 26 | 27 | 28 | #endif //RESOURCES_QRC_BUTTON_H 29 | -------------------------------------------------------------------------------- /src/Player/Player.h: -------------------------------------------------------------------------------- 1 | #ifndef PLYING_WITH_FIRE2_PLAYER_H 2 | #define PLYING_WITH_FIRE2_PLAYER_H 3 | 4 | #include 5 | 6 | class Player : public QGraphicsPixmapItem { 7 | private: 8 | 9 | int width{}; 10 | int height{}; 11 | int HitPoint{5}; 12 | 13 | public: 14 | 15 | int NumberOfBombs{}; 16 | int score{0}; 17 | 18 | void DecreaseHealth(); 19 | void increaseScore(int amountOfIncreasing); 20 | Player(const char* icon,int width,int height,int NumberOfBombs); 21 | QRectF boundingRect() const override; 22 | 23 | void setHitPoint(int hp); 24 | int getHitPoint(); 25 | 26 | 27 | }; 28 | 29 | 30 | #endif //PLYING_WITH_FIRE2_PLAYER_H 31 | -------------------------------------------------------------------------------- /src/Home/Game.h: -------------------------------------------------------------------------------- 1 | #ifndef RESOURCES_QRC_GAME_H 2 | #define RESOURCES_QRC_GAME_H 3 | 4 | #include 5 | #include "../Player/Player.h" 6 | #include "../views/wall.h" 7 | #include "../Player/Bomb.h" 8 | #include "../views/Brick.h" 9 | 10 | 11 | class Game : public QGraphicsView{ 12 | 13 | public: 14 | Game(QString name_player1,QString name_player2,int hp); 15 | QList players{}; 16 | QList walls{}; 17 | QList bricks{}; 18 | QString checkWinner(); 19 | QString name_player1{}; 20 | QString name_player2{}; 21 | 22 | protected: 23 | void keyPressEvent(QKeyEvent *event) override; 24 | 25 | public slots: 26 | void onResult(); 27 | }; 28 | 29 | 30 | #endif //RESOURCES_QRC_GAME_H 31 | -------------------------------------------------------------------------------- /resources.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | Resources/images/menu.png 4 | Resources/images/icon.png 5 | Resources/images/wall.png 6 | Resources/images/ground.png 7 | Resources/images/brick.png 8 | Resources/images/button.png 9 | Resources/images/player1.png 10 | Resources/images/player2.png 11 | Resources/images/bomb.png 12 | Resources/music/game.mp3 13 | Resources/images/result.png 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/Player/Bomb.h: -------------------------------------------------------------------------------- 1 | #ifndef PLYING_WITH_FIRE2_BOMB_H 2 | #define PLYING_WITH_FIRE2_BOMB_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "Player.h" 9 | #include "../views/Brick.h" 10 | 11 | class Bomb : public QObject, public QGraphicsPixmapItem { 12 | Q_OBJECT 13 | 14 | private: 15 | int width{}; 16 | int height{}; 17 | int pos_x{}; 18 | int pos_y{}; 19 | QString PlayerRecognizer{}; 20 | QTimer *BombTimer; 21 | QList *bricks; 22 | QList *players; 23 | 24 | public: 25 | 26 | 27 | Bomb(int posX, int posY, int width, int height, QList *bricks,QList *players,QString PlayerRecognizer); 28 | 29 | signals: 30 | void onPlayerKilled(); 31 | public slots: 32 | 33 | void Exploding(); 34 | 35 | }; 36 | 37 | 38 | #endif //PLYING_WITH_FIRE2_BOMB_H 39 | -------------------------------------------------------------------------------- /src/Player/Player.cpp: -------------------------------------------------------------------------------- 1 | #include "Player.h" 2 | #include "../Home/Game.h" 3 | 4 | #include 5 | 6 | Player::Player(const char* icon,int width,int height,int NumberOfBombs): width(width),height(height),NumberOfBombs{NumberOfBombs} { 7 | 8 | QPixmap pixmap(icon); 9 | pixmap = pixmap.scaled(width,height); 10 | setPixmap(pixmap); 11 | 12 | } 13 | 14 | QRectF Player::boundingRect() const { 15 | 16 | auto player = QGraphicsPixmapItem::boundingRect(); 17 | player.setWidth(width); 18 | player.setHeight(height); 19 | return QGraphicsPixmapItem::boundingRect(); 20 | } 21 | void Player::DecreaseHealth() 22 | { 23 | HitPoint--; 24 | } 25 | 26 | void Player::increaseScore(int amountOfIncreasing) 27 | { 28 | score+=amountOfIncreasing; 29 | } 30 | 31 | void Player::setHitPoint(int hp) 32 | { 33 | HitPoint = hp; 34 | } 35 | 36 | int Player::getHitPoint() 37 | { 38 | return HitPoint; 39 | } -------------------------------------------------------------------------------- /src/views/Button.cpp: -------------------------------------------------------------------------------- 1 | #include "Button.h" 2 | #include 3 | #include 4 | #include 5 | 6 | 7 | Button::Button(int width, int height): width(width),height(height),QGraphicsTextItem() { 8 | 9 | 10 | 11 | QFont font; 12 | font.setPixelSize(22); 13 | font.setBold(true); 14 | setFont(font); 15 | 16 | setTextWidth(width); 17 | 18 | document()->setDocumentMargin(4); 19 | 20 | 21 | } 22 | 23 | 24 | void Button::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { 25 | 26 | QPixmap pixmap(":/images/button"); 27 | pixmap = pixmap.scaled(width,height); 28 | 29 | painter->setBrush(pixmap); 30 | painter->drawRect(boundingRect()); 31 | 32 | QGraphicsTextItem::paint(painter,option, widget); 33 | } 34 | 35 | void Button::mousePressEvent(QGraphicsSceneMouseEvent *event) { 36 | QGraphicsTextItem::mousePressEvent(event); 37 | 38 | emit onPress(); 39 | } 40 | 41 | 42 | -------------------------------------------------------------------------------- /src/views/TextField.cpp: -------------------------------------------------------------------------------- 1 | #include "TextField.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | TextField::TextField(int width, int height): width(width),height(height), QGraphicsTextItem(){ 8 | 9 | QFont font; 10 | font.setPixelSize(22); 11 | font.setBold(true); 12 | setFont(font); 13 | 14 | 15 | setTextInteractionFlags(Qt::TextEditorInteraction); 16 | 17 | 18 | setTextWidth(width); 19 | 20 | document()->setDocumentMargin(4); 21 | 22 | } 23 | 24 | void TextField::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { 25 | QPixmap pixmap(":/images/icon"); 26 | pixmap = pixmap.scaled(width,height); 27 | 28 | painter->setBrush(pixmap); 29 | painter->drawRect(boundingRect()); 30 | 31 | QStyleOptionGraphicsItem newOption(*option); 32 | newOption.state = QStyle::State_None; 33 | 34 | QGraphicsTextItem::paint(painter, &newOption, widget); 35 | } 36 | 37 | QRectF TextField::boundingRect() const { 38 | auto rect = QGraphicsTextItem::boundingRect(); 39 | rect.setWidth(width); 40 | rect.setHeight(height); 41 | return QGraphicsTextItem::boundingRect(); 42 | 43 | } 44 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # playing-with-fire2 2 | This is a 1v1 game base on [playing with fire](https://www.crazygames.com/game/playing-with-fire-2) 3 | for university project of Advanced programming written in qt (a frame work for C++)


4 | ![image](https://user-images.githubusercontent.com/88885103/180598955-91c706c6-2386-477f-b524-1d424800766f.png) 5 | # how to play 6 | first player one movements are going up (w) & goint left (a) & going right (d) & goint down (s) & and planting(space bar)
7 | second player one movements are going up (8) & goint left (4) & going right (6) & goint down (2) & and planting(+)

8 | you will earn 50 point for eliminating other opponent and 25 for exploding bricks 9 | # how to run the game in your device 10 | first you should install qt in your device
11 | [installing qt](https://doc.qt.io/qt-5/gettingstarted.html#:~:text=Installing%20Qt,platform%20operating%20system%20and%20compiler) 12 |
13 | then clone the repository 14 | ``` 15 | git clone https://github.com/ArmanTaheriGhaleTaki/playing-with-fire2.git 16 | ``` 17 | and open playing-with-fire2 folder with QT creator build and run and enjoy :wink:
18 | you can supprot us with hit that star buttom on top right your screen we will very appreciate that :pray: 19 | -------------------------------------------------------------------------------- /src/Home/Result.cpp: -------------------------------------------------------------------------------- 1 | #include "Result.h" 2 | #include "../views/Label.h" 3 | 4 | 5 | Result::Result(QString winner,int scoreOfPlayer1,int scoreOfPlayer2) 6 | { 7 | 8 | 9 | // set fixed size 10 | 11 | setFixedSize(443,390); 12 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 13 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 14 | 15 | 16 | // create scene 17 | 18 | auto scene = new QGraphicsScene(this); 19 | scene->setSceneRect(0,0,443,390); 20 | scene->setBackgroundBrush(QBrush(QImage(":/images/result"))); 21 | setScene(scene); 22 | 23 | // the winner of game 24 | auto winnerLabel = new Label(50,"white"); // first part is size of font and second part is color 25 | winnerLabel->setPlainText(winner); 26 | scene->addItem(winnerLabel); 27 | winnerLabel->setPos(130,230); 28 | 29 | // score of players 30 | auto scoreOfPlayer1Label = new Label(25,"white"); 31 | scoreOfPlayer1Label->setPlainText(QString::number(scoreOfPlayer1)); 32 | scene->addItem(scoreOfPlayer1Label); 33 | scoreOfPlayer1Label->setPos(40,300); 34 | 35 | auto scoreOfPlayer2Label = new Label(25,"white"); 36 | scoreOfPlayer2Label->setPlainText(QString::number(scoreOfPlayer2)); 37 | scene->addItem(scoreOfPlayer2Label); 38 | scoreOfPlayer2Label->setPos(370,300); 39 | 40 | 41 | } 42 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.22) 2 | project(plying_with_fire2) 3 | 4 | set(CMAKE_CXX_STANDARD 17) 5 | set(CMAKE_AUTOMOC ON) 6 | set(CMAKE_AUTORCC ON) 7 | set(CMAKE_AUTOUIC ON) 8 | 9 | find_package( 10 | Qt6 COMPONENTS 11 | Core 12 | Gui Widgets 13 | Multimedia 14 | REQUIRED) 15 | add_executable(plying_with_fire2 main.cpp src/Home/Home.cpp src/Home/Home.h src/views/TextField.cpp src/views/TextField.h src/views/Label.cpp src/views/Label.h src/views/Button.cpp src/views/Button.h resources.qrc src/Home/Game.cpp src/Home/Game.h src/views/block.h src/views/block.cpp src/views/wall.h src/views/wall.cpp src/Player/Player.cpp src/Player/Player.h src/Player/Bomb.cpp src/Player/Bomb.h src/views/Brick.cpp src/views/Brick.h src/Home/Result.cpp src/Home/Result.h) 16 | target_link_libraries(plying_with_fire2 17 | Qt::Core 18 | Qt::Gui 19 | Qt::Widgets 20 | Qt::Multimedia 21 | ) 22 | 23 | if (WIN32) 24 | set(CMAKE_PREFIX_PATH C:/Qt/6.2.4/mingw_64) 25 | set(DEBUG_SUFFIX) 26 | if (MSVC AND CMAKE_BUILD_TYPE MATCHES "Debug") 27 | set(DEBUG_SUFFIX "d") 28 | endif () 29 | set(QT_INSTALL_PATH "${CMAKE_PREFIX_PATH}") 30 | if (NOT EXISTS "${QT_INSTALL_PATH}/bin") 31 | set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..") 32 | if (NOT EXISTS "${QT_INSTALL_PATH}/bin") 33 | set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..") 34 | endif () 35 | endif () 36 | if (EXISTS "${QT_INSTALL_PATH}/plugins/platforms/qwindows${DEBUG_SUFFIX}.dll") 37 | add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD 38 | COMMAND ${CMAKE_COMMAND} -E make_directory 39 | "$/plugins/platforms/") 40 | add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD 41 | COMMAND ${CMAKE_COMMAND} -E copy 42 | "${QT_INSTALL_PATH}/plugins/platforms/qwindows${DEBUG_SUFFIX}.dll" 43 | "$/plugins/platforms/") 44 | endif () 45 | foreach (QT_LIB Core Gui Widgets) 46 | add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD 47 | COMMAND ${CMAKE_COMMAND} -E copy 48 | "${QT_INSTALL_PATH}/bin/Qt6${QT_LIB}${DEBUG_SUFFIX}.dll" 49 | "$") 50 | endforeach (QT_LIB) 51 | else() 52 | set(CMAKE_PREFIX_PATH /home/arman/Qt/6.2.4/gcc_x64) 53 | endif () 54 | 55 | -------------------------------------------------------------------------------- /src/Home/Home.cpp: -------------------------------------------------------------------------------- 1 | #include "Home.h" 2 | #include "../views/Label.h" 3 | #include "../views/Button.h" 4 | #include "Game.h" 5 | #include 6 | #include 7 | 8 | Home::Home() { 9 | 10 | // set fixed size 11 | 12 | setFixedSize(800,800); 13 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 14 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 15 | 16 | 17 | // create scene 18 | auto scene = new QGraphicsScene(this); 19 | scene->setSceneRect(0,0,800,800); 20 | scene->setBackgroundBrush(QBrush(QImage(":/images/menu"))); 21 | setScene(scene); 22 | 23 | 24 | 25 | // name inputs 26 | 27 | textField_player1 = new TextField(150,39); 28 | textField_player1->setPlainText(" "); 29 | scene->addItem(textField_player1); 30 | textField_player1->setPos(240,430); 31 | 32 | textField_player2 = new TextField(150,39); 33 | textField_player2->setPlainText(" "); 34 | scene->addItem(textField_player2); 35 | textField_player2->setPos(440,430); 36 | 37 | 38 | // hit points input 39 | 40 | textField_hp = new TextField(46,39); 41 | textField_hp->setPlainText(" "); 42 | scene->addItem(textField_hp); 43 | textField_hp->setPos(398,545); 44 | 45 | 46 | // name label 47 | 48 | auto name_label = new Label(40,"white"); 49 | name_label->setPlainText("vs "); 50 | scene->addItem(name_label); 51 | name_label->setPos(392,415); 52 | 53 | 54 | // hit point label 55 | 56 | auto hp_label = new Label(40,"white"); 57 | hp_label->setPlainText("HP:"); 58 | scene->addItem(hp_label); 59 | hp_label->setPos(322,530); 60 | 61 | // start button 62 | auto start_button = new Button(100,50); 63 | start_button->setPlainText(" Start ->"); 64 | scene->addItem(start_button); 65 | start_button->setPos(640,680); 66 | 67 | 68 | // go to main scene from home page 69 | connect (start_button, &Button::onPress,this, &Home::onGameStart); 70 | 71 | } 72 | void Home::onGameStart() 73 | { 74 | QFile file{"game.txt"}; 75 | if(file.open(QIODevice::ReadWrite)) { 76 | file.write((textField_player1->toPlainText().toStdString() 77 | +"\n"+(textField_player2->toPlainText().toStdString()) 78 | +"\n"+textField_hp->toPlainText().toStdString()).c_str()); 79 | file.flush(); 80 | } 81 | auto name_player1 = textField_player1->toPlainText(); 82 | auto name_player2 = textField_player2->toPlainText(); 83 | auto hp = textField_hp->toPlainText().toInt(); 84 | close(); 85 | (new Game(name_player1,name_player2,hp))->show(); 86 | } 87 | -------------------------------------------------------------------------------- /src/Player/Bomb.cpp: -------------------------------------------------------------------------------- 1 | #include "Bomb.h" 2 | #include "../views/Brick.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "../Home/Game.h" 8 | #include 9 | 10 | 11 | Bomb::Bomb(int posX, int posY, int width, int height, QList *bricks, QList *players, 12 | QString PlayerRecognizer) : pos_x{posX}, pos_y{posY}, width{width}, height{height}, bricks{bricks}, 13 | players{players}, PlayerRecognizer{PlayerRecognizer}, QObject() 14 | { 15 | 16 | QPixmap pixmap(":/images/bomb"); 17 | pixmap = pixmap.scaled(width,height); 18 | setPixmap(pixmap); 19 | auto BombTimer = new QTimer(); 20 | connect(BombTimer, &QTimer::timeout, this , &Bomb::Exploding); 21 | BombTimer->start(2000); 22 | 23 | } 24 | void Bomb::Exploding() 25 | { 26 | 27 | // destroying bricks 28 | for (const auto brick : *bricks) 29 | { 30 | auto brick_x = brick->x(); 31 | auto brick_y = brick->y(); 32 | auto distance = sqrt(pow(brick_x - pos_x,2)+pow(brick_y - pos_y,2)); 33 | auto distanceBetweenPlayer_Bomb = sqrt(pow(brick_x - pos_x,2)+pow(brick_y - pos_y,2)); 34 | if((distance <= 120)&&((( pos_x/60==brick_x/60)&&!(((pos_x/60)%2==0)&&(pos_y/60)%2==1))||((pos_y/60==brick_y/60)&&!(((pos_x/60)%2==1)&&(pos_y/60)%2==0)))) 35 | { 36 | scene()->removeItem(brick); 37 | bricks->removeAt(bricks->indexOf(brick)); 38 | if (PlayerRecognizer == "player_1") 39 | players->at(0)->increaseScore(25); 40 | else if (PlayerRecognizer == "player_2") 41 | players->at(1)->increaseScore(25); 42 | } 43 | } 44 | 45 | auto player1 = players->at(0); 46 | auto player2 = players->at(1); 47 | auto distancePlayer1_Bomb = sqrt(pow(player1->x() - pos_x, 2) + pow(player1->y() - pos_y, 2)); 48 | auto distancePlayer2_Bomb = sqrt(pow(player2->x() - pos_x, 2) + pow(player2->y() - pos_y, 2)); 49 | 50 | if(distancePlayer1_Bomb < 120) 51 | { 52 | players->at(0)->DecreaseHealth(); 53 | if (players->at(0)->getHitPoint() == 0) 54 | { 55 | players->at(1)->increaseScore(50); 56 | emit onPlayerKilled(); 57 | } 58 | } 59 | else if(distancePlayer2_Bomb < 120) 60 | { 61 | players->at(1)->DecreaseHealth(); 62 | if (players->at(1)->getHitPoint() == 0) 63 | { 64 | players->at(0)->increaseScore(50); 65 | emit onPlayerKilled(); 66 | } 67 | } 68 | 69 | 70 | scene()->removeItem(this); 71 | delete this; 72 | 73 | } 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # C++ objects and libs 2 | *.slo 3 | *.lo 4 | *.o 5 | *.a 6 | *.la 7 | *.lai 8 | *.so 9 | *.so.* 10 | *.dll 11 | *.dylib 12 | 13 | # Qt-es 14 | object_script.*.Release 15 | object_script.*.Debug 16 | *_plugin_import.cpp 17 | /.qmake.cache 18 | /.qmake.stash 19 | *.pro.user 20 | *.pro.user.* 21 | *.qbs.user 22 | *.qbs.user.* 23 | *.moc 24 | moc_*.cpp 25 | moc_*.h 26 | qrc_*.cpp 27 | ui_*.h 28 | *.qmlc 29 | *.jsc 30 | Makefile* 31 | *build-* 32 | *.qm 33 | *.prl 34 | 35 | # Qt unit tests 36 | target_wrapper.* 37 | 38 | # QtCreator 39 | *.autosave 40 | 41 | # QtCreator Qml 42 | *.qmlproject.user 43 | *.qmlproject.user.* 44 | 45 | # QtCreator CMake 46 | CMakeLists.txt.user* 47 | 48 | # QtCreator 4.8< compilation database 49 | compile_commands.json 50 | 51 | # QtCreator local machine specific files for imported projects 52 | *creator.user* 53 | 54 | # files 55 | README.md 56 | #folders 57 | .idea/ 58 | # Created by https://www.toptal.com/developers/gitignore/api/clion 59 | # Edit at https://www.toptal.com/developers/gitignore?templates=clion 60 | 61 | ### CLion ### 62 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider 63 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 64 | 65 | # User-specific stuff 66 | .idea/**/workspace.xml 67 | .idea/**/tasks.xml 68 | .idea/**/usage.statistics.xml 69 | .idea/**/dictionaries 70 | .idea/**/shelf 71 | 72 | # AWS User-specific 73 | .idea/**/aws.xml 74 | 75 | # Generated files 76 | .idea/**/contentModel.xml 77 | 78 | # Sensitive or high-churn files 79 | .idea/**/dataSources/ 80 | .idea/**/dataSources.ids 81 | .idea/**/dataSources.local.xml 82 | .idea/**/sqlDataSources.xml 83 | .idea/**/dynamic.xml 84 | .idea/**/uiDesigner.xml 85 | .idea/**/dbnavigator.xml 86 | 87 | # Gradle 88 | .idea/**/gradle.xml 89 | .idea/**/libraries 90 | 91 | # Gradle and Maven with auto-import 92 | # When using Gradle or Maven with auto-import, you should exclude module files, 93 | # since they will be recreated, and may cause churn. Uncomment if using 94 | # auto-import. 95 | # .idea/artifacts 96 | # .idea/compiler.xml 97 | # .idea/jarRepositories.xml 98 | # .idea/modules.xml 99 | # .idea/*.iml 100 | # .idea/modules 101 | # *.iml 102 | # *.ipr 103 | 104 | # CMake 105 | cmake-build-*/ 106 | 107 | # Mongo Explorer plugin 108 | .idea/**/mongoSettings.xml 109 | 110 | # File-based project format 111 | *.iws 112 | 113 | # IntelliJ 114 | out/ 115 | 116 | # mpeltonen/sbt-idea plugin 117 | .idea_modules/ 118 | 119 | # JIRA plugin 120 | atlassian-ide-plugin.xml 121 | 122 | # Cursive Clojure plugin 123 | .idea/replstate.xml 124 | 125 | # SonarLint plugin 126 | .idea/sonarlint/ 127 | 128 | # Crashlytics plugin (for Android Studio and IntelliJ) 129 | com_crashlytics_export_strings.xml 130 | crashlytics.properties 131 | crashlytics-build.properties 132 | fabric.properties 133 | 134 | # Editor-based Rest Client 135 | .idea/httpRequests 136 | 137 | # Android studio 3.1+ serialized cache file 138 | .idea/caches/build_file_checksums.ser 139 | 140 | ### CLion Patch ### 141 | # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 142 | 143 | # *.iml 144 | # modules.xml 145 | # .idea/misc.xml 146 | # *.ipr 147 | 148 | # Sonarlint plugin 149 | # https://plugins.jetbrains.com/plugin/7973-sonarlint 150 | .idea/**/sonarlint/ 151 | 152 | # SonarQube Plugin 153 | # https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin 154 | .idea/**/sonarIssues.xml 155 | 156 | # Markdown Navigator plugin 157 | # https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced 158 | .idea/**/markdown-navigator.xml 159 | .idea/**/markdown-navigator-enh.xml 160 | .idea/**/markdown-navigator/ 161 | 162 | # Cache file creation bug 163 | # See https://youtrack.jetbrains.com/issue/JBR-2257 164 | .idea/$CACHE_FILE$ 165 | 166 | # CodeStream plugin 167 | # https://plugins.jetbrains.com/plugin/12206-codestream 168 | .idea/codestream.xml 169 | 170 | # Azure Toolkit for IntelliJ plugin 171 | # https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij 172 | .idea/**/azureSettings.xml 173 | 174 | # End of https://www.toptal.com/developers/gitignore/api/clion 175 | 176 | -------------------------------------------------------------------------------- /src/Home/Game.cpp: -------------------------------------------------------------------------------- 1 | #include "Game.h" 2 | #include "../views/wall.h" 3 | #include "../Player/Bomb.h" 4 | #include "../views/Brick.h" 5 | #include "../views/Label.h" 6 | #include "Result.h" 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | Game::Game(QString name_player1,QString name_player2,int hp) : name_player1{name_player1},name_player2{name_player2},QGraphicsView(){ 14 | 15 | // set fixed size 16 | setFixedSize(900,900); 17 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 18 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 19 | 20 | // create ground 21 | auto scene = new QGraphicsScene(this); 22 | scene->setSceneRect(0,0,900,900); 23 | scene->setBackgroundBrush(QBrush(QImage(":/images/ground"))); 24 | setScene(scene); 25 | 26 | // // play music 27 | // auto player = new QMediaPlayer; 28 | // auto audioOutput = new QAudioOutput; 29 | // player->setAudioOutput(audioOutput); 30 | // connect(player, SIGNAL(positionChanged(qint64)), this, SLOT(positionChanged(qint64))); 31 | // player->setSource(QUrl(":/music/game")); 32 | // audioOutput->setVolume(50); 33 | // player->play(); 34 | 35 | auto blockWidth = 60; 36 | auto blockHeight= 60; 37 | 38 | // put blocks on ground 39 | for(int i =0 ; i<15;i++) 40 | for(int j =0;j<15;j++){ 41 | if(i!=0&&i!=14&&j!=0&&j!=14&&(j%2!=0||i%2!=0)) 42 | continue; 43 | auto wall = new Wall(blockWidth, blockHeight); 44 | scene->addItem(wall); 45 | wall->setPos(blockWidth*i,blockHeight*j); 46 | walls.append(wall); 47 | } 48 | 49 | // set bricks 50 | auto brickWidth = 60; 51 | auto brickHeight= 60; 52 | int bricksStructure[15][15] = 53 | { 54 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 55 | {0,0,0,0,1,1,0,1,1,1,1,1,1,0,0,}, 56 | {0,0,0,1,0,1,0,1,0,1,0,1,0,1,0}, 57 | {0,0,1,0,1,0,0,1,1,0,1,1,0,1,0}, 58 | {0,0,0,1,0,1,0,1,0,1,0,1,0,1,0}, 59 | {0,0,1,1,1,1,1,1,1,1,1,1,0,0,0}, 60 | {0,1,0,1,0,1,0,0,0,1,0,1,0,0,0}, 61 | {0,1,0,1,1,1,1,1,1,1,1,1,0,1,0}, 62 | {0,1,0,1,0,1,0,1,0,1,0,1,0,1,0}, 63 | {0,0,1,0,1,1,0,1,0,1,0,1,1,0,0}, 64 | {0,0,0,1,0,1,0,1,0,1,0,0,0,0,0}, 65 | {0,0,1,0,1,1,1,1,0,1,1,1,1,0,0}, 66 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 67 | {0,0,0,1,1,1,1,1,0,1,0,1,0,0,0}, 68 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},}; 69 | for(int i =0 ; i<15;i++) 70 | for(int j =0;j<15;j++){ 71 | if(bricksStructure[i][j]!=1) 72 | continue; 73 | auto brick = new Brick(brickWidth, brickHeight); 74 | scene->addItem(brick); 75 | brick->setPos(brickWidth*i,brickHeight*j); 76 | bricks.append(brick); 77 | 78 | } 79 | 80 | 81 | // add players to scene 82 | auto player1 = new Player(":/images/player1",33,45,100); 83 | scene->addItem(player1); 84 | player1->setPos(75,70); 85 | players.append(player1); 86 | 87 | auto player2 = new Player(":/images/player2",33,45,100); 88 | scene->addItem(player2); 89 | player2->setPos(795,770); 90 | players.append(player2); 91 | 92 | // add name of players to game scene 93 | auto player1NameLabel = new Label(25,"#dcf1c2"); 94 | player1NameLabel->setPlainText(name_player1); 95 | scene->addItem(player1NameLabel); 96 | player1NameLabel->setPos(48,20); 97 | 98 | auto player2NameLabel = new Label(25,"#d53a5e"); 99 | player2NameLabel->setPlainText(name_player2); 100 | scene->addItem(player2NameLabel); 101 | player2NameLabel->setPos(723,20); 102 | 103 | // add hit point of players to game scene 104 | players.at(0)->setHitPoint(hp); // set hit point of player 1 105 | auto player1Hp = new Label(25,"#d53a5e"); 106 | player1Hp->setPlainText(QString::number(players.at(0)->getHitPoint())); 107 | scene->addItem(player1Hp); 108 | player1Hp->setPos(130,22); 109 | 110 | players.at(1)->setHitPoint(hp); // set hit point of player 2 111 | auto player2Hp = new Label(25,"#dcf1c2"); 112 | player2Hp->setPlainText(QString::number(players.at(1)->getHitPoint())); 113 | scene->addItem(player2Hp); 114 | player2Hp->setPos(800,22); 115 | } 116 | 117 | 118 | // control players 119 | void Game::keyPressEvent(QKeyEvent *event) { 120 | QGraphicsView::keyPressEvent(event); 121 | 122 | 123 | // control player 1 124 | auto player_1 = players.at(0); 125 | 126 | auto player_1Width = player_1->boundingRect().width(); 127 | auto player_1Height = player_1->boundingRect().height(); 128 | 129 | auto newX_p1 = player_1->x(); 130 | auto newY_p1 = player_1->y(); 131 | 132 | if(event->key() == Qt::Key_S) 133 | newY_p1 = player_1->y() + 7; 134 | 135 | if(event->key() == Qt::Key_W) 136 | newY_p1 = player_1->y() - 7; 137 | 138 | if(event->key() == Qt::Key_A) 139 | newX_p1 = player_1->x() - 7; 140 | 141 | if(event->key() == Qt::Key_D) 142 | newX_p1 = player_1->x() + 7; 143 | 144 | 145 | // collision with walls 146 | for(const auto wall:walls) 147 | { 148 | 149 | if(wall->x() < newX_p1 && wall->x() + wall->boundingRect().width() > newX_p1 150 | && wall->y() < newY_p1 && wall->y() + wall->boundingRect().height() > newY_p1) 151 | return; 152 | if(wall->x() < newX_p1 + player_1Width && wall->x() + wall->boundingRect().width() > newX_p1 + (player_1Width-2) 153 | && wall->y() < newY_p1 && wall->y() + wall->boundingRect().height() > newY_p1) 154 | return; 155 | if(wall->x() < newX_p1 + player_1Width && wall->x() + wall->boundingRect().width() > newX_p1 + (player_1Width-30) 156 | && wall->y() < newY_p1 + player_1Height && wall->y() + wall->boundingRect().height() > newY_p1 + player_1Height) 157 | return; 158 | if(wall->x() x() + wall->boundingRect().width() > newX_p1 159 | && wall->y() < + player_1Height && wall->y() + wall->boundingRect().height() > newY_p1 + player_1Height) 160 | return; 161 | } 162 | 163 | // collision with bricks 164 | for(const auto brick:bricks) 165 | { 166 | 167 | if(brick->x() < newX_p1 && brick->x() + brick->boundingRect().width() > newX_p1 168 | && brick->y() < newY_p1 && brick->y() + brick->boundingRect().height() > newY_p1) 169 | return; 170 | if(brick->x() < newX_p1 + player_1Width && brick->x() + brick->boundingRect().width() > newX_p1 + (player_1Width-2) 171 | && brick->y() < newY_p1 && brick->y() + brick->boundingRect().height() > newY_p1) 172 | return; 173 | if(brick->x() < newX_p1 + player_1Width && brick->x() + brick->boundingRect().width() > newX_p1 + (player_1Width-30) 174 | && brick->y() < newY_p1 + player_1Height && brick->y() + brick->boundingRect().height() > newY_p1 + player_1Height) 175 | return; 176 | if(brick->x() x() + brick->boundingRect().width() > newX_p1 177 | && brick->y() < + player_1Height && brick->y() + brick->boundingRect().height() > newY_p1 + player_1Height) 178 | return; 179 | } 180 | 181 | 182 | player_1->setPos(newX_p1,newY_p1); 183 | 184 | 185 | QString reconigzer; // reconigzing the player who is playing in that moment 186 | 187 | // add bombs to player1 188 | if(event->key() == Qt::Key_Space && player_1->NumberOfBombs > 0) 189 | { 190 | if (player_1) 191 | reconigzer = "player_1"; 192 | auto bomb = new Bomb(newX_p1,newY_p1,25, 25, &bricks,&players,reconigzer); 193 | connect(bomb, &Bomb::onPlayerKilled, this, &Game::onResult); 194 | scene()->addItem(bomb); 195 | bomb->setPos(newX_p1,(newY_p1+23)); 196 | player_1->NumberOfBombs--; 197 | 198 | } 199 | 200 | 201 | 202 | 203 | // control player 2 204 | auto player_2 = players.at(1); 205 | 206 | auto player_2Width = player_2->boundingRect().width(); 207 | auto player_2Height = player_2->boundingRect().height(); 208 | 209 | auto newX_p2 = player_2->x(); 210 | auto newY_p2 = player_2->y(); 211 | 212 | if(event->key() == Qt::Key_Up) 213 | newY_p2 = player_2->y() - 7; 214 | 215 | if(event->key() == Qt::Key_Down) 216 | newY_p2 = player_2->y() + 7; 217 | 218 | if(event->key() == Qt::Key_Left) 219 | newX_p2 = player_2->x() - 7; 220 | 221 | if(event->key() == Qt::Key_Right) 222 | newX_p2 = player_2->x() + 7; 223 | 224 | // collision with walls 225 | for(const auto wall:walls) 226 | { 227 | 228 | if(wall->x() < newX_p2 && wall->x() + wall->boundingRect().width() > newX_p2 229 | && wall->y() < newY_p2 && wall->y() + wall->boundingRect().height() > newY_p2) 230 | return; 231 | if(wall->x() < newX_p2 + player_2Width && wall->x() + wall->boundingRect().width() > newX_p2 + (player_2Width-2) 232 | && wall->y() < newY_p2 && wall->y() + wall->boundingRect().height() > newY_p2) 233 | return; 234 | if(wall->x() < newX_p2 + player_2Width && wall->x() + wall->boundingRect().width() > newX_p2 + (player_2Width-30) 235 | && wall->y() < newY_p2 + player_2Height && wall->y() + wall->boundingRect().height() > newY_p2 + player_2Height) 236 | return; 237 | if(wall->x() x() + wall->boundingRect().width() > newX_p2 238 | && wall->y() < + player_2Height && wall->y() + wall->boundingRect().height() > newY_p2 + player_2Height) 239 | return; 240 | } 241 | 242 | // collision with bricks 243 | for(const auto brick:bricks) 244 | { 245 | 246 | if(brick->x() < newX_p2 && brick->x() + brick->boundingRect().width() > newX_p2 247 | && brick->y() < newY_p2 && brick->y() + brick->boundingRect().height() > newY_p2) 248 | return; 249 | if(brick->x() < newX_p2 + player_2Width && brick->x() + brick->boundingRect().width() > newX_p2 + (player_2Width-2) 250 | && brick->y() < newY_p2 && brick->y() + brick->boundingRect().height() > newY_p2) 251 | return; 252 | if(brick->x() < newX_p2 + player_2Width && brick->x() + brick->boundingRect().width() > newX_p2 + (player_2Width-30) 253 | && brick->y() < newY_p2 + player_2Height && brick->y() + brick->boundingRect().height() > newY_p2 + player_2Height) 254 | return; 255 | if(brick->x() x() + brick->boundingRect().width() > newX_p2 256 | && brick->y() < + player_2Height && brick->y() + brick->boundingRect().height() > newY_p2 + player_2Height) 257 | return; 258 | } 259 | 260 | player_2->setPos(newX_p2,newY_p2); 261 | 262 | 263 | 264 | // add bombs of player2 265 | 266 | if(event->key() == Qt::Key_Plus || event->key() == Qt::Key_Enter && player_2->NumberOfBombs > 0) 267 | { 268 | 269 | if (player_2) 270 | reconigzer = "player_2"; 271 | auto bomb = new Bomb(newX_p2,newY_p2,25, 25, &bricks,&players,reconigzer); 272 | connect(bomb, &Bomb::onPlayerKilled, this, &Game::onResult); 273 | scene()->addItem(bomb); 274 | bomb->setPos(newX_p2,(newY_p2+23)); 275 | player_2->NumberOfBombs--; 276 | 277 | } 278 | 279 | } 280 | QString Game::checkWinner() 281 | { 282 | if(players.at(0)->score > players.at(1)->score) 283 | return name_player1; 284 | else 285 | return name_player2; 286 | } 287 | void Game::onResult() 288 | { 289 | auto winner = checkWinner(); 290 | auto scoreOfPlayer1 = players.at(0)->score; 291 | auto scoreOfPlayer2 = players.at(1)->score; 292 | (new Result(winner,scoreOfPlayer1,scoreOfPlayer2))->show(); 293 | close(); 294 | 295 | } 296 | 297 | --------------------------------------------------------------------------------