コード例 #1
0
ファイル: Source.cpp プロジェクト: DeVonFire27/DTW_TicTacToe
LRESULT KeyCommands(HWND hWnd, WPARAM wParam)
{
	if (mode == 1)
	{
		short gridPosX = -1, gridPosY = -1;
		SetCursor(cur[game.WhoseTurn()]);

		switch(wParam)
		{
		case VK_NUMPAD1:
			gridPosX = 0; gridPosY = 2;
			break;
		case VK_NUMPAD2:
			gridPosX = 1; gridPosY = 2;
			break;
		case VK_NUMPAD3:
			gridPosX = 2; gridPosY = 2;
			break;
		case VK_NUMPAD4:
			gridPosX = 0; gridPosY = 1;
			break;
		case VK_NUMPAD5:
			gridPosX = 1; gridPosY = 1;
			break;
		case VK_NUMPAD6:
			gridPosX = 2; gridPosY = 1;
			break;
		case VK_NUMPAD7:
			gridPosX = 0; gridPosY = 0;
			break;
		case VK_NUMPAD8:
			gridPosX = 1; gridPosY = 0;
			break;
		case VK_NUMPAD9:
			gridPosX = 2; gridPosY = 0;
			break;

		case VK_LEFT:
			if(!focusVis)
				focusVis = !focusVis;
			else
			{
				if(focus[1].x-200.0f <= 100.0f)
				{
					focus[1].x = 700.0f;
					focus[0].x = 500.0f;
				}
				else
				{
					focus[1].x -= 200.0f;
					focus[0].x -= 200.0f;
				}
			}
			InvalidateRect(hWnd, NULL, true);
			break;
		case VK_RIGHT:
			if(!focusVis)
				focusVis = !focusVis;
			else
			{
				if(focus[1].x+200.0f > 700.0f)
				{
					focus[1].x = 300.0f;
					focus[0].x = 100.0f;
				}
				else
				{
					focus[1].x += 200.0f;
					focus[0].x += 200.0f;
				}
			}
			InvalidateRect(hWnd, NULL, true);
			break;
		case VK_UP:
			if(!focusVis)
				focusVis = !focusVis;
			else
			{
				if(focus[1].y-200.0f <= 100.0f)
				{
					focus[1].y = 700.0f;
					focus[0].y = 500.0f;
				}
				else
				{
					focus[1].y -= 200.0f;
					focus[0].y -= 200.0f;
				}
			}
			InvalidateRect(hWnd, NULL, true);
			break;
		case VK_DOWN:
			if(!focusVis)
				focusVis = !focusVis;
			else
			{
				if(focus[1].y+200.0f > 700.0f)
				{
					focus[1].y = 300.0f;
					focus[0].y = 100.0f;
				}
				else
				{
					focus[1].y += 200.0f;
					focus[0].y += 200.0f;
				}
			}
			InvalidateRect(hWnd, NULL, true);
			break;
		case VK_RETURN:
			float tempX = 0, tempY = 0;
			tempX = (focus[0].x - 100.0f)*0.005f;
			tempY = (focus[0].y - 100.0f)*0.005f;
			if(game.CheckGrid((short)tempX, (short)tempY))
			{
				game.DrawMark();
				InvalidateRect(hWnd, NULL, false);
				if(WinnerCheck(hWnd) == 0)
				{
					if(game.AITurn())
						SetCursor(cur[0]);
					InvalidateRect(hWnd, NULL, false);
					WinnerCheck(hWnd);
				}
			} 
			break;
		}

		if(game.CheckGrid(gridPosX, gridPosY))
		{
			game.DrawMark();
			InvalidateRect(hWnd, NULL, false);
			if(WinnerCheck(hWnd) == 0)
			{
				if(game.AITurn())
					SetCursor(cur[0]);
				InvalidateRect(hWnd, NULL, false);
				WinnerCheck(hWnd);
			}
		} 
	} 
	else if(mode == 99)
		if(wParam == VK_RETURN)
		{
			mode = 1;
			Reset(hWnd);
		}

		return 0;
}
コード例 #2
0
ファイル: Source.cpp プロジェクト: DeVonFire27/DTW_TicTacToe
LRESULT OnLButtonDown(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
	UNREFERENCED_PARAMETER(wParam);

	ptMouse.x = GET_X_LPARAM(lParam);
	ptMouse.y = GET_Y_LPARAM(lParam);

#pragma region MenuLM
	if(mode == 0)
	{
		if(ptMouse.x >=300 && ptMouse.x < 500
			&& ptMouse.y > 125 && ptMouse.y < 575)
		{
			if(ptMouse.y > 125 && ptMouse.y < 175)
			{
				//TicTacToe
				mode = 1;
				EnableMenuItem(GetMenu(hWnd), ID_TICTACTOE_X, MF_ENABLED);
				EnableMenuItem(GetMenu(hWnd), ID_TICTACTOE_O, MF_ENABLED);
				SetColors();
				game.AI(false);
				game.Reset(true);
				ptMouse.x = NULL;
				ptMouse.y = NULL;
				InvalidateRect(hWnd, NULL, true);
			}
			else if(ptMouse.y > 225 && ptMouse.y < 275)
			{
				//HangMan
				mode = 2;
				SetColors();
				ptMouse.x = NULL;
				ptMouse.y = NULL;
				InvalidateRect(hWnd, NULL, true);
			}
			else if(ptMouse.y > 325 && ptMouse.y < 375)
			{
				// 
			}
			else if(ptMouse.y > 425 && ptMouse.y < 475)
			{
				//Options
				mode = 4;
				SetColors();
				ptMouse.x = NULL;
				ptMouse.y = NULL;
				InvalidateRect(hWnd, NULL, true);
			}
			else if(ptMouse.y > 525 && ptMouse.y < 575)
			{
				//Exit
				DestroyWindow(hWnd);
			}
		}
	}
#pragma endregion

#pragma region TicTacToeLM
	if (mode == 1)
	{

		short gridPosX = -1, gridPosY = -1;

		if(ptMouse.x >=100 && ptMouse.x < 700
			&& ptMouse.y > 100 && ptMouse.y < 700)
		{

			if(ptMouse.x > 100 && ptMouse.x < 300)
				gridPosX = 0;
			else if(ptMouse.x > 300 && ptMouse.x < 500)
				gridPosX = 1;
			else
				gridPosX = 2;

			if(ptMouse.y > 100 && ptMouse.y < 300)
				gridPosY = 0;
			else if(ptMouse.y > 300 && ptMouse.y < 500)
				gridPosY = 1;
			else
				gridPosY = 2;
		}

		if(game.CheckGrid(gridPosX, gridPosY))
		{
			game.DrawMark();
			InvalidateRect(hWnd, NULL, false);
			if(WinnerCheck(hWnd) == 0)
			{
				if(game.AITurn())
					SetCursor(cur[0]);
				InvalidateRect(hWnd, NULL, false);
				WinnerCheck(hWnd);
			}
		} 
	}  
#pragma endregion

#pragma region OptionLM
	if(mode == 4)
	{
		if(ptMouse.x >=300 && ptMouse.x < 500
			&& ptMouse.y > 125 && ptMouse.y < 575)
		{
			if(ptMouse.y > 125 && ptMouse.y < 175)
			{
				//Instructions
				mode = 11;
				ptMouse.x = NULL;
				ptMouse.y = NULL;
				InvalidateRect(hWnd, NULL, true);
			}
			else if(ptMouse.y > 225 && ptMouse.y < 275)
			{
				//Cheats
				mode = 12;
				ptMouse.x = NULL;
				ptMouse.y = NULL;
				InvalidateRect(hWnd, NULL, true);
			}
			else if(ptMouse.y > 325 && ptMouse.y < 375)
			{
				//Credit 
				mode = 13;
				ptMouse.x = NULL;
				ptMouse.y = NULL;
				InvalidateRect(hWnd, NULL, true);
			}
			else if(ptMouse.y > 425 && ptMouse.y < 475)
			{
				mode = 0;
				SetColors();
				ptMouse.x = NULL;
				ptMouse.y = NULL;
				InvalidateRect(hWnd, NULL, true);
				//Back
			}

		}
	}
#pragma endregion

#pragma region WinnerLM
	if(mode == 99)
	{
		if(ptMouse.x >=100 && ptMouse.x < 750
			&& ptMouse.y > 600 && ptMouse.y < 700)
		{
			if(ptMouse.x < 350)
			{
				//Yes
				mode = 1;
				SetCursor(cur[0]);
				Reset(hWnd);
			}
			else if(ptMouse.x > 500)
			{
				//No/Exit
				DestroyWindow(hWnd);
			}
		}
	}
#pragma endregion

	return 0;
}