Exemplo n.º 1
0
static int event(SDL_Event *event)
{
	if(event->type == SDL_KEYDOWN) {
		switch(event->key.keysym.sym) {
		case SDLK_w:
		case SDLK_k:
			orderMotion(0);
			break;
		case SDLK_s:
		case SDLK_j:
			orderMotion(1);
			break;
		case SDLK_a:
		case SDLK_h:
			orderMotion(2);
			break;
		case SDLK_d:
		case SDLK_l:
			orderMotion(3);
			break;
		default:
			break;
		}
		autoSolveTimer = AUTOSOLVE_WAIT;
	}
	return 0;
}
Exemplo n.º 2
0
// Touch action
const char* PuzzleTV::touch(int action, int x, int y)
{
	LOGI("%s(L=%d): action=%d, x=%d, y=%d", __func__, __LINE__, action, x, y);
	switch(action) {
	case 0: { // Down
		if (movingBlock >= 0) {
			return NULL;
		}
		int bx = x / blockSizeW;
		int by = y / blockSizeH;
		if (bx < 0 || bx >= blockW || by < 0 || by >= blockH) {
			return NULL;
		}
		int bn = bx + by * blockW;
		if (bn - blockW == spaceBlock) {
			orderMotion(0); // Down
			autoSolveTimer = AUTOSOLVE_WAIT;
		} else if (bn + blockW == spaceBlock) {
			orderMotion(1); // Up
			autoSolveTimer = AUTOSOLVE_WAIT;
		} else if (bn - 1 == spaceBlock) {
			orderMotion(2); // Left
			autoSolveTimer = AUTOSOLVE_WAIT;
		} else if (bn + 1 == spaceBlock) {
			orderMotion(3); // Right
			autoSolveTimer = AUTOSOLVE_WAIT;
		}
	} break;
	case 1: // Move
		break;
	case 2: // Up
		break;
	}
	return NULL;
}
Exemplo n.º 3
0
void PuzzleTV::autoSolve(void)
{
#if 1
	return;
#else
	/* FIXME: IMPORTANT BUG: this functions does *NOT* solve the puzzle! */
	static int lastMove = 0;
	static char dir[4];

	if (movingBlock >= 0) return;
	for (int i=0; i<4; i++) {
		dir[i] = i;
	}
	dir[lastMove] = -1;
	int x = spaceBlock % blockW;
	int y = spaceBlock / blockW;
	if (x <= 0) dir[3] = -1;
	if (x >= blockW - 1) dir[2] = -1;
	if (y <= 0) dir[1] = -1;
	if (y >= blockH - 1) dir[0] = -1;

	int max = 0;
	for (int i=0; i<3; i++) {
		if (dir[i] == -1) {
			for (int j=i+1; j<4; j++) {
				if (dir[j] != -1) {
					dir[i] = dir[j];
					dir[j] = -1;
					max++;
					break;
				}
			}
		} else {
			max++;
		}
	}

	if (max > 0) {
		int i = dir[mUtils->fastrand() % max];
		if (orderMotion(i) == 0) {
			if (i < 2) {
				lastMove = 1 - i;
			} else {
				lastMove = 5 - i;
			}
		}
	}
#endif
}
Exemplo n.º 4
0
static void autoSolve(void)
{
	/* IMPORTANT BUG: this functions does *NOT* solve the puzzle! */
	static int lastMove = 0;
	static char dir[4];
	int i, j, x, y, max;

	if(movingBlock >= 0) return;
	for(i=0; i<4; i++) {
		dir[i] = i;
	}
	dir[lastMove] = -1;
	x = spaceBlock % blockW;
	y = spaceBlock / blockW;
	if(x <= 0) dir[3] = -1;
	if(x >= blockW - 1) dir[2] = -1;
	if(y <= 0) dir[1] = -1;
	if(y >= blockH - 1) dir[0] = -1;

	max = 0;
	for(i=0; i<3; i++) {
		if(dir[i] == -1) {
			for(j=i+1; j<4; j++) {
				if(dir[j] != -1) {
					dir[i] = dir[j];
					dir[j] = -1;
					max++;
					break;
				}
			}
		} else {
			max++;
		}
	}

	if(max > 0) {
		i = dir[inline_fastrand() % max];
		if(orderMotion(i) == 0) {
			if(i < 2) {
				lastMove = 1 - i;
			} else {
				lastMove = 5 - i;
			}
		}
	}
}