Exemplo n.º 1
0
void HelloWorld::gameRefreshCallback(Ref* pSender)
{
	pSetGame->shuffleBoard();	

	while (!(pSetGame->isBoardSolution())) {
		pSetGame->shuffleBoard();
	}

	pBoardArray = pSetGame->getBoard();

	refreshGrid(pBoardArray);
}
Exemplo n.º 2
0
void HelloWorld::arrangeBoard(int answerSheet[])
{
	std::vector<int> vStackValue1;
	std::vector<int> vStackValue2;
	std::vector<int> vStackValue3;

	std::vector<int> vStacknewValue1;
	std::vector<int> vStacknewValue2;
	std::vector<int> vStacknewValue3;

	int selectedIndex[3];

	for (int i = 0; i < 3; i++) {
		vStackValue1.push_back(pBoardArray[i * 3]);
		vStackValue2.push_back(pBoardArray[i * 3 + 1]);
		vStackValue3.push_back(pBoardArray[i * 3 + 2]);
	}

	for (int i = 0; i < 3; i++) {
		int value = answerSheet[i];
		for (int j = 0; j < mGrid.size(); j++) {
			if (mGrid.at(j)->getTag() == value) {
				selectedIndex[i] = j;
				break;
			}
		}
		mGrid.at(selectedIndex[i])->setTexture("black.png");
	}
	
	for (int i = 0; i < 3; i++) {
		int remainder = selectedIndex[i] % 3;
		switch (remainder) {
		case 0:
			vStackValue1[selectedIndex[i] / 3] = -1;
			break;
		case 1:
			vStackValue2[selectedIndex[i] / 3] = -1;
			break;
		case 2:
			vStackValue3[selectedIndex[i] / 3] = -1;
			break;
		default:
			break;
		}
	}

	printf(">> ArrangeBoard : \n");
	for (int i = 0; i < 3; i++) {

		printf(" %d %d %d\n", vStackValue1[i], vStackValue2[i], vStackValue3[i]);
	}

	vStackValue1.erase(std::remove(vStackValue1.begin(), vStackValue1.end(), -1), vStackValue1.end());
	vStackValue2.erase(std::remove(vStackValue2.begin(), vStackValue2.end(), -1), vStackValue2.end());
	vStackValue3.erase(std::remove(vStackValue3.begin(), vStackValue3.end(), -1), vStackValue3.end());

	for (int i = 0; i < 3; i++) {
		vStacknewValue1.push_back(-1);
		vStacknewValue2.push_back(-1);
		vStacknewValue3.push_back(-1);
	}

	for (int i = 0; i < vStackValue1.size(); i++) {
		vStacknewValue1[i] = vStackValue1[i];
	}

	for (int i = 0; i < vStackValue2.size(); i++) {
		vStacknewValue2[i] = vStackValue2[i];
	}

	for (int i = 0; i < vStackValue3.size(); i++) {
		vStacknewValue3[i] = vStackValue3[i];
	}

	printf(">> ArrangeBoard : \n");
	for (int i = 0; i < 3; i++) {
		
		printf(" %d %d %d\n", vStacknewValue1[i], vStacknewValue2[i], vStacknewValue3[i]);
	}

	for (int i = 0; i < vStacknewValue1.size(); i++) {
		pBoardArray[i * 3] = vStacknewValue1[i];
	}

	for (int i = 0; i < vStacknewValue2.size(); i++) {
		pBoardArray[i * 3 + 1] = vStacknewValue2[i];
	}

	for (int i = 0; i < vStacknewValue3.size(); i++) {
		pBoardArray[i * 3 + 2] = vStacknewValue3[i];
	}

	pSetGame->setBoard(pBoardArray);
	pSetGame->redesignBoard();
	

	bool check = pSetGame->isBoardSolution();
	
	

	//while (!(pSetGame->isBoardSolution())) {
	//	pSetGame->shuffleBoard();
	//}

	refreshGrid(pBoardArray);
}
Exemplo n.º 3
0
/********************************************************************
 * update()
 * 	This method is in charge of always keeping the grid up to date.
 * 	It needs info from the mouse in order to do this.
 ********************************************************************/
void Grid :: update(const Input & input) {
	char state = NONE;
	bool same = true;

	// STEP 1 - UPDATE COORDS
	if (input.didMouseMove()) {
		int row = (int) (input.mouseX() / x1);
		int col = (int) (input.mouseY() / y1);

		// Make sure the spaces keep their bounds.
		if (row > 2)
			row = 2;
		else if (row < 0)
			row = 0;

		if (col > 2)
			col = 2;
		else if (col < 0)
			col = 0;

		// DEBUG
		//std::cout << "ROW: " << row << " | COL: " << col << std::endl;
		same = (curRow == row && curCol == col);

		if (!same) {
			curRow = row;
			curCol = col;
		}
	}

	// STEP 2 - FIGURE OUT STATUS
	if (input.mousePressed() && input.mouseDown()) {
		// Reason for the and, if you press a mouse quickly enough,
		// it will release and press in the same turn. When it is
		// released, it will no longer be down. We don't want mouse
		// input to be that quick.
		state = PRESS;
	} else if (input.mouseDown()) {
		if (!same)
			refreshGrid();

		//if (gridStates[curRow][curCol] == SELECT)
			//state = SELECT;
		//else
			//state = DOWN;
		state = DOWN;

	} else if (input.mouseReleased()) {
		clearGrid();
		state = RELEASE;
	} else {
		if (!same)
			clearGrid();
		state = HOVER;
	}

	// STEP 3 - UPDATE GRID
	gridStates[curRow][curCol] = state;

	// STEP 4 - UPDATE TO GL
	glUseProgram(mprogram);
	glUniform2f(glGetUniformLocation(mprogram, "mpos"), input.mouseX(), input.mouseY());
}