diff --git a/src/Event.h b/src/Event.h index 0c52d2c..7ba9cc7 100644 --- a/src/Event.h +++ b/src/Event.h @@ -2,10 +2,9 @@ #include #include +#include -struct InputEvent{ - QEvent::Type type; -}; +using InputEvent = QInputEvent; struct GameEvent { int time = 0; diff --git a/src/Listener.cpp b/src/Listener.cpp index 8ea4288..0daf606 100644 --- a/src/Listener.cpp +++ b/src/Listener.cpp @@ -9,5 +9,5 @@ void GameListener::accept(GameEvent *event) { } void InputListener::accept(InputEvent *event) { - OnMouseClicked(); + // TODO distinguish QEvent Type } diff --git a/src/Window.cpp b/src/Window.cpp index ab55ba0..62114f9 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -1 +1,5 @@ #include "Window.h" + +void Window::mousePressEvent(QMouseEvent *event) { + InputQueue->submitEvent(event); +} diff --git a/src/Window.h b/src/Window.h index bc30a66..4ee1619 100644 --- a/src/Window.h +++ b/src/Window.h @@ -1,7 +1,16 @@ #pragma once #include +#include "Queue.h" +#include "Audio.h" +#include "FileManager.h" class Window : public QWidget { - +public: + static InputQueue * InputQueue; + static GameQueue * GameQueue; + static Audio * AudioManager; + static FileManager * FileManager; +protected: + void mousePressEvent(QMouseEvent *event) override; }; diff --git a/src/main.cpp b/src/main.cpp index ca58e58..29685ef 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,4 @@ #include -#include #include #include "Queue.h" #include "Audio.h" @@ -9,11 +8,6 @@ using std::cout, std::endl; -auto audioManager = new Audio; -auto fileManager = new FileManager; -auto gameQueue = new GameQueue; -auto inputQueue = new InputQueue; - int main(int argc, char * argv[]){ QApplication app(argc, argv); @@ -24,24 +18,28 @@ int main(int argc, char * argv[]){ /* for (int i = 0; i < 10'000; i++){ - fileManager->readFile("path" + std::to_string(i), [](const std::string& content){ + FileManager->readFile("path" + std::to_string(i), [](const std::string& content){ std::cout << content << std::endl; }); - fileManager->writeFile("path" + std::to_string(i), "some content" + std::to_string(i)); + FileManager->writeFile("path" + std::to_string(i), "some content" + std::to_string(i)); } */ - auto player = new Player; - - inputQueue->registerListener(player); - inputQueue->submitEvent(new InputEvent); - - gameQueue->registerListener(player); - gameQueue->submitEvent(new CoinCollectEvent); - gameQueue->submitEvent(new DamageEvent); + Window::InputQueue = new InputQueue; + Window::GameQueue = new GameQueue; + Window::AudioManager = new Audio; + Window::FileManager = new FileManager; Window window; window.show(); + auto player = new Player; + + Window::InputQueue->registerListener(player); + + Window::GameQueue->registerListener(player); + Window::GameQueue->submitEvent(new CoinCollectEvent); + Window::GameQueue->submitEvent(new DamageEvent); + return QApplication::exec(); } \ No newline at end of file