Example #1
0
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    SimonModel simon;
    //GameEngine engine(w,simon);

    w.show();

    QObject::connect(&w, SIGNAL(RedButtonPushed()), &simon, SLOT(RedPushed()));
    QObject::connect(&w, SIGNAL(BlueButtonPushed()), &simon, SLOT(BluePushed()));
    QObject::connect(&w, SIGNAL(StartButtonPushed()), &simon, SLOT(StartPushed()));
    QObject::connect(&simon, SIGNAL(Highlight(bool, int)), &w, SLOT(ButtonToHighlight(bool, int)));
    QObject::connect(&simon, SIGNAL(DisableStart()), &w, SLOT(disableStart()));
    QObject::connect(&simon, SIGNAL(playersTurn()), &w, SLOT(playersTurn()));
    QObject::connect(&simon, SIGNAL(computersTurn()), &w, SLOT(computersTurn()));
    QObject::connect(&simon, SIGNAL(HighlightDone()), &w, SLOT(HighlightDone()));
    QObject::connect(&simon,SIGNAL(updateStartTime(int)), &w, SLOT(updateStartTime(int)));
    QObject::connect(&simon, SIGNAL(updateProgress(int, int)), &w, SLOT(updateProgress(int, int)));
    QObject::connect(&simon, SIGNAL(wrongMove()), &w, SLOT(wrongMove()));
    QObject::connect(&w, SIGNAL(restart2()), &simon, SLOT(restartSlot()));
    QObject::connect(&simon, SIGNAL(restartSig()), &w, SLOT(restartForModel()));
    QObject::connect(&simon, SIGNAL(updateTextSig(QString)), &w, SLOT(updateText(QString)));
    return a.exec();
}
Example #2
0
/* Move is in form of 103, where 1 is the player's turn and 3 is the matches taken off */
MOVELIST *GenerateMoves (POSITION position)
{
	MOVELIST *moves = NULL;
	int matchCount = numberOfMatches(position);
	int whoseTurn = playersTurn(position);
	int moveCount = 1; /* Minimum move is 1 */
	if(matchCount == 0) {
		moves = CreateMovelistNode(whoseTurn*MULTIPLE, moves);
	}
	else
	if(whoseTurn == FIRST_TURN) {
		while(matchCount > 0 && moveCount <= MAXMOVE) {
			moves = CreateMovelistNode(FIRST_TURN*MULTIPLE + moveCount, moves);
			--matchCount;
			++moveCount;
		}
	}
	else {
		while(matchCount > 0 && moveCount <= MAXMOVE) {
			moves = CreateMovelistNode(SECOND_TURN*MULTIPLE + moveCount, moves);
			--matchCount;
			++moveCount;
		}
	}

	return moves;
}
Example #3
0
int main(int argc, char *argv[]) {
    QApplication a(argc, argv);
    MainWindow w;
    SimonModel simon;
    w.show();

    QObject::connect(&w, SIGNAL(ColorButtonClicked(int)), &simon, SLOT(ColorClicked(int)));
    QObject::connect(&w, SIGNAL(StartButtonClicked()), &simon, SLOT(StartClicked()));
    QObject::connect(&w, SIGNAL(HintRequest()), &simon, SLOT(GiveHint()));
    QObject::connect(&simon, SIGNAL(flashColor(int)), &w, SLOT(flashButtonWithColor(int)));
    QObject::connect(&simon, SIGNAL(flashDone()), &w, SLOT(flashComplete()));
    QObject::connect(&simon, SIGNAL(startToRestart()), &w, SLOT(makeRestartButton()));
    QObject::connect(&simon, SIGNAL(playersTurn()), &w, SLOT(playersTurn()));
    QObject::connect(&simon, SIGNAL(simonsTurn()), &w, SLOT(simonsTurn()));
    QObject::connect(&simon, SIGNAL(updateProgress(int, int)), &w, SLOT(updateProgress(int, int)));
    QObject::connect(&simon, SIGNAL(endGame()), &w, SLOT(gameOver()));
    QObject::connect(&simon, SIGNAL(provideHints(int, int)), &w, SLOT(updateHint(int, int)));


    return a.exec();
}
Example #4
0
/* Actually there is a tie... If there are even matches, even though it doesn't make sense */
VALUE Primitive (POSITION position)
{

	if(gameOver(position)) {
		int whoseTurn = playersTurn(position);
		int firstMatches = firstPlayerMatches(position);
		int secondMatches = secondPlayerMatches(position);
		if(whoseTurn == FIRST_TURN) {
			if((firstMatches % 2) != 0)
				return lose;
			else
				return win;
		}
		else {
			if((secondMatches % 2) != 0)
				return lose;
			else
				return win;
		}
	}
	else
		return undecided;

}