Hanoi-Towers/source/backEnd.cpp

31 lines
561 B
C++
Raw Normal View History

2018-04-11 20:27:22 +03:00
#include "backEnd.h"
#include <cmath>
2018-01-20 17:44:28 +03:00
2018-04-11 20:27:22 +03:00
BackEnd::BackEnd():
2018-01-20 17:44:28 +03:00
QObject()
{
}
2018-04-11 20:27:22 +03:00
unsigned short BackEnd::getMinSteps(const unsigned short lvl) const{
return pow(2, lvl) - 1;
}
void BackEnd::save(const short &lvl) const{
2018-01-20 17:44:28 +03:00
QFile f(SAVE);
if(f.open(QIODevice::WriteOnly|QIODevice::Truncate)){
f.write((char*)(&lvl),sizeof(lvl));
f.close();
}
}
2018-04-11 20:27:22 +03:00
short BackEnd::read()const{
2018-01-20 17:44:28 +03:00
short temp=1;
QFile f(SAVE);
if(f.open(QIODevice::ReadOnly)){
f.read((char*)&temp,sizeof(temp));
f.close();
}
return temp;
}