From 81e1b5e6da2cb405b71471e99aaaf6c7d821c1e5 Mon Sep 17 00:00:00 2001 From: yzhang Date: Tue, 26 Mar 2019 22:28:47 +0800 Subject: [PATCH] i dont know what's added! --- .DS_Store | Bin 0 -> 6148 bytes Game.cpp | 2 +- Game.cpp.autosave | 344 ++++++++++++++++++++++++++++++++++++++++++ mota.pro.user | 28 ++-- mota.pro.user.8207200 | 327 +++++++++++++++++++++++++++++++++++++++ mota_group.pro | 61 -------- 6 files changed, 685 insertions(+), 77 deletions(-) create mode 100644 .DS_Store create mode 100644 Game.cpp.autosave create mode 100644 mota.pro.user.8207200 delete mode 100644 mota_group.pro diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0show(0); // initial render & show floor 0 // draw the hero diff --git a/Game.cpp.autosave b/Game.cpp.autosave new file mode 100644 index 0000000..f75df75 --- /dev/null +++ b/Game.cpp.autosave @@ -0,0 +1,344 @@ +/* + * File: Game.cpp + * -------------------- + * This file implements Game.h interface. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "Game.h" +#include "Hero.h" +#include "Monster.h" +#include "Button.h" +#include "Unwalkable.h" +#include "npc.h" +#include "subtitle.h" +#include "saveload.h" +using namespace std; + +Game::Game(QWidget* parent) +{ + // set the scene & background + scene = new QGraphicsScene(); + scene->setSceneRect(0,0,440+100*2,440); + setBackgroundBrush(QBrush(QImage(":/images/bg.png").scaled(440+100*2, 440))); + setScene(scene); + setFixedSize(640,440); +} + +/* + * Implementation notes: subtitleMove() + * ------------------------------------ + * Clear main menu and show subtitle. Choose skip to skip. + */ + +void Game::subtitleMove() +{ + // clear + scene->clear(); + + // subtitle Move + QString subtitleContent = "offer收割🐔陈教授🐂🍺!\n"\ + "陈教授真的太强了,强无敌!!!\n"\ + "陈教授怎么会这么强 其他人真的都是弟弟\n"\ + "所以陈教授进入这个地方是干嘛???"; + subtitle* beginSubtitle = new subtitle(subtitleContent); +} + +/* + * Implementation notes: start() / restartGame() + * ----------------------------- + * Start the game and initialize the information. + */ + +void Game::start() +{ + scene->clear(); // clear + + // new backpack + backpackSys = new backpack(); + + // draw the map + maps = new Map("/Users/clydezhang/motaGroup/map.dat"); // TO DO: use relative path + maps->show(0); // initial render & show floor 0 + + // draw the hero + hero = new Hero(); + hero -> setPos(300, 400); // Initial Position + hero->show(); + scene->addItem(hero); + hero ->setFlag(QGraphicsItem::ItemIsFocusable); + + drawGUI(); // draw the information + + // add BGM + // TO DO: use Button to control BGM + QMediaPlayer * music = new QMediaPlayer(); + music->setMedia(QUrl("qrc:/sounds/bgm.mp3")); + music->play(); + + hero->setFocus(); // set focus to Hero + show(); // show game +} + +void Game::restartGame() +{ + start(); +} + +/* + * Implementation notes: drawPanel(int x, int y, int width, int height, QColor color, double opacity) + * -------------------------------------------------------------------------------------------------- + * Draw the background of information window. + */ + +void Game::drawPanel(int x, int y, int width, int height, QColor color, double opacity) +{ + // draw the panel + QGraphicsRectItem* panel = new QGraphicsRectItem(x, y, width, height); + QBrush brush; + brush.setStyle(Qt::SolidPattern); + brush.setColor(color); + panel->setBrush(brush); + panel->setOpacity(opacity); + scene->addItem(panel); +} + + + +/* + * Implementation notes: displayMainMenu() + * ------------------------------- + * Main menu includes three Buttons: + * Play + * Load + * Quit + */ + +void Game::displayMainMenu() +{ + // show game title + QGraphicsTextItem* titleText = new QGraphicsTextItem(QString("Magic Tower")); + QFont titleFont("comic sans", 50); + titleText->setFont(titleFont); + double txPos = this->width()/2 - titleText->boundingRect().width()/2; + double tyPos = 150; + titleText->setPos(txPos, tyPos); + scene->addItem(titleText); + + // Play button + Button* playButton = new Button(QString("Play"), 200, 40); + double bxPos = this->width()/2 - titleText->boundingRect().width()/2+50; + double byPos = 250; + playButton->setPos(bxPos, byPos); + connect(playButton, SIGNAL(clicked()), this, SLOT(subtitleMove())); + scene->addItem(playButton); + + // Load button + Button* loadButton = new Button(QString("Load"), 200, 40); + double lxPos = this->width()/2 - titleText->boundingRect().width()/2+50; + double lyPos = 300; + loadButton->setPos(lxPos, lyPos); + connect(loadButton, SIGNAL(clicked()), this, SLOT(showLoadOnMainMenu())); + scene->addItem(loadButton); + + // Quit button + Button* quitButton = new Button(QString("Quit"), 200, 40); + double qxPos = this->width()/2 - titleText->boundingRect().width()/2+50; + double qyPos = 350; + quitButton->setPos(qxPos, qyPos); + connect(quitButton, SIGNAL(clicked()), this, SLOT(close())); + scene->addItem(quitButton); +} + +/* + * Implementation notes: drawGUI() + * ------------------------------- + * Draw the information about item and hero. + */ + +void Game::drawGUI() +{ + // left side about hero information + drawPanel(0, 0, 100, 440, Qt::darkCyan, 1); + + QGraphicsTextItem* HeroInfo = new QGraphicsTextItem(QString("Hero")); + HeroInfo->setPos(25, 0); + scene->addItem(HeroInfo); + + lvText = new QGraphicsTextItem(QString("Lv :\t") + QString::number(hero->getLv())); + hpText = new QGraphicsTextItem(QString("HP :\t") + QString::number(hero->getHp())); + atkText = new QGraphicsTextItem(QString("Attack :\t") + QString::number(hero->getAtk())); + defText = new QGraphicsTextItem(QString("Defence :\t") + QString::number(hero->getDef())); + expText = new QGraphicsTextItem(QString("Exp :\t") + QString::number(hero->getExperience())); + moneyText = new QGraphicsTextItem(QString("Money :\t") + QString::number(hero->getMoney())); + floorText = new QGraphicsTextItem(QString("Floor :\t") + QString::number(hero->getFloor())); + + lvText->setPos(0, 40); + hpText->setPos(0, 80); + atkText->setPos(0, 120); + defText->setPos(0, 160); + expText->setPos(0, 200); + moneyText->setPos(0, 240); + floorText->setPos(0, 280); + + scene->addItem(lvText); + scene->addItem(hpText); + scene->addItem(atkText); + scene->addItem(defText); + scene->addItem(expText); + scene->addItem(moneyText); + scene->addItem(floorText); + + // right side about item information + drawPanel(540, 0, 100, 440, Qt::darkCyan, 1); + + QGraphicsTextItem* OtherInfo = new QGraphicsTextItem(QString("Item")); + OtherInfo->setPos(540, 0); + scene->addItem(OtherInfo); + + yellowKeyText = new QGraphicsTextItem(QString("Yellow key :\t") + QString::number(hero->getYellowKey())); + blueKeyText = new QGraphicsTextItem(QString("Blue key :\t") + QString::number(hero->getBlueKey())); + redKeyText = new QGraphicsTextItem(QString("Red key :\t") + QString::number(hero->getRedKey())); + + yellowKeyText->setPos(540, 40); + blueKeyText->setPos(540, 80); + redKeyText->setPos(540, 120); + + scene->addItem(yellowKeyText); + scene->addItem(blueKeyText); + scene->addItem(redKeyText); + + // if special tool is obtained, show how to use + // TO DO: special functions for tools + if (hero->getFloor() == true) { + floorFlyText = new QGraphicsTextItem(QString("Fly :\t") + QString("Press F")); + floorFlyText->setPos(540, 160); + scene->addItem(floorFlyText); + } + if (hero->getMonsterInfo() == true) { + monsterSearchText = new QGraphicsTextItem(QString("Search :\t") + QString("Press I")); + monsterSearchText->setPos(540, 200); + scene->addItem(monsterSearchText); + } +} + +/* + * Implementation notes: showLoad(), showSave, showLoadOnMainMenu() + * ---------------------------------------------------------------- + * Show frame of load, save or load on main menu. The difference between + * showLoad() and showLoadOnMainMenu() is + * backButton. + */ + +void Game::showLoad() +{ + SaveLoad *loadFrame = new SaveLoad(); + loadFrame->showLoadRecord(); +} + +void Game::showSave() +{ + SaveLoad *saveFrame = new SaveLoad(); + saveFrame->showSaveRecord(); +} + +void Game::showLoadOnMainMenu() +{ + SaveLoad *loadFrame = new SaveLoad(); + loadFrame->showLoadRecordOnMainMenu(); +} + +/* + * Implementation notes: gameOver(), displayGameoverWindow() + * --------------------------------------------------------- + * Gameover and show information. Choose to start again or quit. + */ + +void Game::gameOver() +{ + // Display gameover window + QString msg = "YOU WON! \nThis game is our childhood, \n if you like it, give me an A."; + displayGameoverWindow(msg); +} + +void Game::displayGameoverWindow(QString textToDisplay) +{ + // disable all items + for (int i = 0, n = scene->items().size(); i < n; i++) scene->items()[i]->setEnabled(false); + + // draw the background and text + drawPanel(0, 0, 640, 440, Qt::darkCyan, 0.65); + QGraphicsTextItem* titleText = new QGraphicsTextItem(QString(textToDisplay)); + QFont titleFont("comic sans", 20); + titleText->setFont(titleFont); + titleText->setPos(60, 100); + scene->addItem(titleText); + + // Play again Button + Button* playAgain = new Button(QString("Play Again"), 200, 40); + playAgain->setPos(110, 300); + scene->addItem(playAgain); + connect(playAgain, SIGNAL(clicked()), this, SLOT(restartGame())); + + // Quit Button + Button* quitButton = new Button(QString("Quit"), 200, 40); + quitButton->setPos(410, 300); + scene->addItem(quitButton); + connect(quitButton, SIGNAL(clicked()), this, SLOT(close())); +} + +/* + * Implementation notes: renderFloor(int floor) + * ------------------------------- + * Re-show map. + */ + +void Game::renderFloor(int floor) +{ + maps->show(floor); // refresh floor +} + +/* + * Implementation note: updateInfo() + * ------------------------------------------------ + * Update information on the window. + */ + +void Game::updateInfo() +{ + // update text + hpText->setPlainText(QString("HP :\t") + QString::number(hero->getHp())); + atkText->setPlainText(QString("Attack :\t") + QString::number(hero->getAtk())); + defText->setPlainText(QString("Defence :\t") + QString::number(hero->getDef())); + lvText->setPlainText(QString("Lv :\t") + QString::number(hero->getLv())); + expText->setPlainText(QString("Exp :\t") + QString::number(hero->getExperience())); + moneyText->setPlainText(QString("Money :\t") + QString::number(hero->getMoney())); + floorText->setPlainText(QString("Floor :\t") + QString::number(hero->getFloor())); + yellowKeyText->setPlainText(QString("Yellow key :\t") + QString::number(hero->getYellowKey())); + blueKeyText->setPlainText(QString("Blue key :\t") + QString::number(hero->getBlueKey())); + redKeyText->setPlainText(QString("Red key :\t") + QString::number(hero->getRedKey())); + + // update special tool status + if (hero->getFlyFloor() == true) { + floorFlyText = new QGraphicsTextItem(QString("Fly :\t") + QString("Press F")); + floorFlyText->setPos(540, 160); + scene->addItem(floorFlyText); + } + + if (hero->getMonsterInfo() == true) { + monsterSearchText = new QGraphicsTextItem(QString("Search :\t") + QString("Press I")); + monsterSearchText->setPos(540, 200); + scene->addItem(monsterSearchText); + } +} diff --git a/mota.pro.user b/mota.pro.user index ea3f41e..0da2db4 100644 --- a/mota.pro.user +++ b/mota.pro.user @@ -1,10 +1,10 @@ - + EnvironmentId - {82072007-f8a9-42ae-80c1-09726bf8fff8} + {3cf61c02-e8ec-48e0-b5d8-460eebd461d8} ProjectExplorer.Project.ActiveTarget @@ -62,14 +62,14 @@ ProjectExplorer.Project.Target.0 - Qt 5.11.3 clang 64bit - Qt 5.11.3 clang 64bit - {fdba9f44-9951-4708-9fa1-8cec5c95e9f9} + Desktop Qt 5.11.3 clang 64bit + Desktop Qt 5.11.3 clang 64bit + qt.qt5.5113.clang_64_kit 0 0 0 - /Users/haroldxu/Desktop/build-mota-Qt_5_11_3_clang_64bit-Debug + /Users/clydezhang/build-mota-Desktop_Qt_5_11_3_clang_64bit-Debug true @@ -125,7 +125,7 @@ true - /Users/haroldxu/Desktop/build-mota-Qt_5_11_3_clang_64bit-Release + /Users/clydezhang/build-mota-Desktop_Qt_5_11_3_clang_64bit-Release true @@ -181,7 +181,7 @@ true - /Users/haroldxu/Desktop/build-mota-Qt_5_11_3_clang_64bit-Profile + /Users/clydezhang/build-mota-Desktop_Qt_5_11_3_clang_64bit-Profile true @@ -240,7 +240,7 @@ 0 - 部署 + Deploy ProjectExplorer.BuildSteps.Deploy @@ -293,21 +293,19 @@ 2 - mota + + Custom Executable - Qt4ProjectManager.Qt4RunConfiguration:/Users/haroldxu/Desktop/mota/mota.pro - mota.pro + ProjectExplorer.CustomExecutableRunConfiguration 3768 false true - false - true false false true - /Users/haroldxu/Desktop/build-mota-Qt_5_11_3_clang_64bit-Debug/mota_group.app/Contents/MacOS + 1 diff --git a/mota.pro.user.8207200 b/mota.pro.user.8207200 new file mode 100644 index 0000000..ea3f41e --- /dev/null +++ b/mota.pro.user.8207200 @@ -0,0 +1,327 @@ + + + + + + EnvironmentId + {82072007-f8a9-42ae-80c1-09726bf8fff8} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + true + + + + ProjectExplorer.Project.Target.0 + + Qt 5.11.3 clang 64bit + Qt 5.11.3 clang 64bit + {fdba9f44-9951-4708-9fa1-8cec5c95e9f9} + 0 + 0 + 0 + + /Users/haroldxu/Desktop/build-mota-Qt_5_11_3_clang_64bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + /Users/haroldxu/Desktop/build-mota-Qt_5_11_3_clang_64bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + true + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + /Users/haroldxu/Desktop/build-mota-Qt_5_11_3_clang_64bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + true + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + 部署 + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy Configuration + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + mota + + Qt4ProjectManager.Qt4RunConfiguration:/Users/haroldxu/Desktop/mota/mota.pro + mota.pro + + 3768 + false + true + false + true + false + false + true + + /Users/haroldxu/Desktop/build-mota-Qt_5_11_3_clang_64bit-Debug/mota_group.app/Contents/MacOS + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 20 + + + Version + 20 + + diff --git a/mota_group.pro b/mota_group.pro deleted file mode 100644 index 163bd06..0000000 --- a/mota_group.pro +++ /dev/null @@ -1,61 +0,0 @@ -#------------------------------------------------- -# -# Project created by QtCreator 2019-01-18T22:01:57 -# -#------------------------------------------------- - -QT += core gui \ - multimedia - - -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets - -TARGET = mota_group -TEMPLATE = app - -# The following define makes your compiler emit warnings if you use -# any feature of Qt which has been marked as deprecated (the exact warnings -# depend on your compiler). Please consult the documentation of the -# deprecated API in order to know how to port your code away from it. -DEFINES += QT_DEPRECATED_WARNINGS - -# You can also make your code fail to compile if you use deprecated APIs. -# In order to do so, uncomment the following line. -# You can also select to disable deprecated APIs only up to a certain version of Qt. -#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 - -CONFIG += c++11 - -SOURCES += \ - main.cpp \ - monster.cpp \ - hero.cpp \ - game.cpp \ - unwalkable.cpp \ - map.cpp \ - Button.cpp \ - Msgboard.cpp - -HEADERS += \ - monster.h \ - hero.h \ - game.h \ - unwalkable.h \ - map.h \ - Button.h \ - Button.h \ - Msgboard.h - -FORMS += \ - mainwindow.ui - -# Default rules for deployment. -qnx: target.path = /tmp/$${TARGET}/bin -else: unix:!android: target.path = /opt/$${TARGET}/bin -!isEmpty(target.path): INSTALLS += target - -DISTFILES += \ - ../Documents/mota/mota/Res/map.dat - -RESOURCES += \ - res.qrc