Exemple #1
0
// 开始槽
void WdgGuess::begin()
{
	int i, j;
	times = 0; // 尝试次数清零
	for (i = 0; i < nrNum; i++) {
		if (radioNoSame->isChecked()) { // 如果有禁止相同数字选项
			do { // 反复生成随机数,直到所有数字不同为止
				num[i] = rand()%10;
				for (j = 0; j < i && num[j] != num[i]; j++) {}
			} while (j < i);
		} else { // 否则允许相同数字
			num[i] = rand()%10; // 直接生成随机数
		}
		labelNum[i]->setText("*"); // 数字显示为 * 号
	}
	// 修改按钮文本为显示答案
	button->setText(tr("Show Answer"));
	// 断开按钮的单击信号与开始槽的连接
	disconnect(button, SIGNAL(clicked()), this, SLOT(begin()));
	// 将按钮的单击信号重新连接到显示答案槽
	connect(button, SIGNAL(clicked()), this, SLOT(showAnswer()));
	// 清理编辑框及显示结果
	clearPad();
	// 开始第一次尝试
	beginThisTime();
}
Exemple #2
0
// 失败
void WdgGuess::failed()
{
	QMessageBox msg(QMessageBox::Critical,
			tr("Fail"), tr("Game over!"),
			QMessageBox::Ok, this);
	showAnswer(); // 显示答案
	msg.exec(); // 显示对话框
}
Exemple #3
0
// 成功
void WdgGuess::victory()
{
	QMessageBox msg(QMessageBox::Question,
			tr("Success"), tr("Good job! Another game?"),
			QMessageBox::Ok | QMessageBox::Cancel, this);
	showAnswer(); // 显示答案
	// 显示对话框,如果用户输入 Ok 则开启新的一局
	if (msg.exec() == QMessageBox::Ok) button->click();
}
Exemple #4
0
// 显示答案槽
void WdgGuess::showAnswer()
{
	int i;
	for (i = 0; i < nrNum; i++) labelNum[i]->setNum(num[i]); // 显示数字
	disableAllEdit(); // 禁用所有编辑框
	// 修改按钮标题为开始
	button->setText(tr("Begin"));
	// 断开按钮的单击信号与显示答案槽的连接
	disconnect(button, SIGNAL(clicked()), this, SLOT(showAnswer()));
	// 将按钮的单击信号重新连接到开始槽
	connect(button, SIGNAL(clicked()), this, SLOT(begin()));
}
Exemple #5
0
int main(int argc,const char* argv[]) {
	std::vector<double> argvSet;
	std::map< std::vector<double>
			 ,std::vector<double> > associative; // 1 - set of 3 income parameters, 2 - answer for this set

	if(!isDigitSet(argc,argv,argvSet))	//Check all digits are digits
		usage();
	fillMap(argvSet,associative);
	squareSolve(associative);
	showAnswer(associative);
	system("pause");
	return 0;
}
Exemple #6
0
void backtrack(int i) {
    int j;
 
    if(i > N) {
        showAnswer();
    }
    else {
        for(j = 1; j <= N; j++) {
            if(column[j] == 1 &&
                 rup[i+j] == 1 && lup[i-j+N] == 1) {
                queen[i] = j;
                // 设定为占用
                column[j] = rup[i+j] = lup[i-j+N] = 0;
                backtrack(i+1);
                column[j] = rup[i+j] = lup[i-j+N] = 1;
            }
        }
    }
}
Exemple #7
0
void ChrsGrid::onCountdownCallBack(float dt)
{
	//log ("count=%d", m_countdown);

	//如果倒计时结束,系统给予提示
	if (m_countdown == 0)
	{
		unschedule(schedule_selector(ChrsGrid::onCountdownCallBack));

		//重新启动倒计时
		resetCountdown();
		schedule(schedule_selector(ChrsGrid::onCountdownCallBack), 1);

		//系统演示消除步骤
		showAnswer();
	}

	m_countdown--;
}