void QExercise::nextState() { if ( mState==Stopped ) startCountDown(); else if ( mState==CountDown ) startWaitForAnswer(); else if ( mState==WaitForAnswer ) startCheckAnswer(); else if ( mState==CheckAnswer ) startCountDown(); }
bool CountDown::init() { if(!LayerColor::initWithColor(MENU_BACKGROUND_COLOR)) { return false; } countDownLabel = label("3")->position(VisibleRect::center())->size(500)->addTo(this); runAction(Sequence::create(DelayTime::create(0.2f), CallFunc::create([&](){ startCountDown(); }), NULL)); return true; }
void CountDown::startCountDown() { SoundManager::sharedSoundManager()->playSoundEffect("ClockTick"); countDownLabel->runAction(Sequence::create(EaseBackInOut::create(ScaleTo::create(0.4, 4.0f)), EaseBackOut::create(ScaleTo::create(0.4, 1.0f)), CallFunc::create([&]() { auto currentString = countDownLabel->getString(); int currentNumber = Converter::toInt(currentString); currentNumber--; if(currentNumber > 0) { countDownLabel->setString(Converter::toString(currentNumber)); startCountDown(); } else { countDownLabel->setString("GO"); SoundManager::sharedSoundManager()->playSoundEffect("Start"); Director::getInstance()->replaceScene(TransitionProgressInOut::create(SCENE_TRANSITION_TIME,HelloWorld::createScene())); } }), NULL)); }
MainWindow::MainWindow(vector<TimeOption> timeOptions_, QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), timer(this), finishedSource(":/sounds/alarm.raw"), timeOptions(timeOptions_) { ui->setupUi(this); for (vector<TimeOption>::iterator it = timeOptions.begin(); it!= timeOptions.end(); ++ it) { TimeOption o = *it; ui->timeSelection->addItem(QString::fromStdString(o.name)); } finishedSource.open(QIODevice::ReadOnly); QAudioFormat format; format.setSampleRate(44100); format.setChannelCount(1); format.setSampleSize(16); format.setCodec("audio/pcm"); format.setByteOrder(QAudioFormat::LittleEndian); format.setSampleType(QAudioFormat::SignedInt); QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice()); if (!info.isFormatSupported(format)) { qWarning() << "Raw audio format not supported by backend, cannot play audio."; finishedSound = NULL; } else { finishedSound = new QAudioOutput(format, this); //finishedSound->start(&finishedSource); } connect(ui->startTimer, SIGNAL(clicked()), this, SLOT(startCountDown())); connect(&timer, SIGNAL(timeout()), this, SLOT(timerTick())); connect(ui->fullscreen, SIGNAL(clicked()), this, SLOT(fullScreenClicked())); }