示例#1
0
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	HDC hdc;
	SIZE size;
	POINT point;
	PAINTSTRUCT ps;
	int caption, border;
	static Game game(hwnd);
	static Scene scene(&game);

	switch (message){
	case WM_CREATE:
		size = scene.GetSize();
		caption = GetSystemMetrics(SM_CYCAPTION);
		border = GetSystemMetrics(SM_CXBORDER);
		SetWindowPos(hwnd, NULL, 0, 0,
			size.cx + border * 10, 
			size.cy + caption + border * 10,
			SWP_NOMOVE | SWP_NOZORDER);

		game.LoadPlayerScore();
		scene.InitScene(hwnd);
		game.GameStart();
		scene.DrawBackground();
		return 0;
	case WM_TIMER:
		KillTimer(hwnd, 1);
		switch (game.GetStatus()){
		case NOTSTART:
			game.GameStart();
			break;
		case GETLANDLORD:
			game.GetLandlord();
			break;
		case SENDLANDLORDCARD:
			game.SendLandlordCard();
			break;
		case DISCARD:
			game.Discard();
			break;
		case GAMEOVER:
			game.GameOver();
			break;
		}
		return 0;
	case WM_MYBUTTON:
		switch ((Command)wParam){
		case No:
		case Score1:
		case Score2:
		case Score3:
			scene.HideQuestionBtn();
			game.SendScore(wParam - 1);
			break;
		case Discard:
			//scene.HideDiscardBtn();
			game.Discard();
			break;
		case Pass:
			scene.HideDiscardBtn();
			game.Pass();
			break;
		case Hint:
			game.Hint();
			break;
		}
		return 0;
	case WM_MOUSEMOVE:
		if (!game.IsHumanTurn() || game.GetStatus() != DISCARD)
			return 0;

		point.x = LOWORD(lParam);
		point.y = HIWORD(lParam);
		if (wParam & MK_LBUTTON)
			scene.SelectCard(point);
		else if (wParam & MK_RBUTTON)
			scene.DeleteCard(point);
		return 0;
	case WM_RBUTTONDOWN:
		if (!game.IsHumanTurn() || game.GetStatus() != DISCARD)
			return 0;
		point.x = LOWORD(lParam);
		point.y = HIWORD(lParam);
		scene.DeleteCard(point);
		return 0;
	case WM_LBUTTONDOWN:
		if (!game.IsHumanTurn() || game.GetStatus() != DISCARD)
			return 0;
		point.x = LOWORD(lParam);
		point.y = HIWORD(lParam);
		scene.SelectCard(point);
		return 0;
	case WM_PAINT:
		hdc = BeginPaint(hwnd, &ps);
		scene.ShowScene(hdc);
		EndPaint(hwnd, &ps);
		return 0;
	case WM_DESTROY:
		game.StorePlayerScore();
		PostQuitMessage(0);
		return 0;
	}
	return DefWindowProc(hwnd, message, wParam, lParam);
}