diff --git a/VaporWaveWars/VaporWaveWars.pro b/VaporWaveWars/VaporWaveWars.pro index 0293e3b..7ff1c56 100644 --- a/VaporWaveWars/VaporWaveWars.pro +++ b/VaporWaveWars/VaporWaveWars.pro @@ -8,11 +8,13 @@ SOURCES += main.cpp \ game.cpp \ mygame.cpp \ button.cpp \ - character.cpp + character.cpp \ + compas.cpp HEADERS += \ game.hpp \ mygame.hpp \ commons.hpp \ button.hpp \ - character.hpp + character.hpp \ + compas.hpp diff --git a/VaporWaveWars/compas.cpp b/VaporWaveWars/compas.cpp new file mode 100644 index 0000000..33b3fca --- /dev/null +++ b/VaporWaveWars/compas.cpp @@ -0,0 +1,50 @@ +#include "compas.hpp" + +Compas::Compas() { + spaceTime = 0; + isPress = false; +} + +void Compas::start() { + if (not isPress) { + std::cout << "start" << std::endl; + isPress = true; + spaceTime = 0; + notes = std::vector(); + } +} + +void Compas::add() { + if (isPress) { + notes.push_back(spaceTime); + spaceTime = 0; + std::cout << "add" << std::endl; + } +} + +void Compas::end() { + if (isPress) { + isPress = false; + std::cout << "end" << std::endl; + for (int i = 0; i < notes.size(); ++i) { + std::cout << notes[i] << std::endl; + } + } +} + +void Compas::incriseTime() { + ++spaceTime; +} + +int Compas::get (int i) const { + return notes[i]; +} + +bool Compas::operator ==(const Compas& d) const{ + int n = notes.size(); + for (int i = 0; i < n; ++i) { + float diff = ((float) (std::abs(notes[i] - d.get(i))))/((float) (notes[i])); + if (diff > margeErr) return false; + } + return true; +} diff --git a/VaporWaveWars/compas.hpp b/VaporWaveWars/compas.hpp new file mode 100644 index 0000000..8067e04 --- /dev/null +++ b/VaporWaveWars/compas.hpp @@ -0,0 +1,28 @@ +#ifndef COMPAS_HPP +#define COMPAS_HPP + +#include +#include +#include + +static const float margeErr = 0.80f; + +class Compas +{ + +private: + bool isPress; + int spaceTime; + std::vector notes; + +public: + Compas(); + void start(); + void add(); + void end(); + void incriseTime(); + int get(int i) const; + bool operator ==(const Compas& d) const; +}; + +#endif // COMPAS_HPP diff --git a/VaporWaveWars/main.cpp b/VaporWaveWars/main.cpp index 15f9142..2b3398f 100644 --- a/VaporWaveWars/main.cpp +++ b/VaporWaveWars/main.cpp @@ -1,5 +1,5 @@ #include "mygame.hpp" - +#include "compas.hpp" int main() { MyGame game = MyGame(); game.run();