Beispiel #1
0
int main(void){

  printf("整数==> " );
  scanf("%d", &seisu1);
  printf("整数==> " );
  scanf("%d", &seisu2);

  koukan(&seisu1, &seisu2);

  printf("交換後\n");
  printf("整数1=%d\n", seisu1);
  printf("整数2=%d\n", seisu2);
}
Beispiel #2
0
LRESULT CALLBACK WndProc(HWND hWnd,
	UINT msg,
	WPARAM wParam,
	LPARAM lParam)
{
	static HBITMAP hBitmap;
	static BYTE oldpai = (BYTE)-1;
	static BYTE oldx;
	static BYTE oldy;
	static BYTE autoiti1, autoiti2;
	static BYTE zansuu;
	switch (msg)
	{
	case WM_COMMAND:
		switch (LOWORD(wParam))
		{
		case ID_HINT:
			if (zansuu)
			{
				iti2pai[autoiti1] += 72;
				iti2pai[autoiti2] += 72;
				InvalidateRect(hWnd, 0, 0);
				UpdateWindow(hWnd);
				if2Space(autoiti1, autoiti2, 1);
				for (int i = 0; i<4; ++i)
				{
					if (pai2iti[4 * (iti2pai[autoiti1] - 72) + i] == autoiti1)
					{
						pai2iti[4 * (iti2pai[autoiti1] - 72) + i] = 0;
					}
					if (pai2iti[4 * (iti2pai[autoiti1] - 72) + i] == autoiti2)
					{
						pai2iti[4 * (iti2pai[autoiti1] - 72) + i] = 0;
					}
				}
				iti2pai[autoiti1] = (BYTE)-1;
				iti2pai[autoiti2] = (BYTE)-1;
				--zansuu;
				if (!zansuu){
					g_hHook = SetWindowsHookEx(
						WH_CBT,
						CBTProc,
						0,
						GetCurrentThreadId()
						);
					MessageBox(
						hWnd,
						TEXT("完了。"),
						TEXT("四川省"),
						0);
				}
				else if (!GetHint(&autoiti1, &autoiti2))
				{
					zansuu = 0;
					g_hHook = SetWindowsHookEx(
						WH_CBT,
						CBTProc,
						0,
						GetCurrentThreadId()
						);
					MessageBox(
						hWnd,
						TEXT("手詰まりです。"),
						TEXT("四川省"),
						0);
				}
			}
			break;
		case ID_NEWGAME:
		{
			int i, j = 0;
			for (i = 0; i<MAX_KOMASUU; ++i)
			{
				if (i<X_NUM ||
					i>X_NUM*(Y_NUM - 1) ||
					i%X_NUM == 0 ||
					i%X_NUM == X_NUM - 1)
				{
					iti2pai[i] = (BYTE)-1;
					continue;
				}
				iti2pai[i] = j / 4;
				pai2iti[j] = i;
				j++;
			}
			for (i = 0; i<MAX_KOMASUU; ++i)
			{
				if (i<X_NUM ||
					i>X_NUM*(Y_NUM - 1) ||
					i%X_NUM == 0 ||
					i%X_NUM == X_NUM - 1)
					continue;
				do{
					j = rand() % MAX_KOMASUU;
				} while (j<X_NUM ||
					j>X_NUM*(Y_NUM - 1) ||
					j%X_NUM == 0 ||
					j%X_NUM == X_NUM - 1);

				koukan(i, j);
			}
			zansuu = 72;
			if (!GetHint(&autoiti1, &autoiti2))
			{
				zansuu = 0;
				g_hHook = SetWindowsHookEx(
					WH_CBT,
					CBTProc,
					0,
					GetCurrentThreadId()
					);
				MessageBox(
					hWnd,
					TEXT("手詰まりです。"),
					TEXT("四川省"),
					0);
			}
			InvalidateRect(hWnd, 0, 0);
		}
		break;
		}
		break;
	case WM_LBUTTONDOWN:
		if (zansuu)
		{
			InvalidateRect(hWnd, NULL, 0);
			UpdateWindow(hWnd);
			RECT rect;
			int xPos = GET_X_LPARAM(lParam) / PAI_WIDTH;
			int yPos = GET_Y_LPARAM(lParam) / PAI_HEIGHT;
			if (iti2pai[xPos%X_NUM + yPos*X_NUM] == (BYTE)-1)
				break;//空白をクリックしても何も起こらない
			if (oldpai == (BYTE)-1)
			{
				iti2pai[xPos%X_NUM + yPos*X_NUM] += 72;
				SetRect(
					&rect,
					PAI_WIDTH*xPos,
					PAI_HEIGHT*yPos,
					PAI_WIDTH + PAI_WIDTH*xPos,
					PAI_HEIGHT + PAI_HEIGHT*yPos
					);
				InvalidateRect(hWnd, &rect, 0);
				oldpai = iti2pai[xPos%X_NUM + yPos*X_NUM];
				oldx = xPos;
				oldy = yPos;
			}
			else
			{
				if (xPos == oldx&&yPos == oldy)//1番目と同じ座標
				{
					iti2pai[xPos%X_NUM + yPos*X_NUM] -= 72;
					SetRect(
						&rect,
						PAI_WIDTH*xPos,
						PAI_HEIGHT*yPos,
						PAI_WIDTH + PAI_WIDTH*xPos,
						PAI_HEIGHT + PAI_HEIGHT*yPos);
					InvalidateRect(hWnd, &rect, 0);
				}
				else
				{
					iti2pai[xPos%X_NUM + yPos*X_NUM] += 72;
					SetRect(
						&rect,
						PAI_WIDTH*xPos,
						PAI_HEIGHT*yPos,
						PAI_WIDTH + PAI_WIDTH*xPos,
						PAI_HEIGHT + PAI_HEIGHT*yPos);
					InvalidateRect(hWnd, &rect, 0);
					UpdateWindow(hWnd);
					if (oldpai == iti2pai[xPos%X_NUM + yPos*X_NUM] &&
						if2Space(
						xPos%X_NUM + yPos*X_NUM,
						oldx%X_NUM + oldy*X_NUM, 1))
					{
						BOOL b = FALSE;
						for (int i = 0; i<4; ++i)
						{
							if (pai2iti[4 * (oldpai - 72) + i] ==
								oldx%X_NUM + oldy*X_NUM)
							{
								if (!b &&
									(pai2iti[4 * (oldpai - 72) + i] == autoiti1 ||
									pai2iti[4 * (oldpai - 72) + i] == autoiti2))
									b = TRUE;
								pai2iti[4 * (oldpai - 72) + i] = 0;
							}
							if (pai2iti[4 * (oldpai - 72) + i] ==
								xPos%X_NUM + yPos*X_NUM)
							{
								if (!b &&
									(pai2iti[4 * (oldpai - 72) + i] == autoiti1 ||
									pai2iti[4 * (oldpai - 72) + i] == autoiti2))
									b = TRUE;
								pai2iti[4 * (oldpai - 72) + i] = 0;
							}
						}
						iti2pai[xPos%X_NUM + yPos*X_NUM] = (BYTE)-1;
						iti2pai[oldx%X_NUM + oldy*X_NUM] = (BYTE)-1;

						zansuu--;
						if (!zansuu){
							g_hHook = SetWindowsHookEx(
								WH_CBT,
								CBTProc,
								0,
								GetCurrentThreadId());
							MessageBox(
								hWnd,
								TEXT("完了。"),
								TEXT("四川省"), 0);
						}
						else if (b&&
							!GetHint(&autoiti1, &autoiti2))
						{
							zansuu = 0;
							g_hHook = SetWindowsHookEx(
								WH_CBT,
								CBTProc,
								0,
								GetCurrentThreadId()
								);
							MessageBox(
								hWnd,
								TEXT("手詰まりです。"),
								TEXT("四川省"),
								0);
						}
					}
					else
					{
						iti2pai[xPos%X_NUM + yPos*X_NUM] -= 72;
						iti2pai[oldx%X_NUM + oldy*X_NUM] -= 72;
						SetRect(
							&rect,
							PAI_WIDTH*xPos,
							PAI_HEIGHT*yPos,
							PAI_WIDTH + PAI_WIDTH*xPos,
							PAI_HEIGHT + PAI_HEIGHT*yPos);
						InvalidateRect(hWnd, &rect, 0);
						SetRect(
							&rect,
							PAI_WIDTH*oldx,
							PAI_HEIGHT*oldy,
							PAI_WIDTH + PAI_WIDTH*oldx,
							PAI_HEIGHT + PAI_HEIGHT*oldy);
						InvalidateRect(hWnd, &rect, 0);
					}
				}
				oldpai = (BYTE)-1;
			}
		}
		break;
	case WM_TIMER:
		KillTimer(hWnd, 0x1234);
		InvalidateRect(hWnd, 0, 0);
		break;
	case WM_CREATE:
		srand(GetTickCount());
		hBitmap = LoadBitmap(
			GetModuleHandle(0),
			MAKEINTRESOURCE(IDB_BITMAP1));
		SNDMSG(hWnd, WM_COMMAND, ID_NEWGAME, 0);
		break;
	case WM_ERASEBKGND:
		return 1;
	case WM_PAINT:
	{
		PAINTSTRUCT ps;
		HDC hdc = BeginPaint(hWnd, &ps);
		HDC hdc_mem = CreateCompatibleDC(hdc);
		SelectObject(hdc_mem, hBitmap);
		for (int i = 0; i<MAX_KOMASUU; ++i)
		{
			if (iti2pai[i] == (BYTE)-1)
			{
				RECT rect;
				SetRect(
					&rect,
					PAI_WIDTH*(i%X_NUM),
					PAI_HEIGHT*(i / X_NUM),
					PAI_WIDTH + PAI_WIDTH*(i%X_NUM),
					PAI_HEIGHT + PAI_HEIGHT*(i / X_NUM));
				COLORREF clrPrev = SetBkColor(hdc, RGB(0, 128, 0));
				ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0);
				SetBkColor(hdc, clrPrev);
			}
			else
			{
				BitBlt(
					hdc,
					(i%X_NUM)*PAI_WIDTH,
					(i / X_NUM)*PAI_HEIGHT,
					PAI_WIDTH, PAI_HEIGHT,
					hdc_mem,
					iti2pai[i] % 72 * PAI_WIDTH,
					(iti2pai[i]<36) ? 0 : PAI_HEIGHT,
					SRCCOPY);
			}
		}
		DeleteDC(hdc_mem);
		EndPaint(hWnd, &ps);
	}
	break;
	case WM_DESTROY:
		DeleteObject(hBitmap);
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hWnd, msg, wParam, lParam);
	}
	return 0;
}