add class compas

This commit is contained in:
serk 2017-01-20 22:12:10 +01:00
parent c64ab18b50
commit 6e5f7d851a
4 changed files with 83 additions and 3 deletions

View file

@ -8,11 +8,13 @@ SOURCES += main.cpp \
game.cpp \ game.cpp \
mygame.cpp \ mygame.cpp \
button.cpp \ button.cpp \
character.cpp character.cpp \
compas.cpp
HEADERS += \ HEADERS += \
game.hpp \ game.hpp \
mygame.hpp \ mygame.hpp \
commons.hpp \ commons.hpp \
button.hpp \ button.hpp \
character.hpp character.hpp \
compas.hpp

50
VaporWaveWars/compas.cpp Normal file
View file

@ -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<int>();
}
}
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;
}

28
VaporWaveWars/compas.hpp Normal file
View file

@ -0,0 +1,28 @@
#ifndef COMPAS_HPP
#define COMPAS_HPP
#include <vector>
#include <iostream>
#include <cmath>
static const float margeErr = 0.80f;
class Compas
{
private:
bool isPress;
int spaceTime;
std::vector<int> 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

View file

@ -1,5 +1,5 @@
#include "mygame.hpp" #include "mygame.hpp"
#include "compas.hpp"
int main() { int main() {
MyGame game = MyGame(); MyGame game = MyGame();
game.run(); game.run();