Exemplo n.º 1
0
	void Board::UndoMove(const Move& inputMove, Players player){
		_moveFinder->Invalidate();
		Move move = ShiftMoveBack(inputMove);
		Vector2D from = _converter->ToAbsolute(move.GetFromCell());
		Vector2D to = _converter->ToAbsolute(move.GetToCell());
		Vector2D used;
		if(move.HasUsedCell()){
			used = _converter->ToAbsolute(move.GetUsedCell());
		}
		switch(move.GetMoveType()){
			case INSERT:
				DeletePiece(*_grid->GetCellAt(to));
			return;
			case STEP:
				if(move.HasUsedCell()){
					MovePiece(
						*_grid->GetCellAt(to), 
						*_grid->GetCellAt(from), 
						player
					);
					MoveTile(*_grid->GetCellAt(to), *_grid->GetCellAt(used));
					return;
				}
				MovePiece(
					*_grid->GetCellAt(to), 
					*_grid->GetCellAt(from), 
					player
				);
			return; 
			case JUMP:
				if(move.HasUsedCell()){
					JumpPiece(
						*_grid->GetCellAt(to), 
						*_grid->GetCellAt(from), 
						player
					);
					MoveTile(*_grid->GetCellAt(to), *_grid->GetCellAt(used));
					return;
				}
				JumpPiece(
					*_grid->GetCellAt(to), 
					*_grid->GetCellAt(from), 
					player
				);
			return; 

		}
	}
Exemplo n.º 2
0
//Function moves clicked tiles
void Fifteen::ClickTile()
{	
	if (gamearea.newClick)
	{
		int x = gamearea.clickpos.x / GetTileSizeX();
		int y = gamearea.clickpos.y / GetTileSizeY();	
		MoveTile(x,y);
		gamearea.newClick = false;
	}
}
Exemplo n.º 3
0
//Move tiles with keyboard arrows
bool Fifteen::Key(dword key, int count)
{
	
	if (key == K_DOWN)
	{
		if(zeroY > 0)
		{
			MoveTile(zeroX, zeroY - 1);
		}
	}
	
	else if (key == K_LEFT)
	{
		if(zeroX < SIZE - 1)
		{
			MoveTile(zeroX + 1, zeroY);
		}
	}
	
	else if (key == K_UP)
	{
		if(zeroY < SIZE - 1)
		{
			MoveTile(zeroX, zeroY + 1);
		}
	}
	
	else if (key == K_RIGHT)
	{
		if(zeroX > 0)
		{
			MoveTile(zeroX - 1, zeroY);
		}
	}
	
	return false;

}
Exemplo n.º 4
0
/*
 * Read the next event and handle it.
 */
static void
HandleEvents(GR_EVENT *ep)
{
int hole_x_pos, hole_y_pos;
int tempx, tempy;

	switch (ep->type) {
		case GR_EVENT_TYPE_BUTTON_DOWN:
			if (ep->button.wid == buttons) {
 				if (ep->button.x < (calc_width/2)) {
					/* 'Again' */
					RandomiseTiles();
					RefreshWindow();
 				} else {
					/* 'Quit' */
					GrClose();
#if USE_IMAGE
					if (using_image)
						free(image_addr);
#endif
					exit(0);
				}
			}

			if (ep->button.wid == tiles) {
				/* Try to move selected tile */
				MoveTile( (int)(ep->button.x / tile_width),
					(int)(ep->button.y / tile_height) );
			}
			break;

		case GR_EVENT_TYPE_KEY_DOWN:
			if (ep->keystroke.wid == master) {
				hole_x_pos = 0;
				hole_y_pos = 0;

				/* Find hole position */
				for (tempx = 0; tempx < WIDTH_IN_TILES; tempx++)
					for (tempy = 0; tempy < HEIGHT_IN_TILES; tempy++)
						if (value[tempx][tempy] == MAX_TILES) {
							hole_x_pos = tempx;
							hole_y_pos = tempy;
						}
	
				switch (ep->keystroke.ch) {
					case 'q':
					case 'Q':
					case MWKEY_CANCEL:
						GrClose();
#if USE_IMAGE
						if (using_image)
							free(image_addr);
#endif
						exit(0);

					case 'r':
					case 'R':
						RandomiseTiles();
						RefreshWindow();
						break;

					/* remember you are moving the tile. not the hole */
					case MWKEY_DOWN:
						if (hole_y_pos != 0) {
							MoveTile(hole_x_pos, hole_y_pos - 1);
						}
						break;
							
					case MWKEY_UP:
						if (hole_y_pos != (HEIGHT_IN_TILES-1) ) {
							MoveTile(hole_x_pos, hole_y_pos + 1);
						}
						break;

					case MWKEY_RIGHT:
						if (hole_x_pos != 0) {
							MoveTile(hole_x_pos - 1, hole_y_pos);
						}
						break;

					case MWKEY_LEFT:
						if (hole_x_pos != (WIDTH_IN_TILES-1) ) {
							MoveTile(hole_x_pos + 1, hole_y_pos);
						}
						break;
				}
			}
			break;

		case GR_EVENT_TYPE_EXPOSURE:
			RefreshWindow();
			break;
		case GR_EVENT_TYPE_CLOSE_REQ:
			GrClose();
			exit(0);
	}

}
Exemplo n.º 5
0
	void Board::MovePiece(Cell<int>& from, Cell<int>& to, Players owner, Cell<int>& tileUsed){
		// convertions already happend save to update converter
		_moveFinder->Invalidate();
		MoveTile(tileUsed, to);
		MovePiece(from, to, owner);
	}