Пример #1
0
// Draw the given board using the provided device context
void SimpleGoPanel::DrawBoard(wxDC& dc, char board[21][21])
{	for(int i=0; i<21; i++)
		for(int j=0; j<21; j++)
		{	if(i>=1&&j>=1&&i<=boardsize&&j<=boardsize)
			{	DrawStone(dc, i, j, board[i][j]);
				if(gnugoscore && board[i][j]!=gnugoboard[i][j])
					DrawStone(dc, i, j, AREA(gnugoboard[i][j]));
			}
			else
			{	dc.SetBrush(*wxWHITE_BRUSH);
				dc.SetPen(*wxWHITE_PEN);
				dc.DrawRectangle(16*i-8, 16*j-8, 16, 16);
			}
		}
}
Пример #2
0
// Make a move on cell (x, y) if legal, and update the current board info and history
void SimpleGoPanel::MakeMove(int x, int y)
{	if(x<=0 || y<=0 || x>boardsize || y>boardsize)
		return;
	char temp[21][21];
	memcpy(temp, board, BOARDMEMORYLEN);
	
	if(ValidMove(temp, x, y, curmove%2+1))
	{	board[x][y] = curmove%2+1;
		wxClientDC dc(this);
		DrawStone(dc, x, y, curmove%2+1);
		if(memcmp(temp, board, BOARDMEMORYLEN))
		{	for(int i=0; i<21; i++)
				for(int j=0; j<21; j++)
					if(temp[i][j]!=board[i][j])
						DrawStone(dc, i, j, temp[i][j]);
			memcpy(board, temp, BOARDMEMORYLEN);

			if(board[x][y] == EMPTY)
				frame->madesuicide = true;
		}
		
		if(gnugoscore)
		{	gnugoscore = false;
			DrawBoard(dc, board);
		}
		curmove++;
		history = (char(*)[21][21])realloc(history, (curmove+1)*BOARDMEMORYLEN);
		memcpy(history[curmove], board, BOARDMEMORYLEN);
		movelist = (pos*)realloc(movelist, curmove*sizeof(pos));
		movelist[curmove-1].x = x;
		movelist[curmove-1].y = y;
		totmove = curmove;
		UpdateStatus();
		gnugopause = false;
	}
}
Пример #3
0
LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch( msg )
	{
		case WM_LBUTTONDOWN:
		{
			// 1. 검은돌 차례인가?
			// 2. 현재 좌표에 돌이 없는가? ( board 배열 확인 )
			// 3. 돌을 그린다...
			POINTS  pt = MAKEPOINTS(lParam);
			pt.x	= (( pt.x) / 30 ) * 30 + 5;
			pt.y    = (( pt.y)/ 30 ) * 30 + 5;

			HDC hdc = GetDC(hwnd);
			// 돌을 화면상에 그리는 함수 구현
			DrawStone(hdc, pt.x, pt.y, BLACK);
			ReleaseDC(hwnd, hdc);

			// 4. board 배열 수정
			// 5. 이겼는가?
			// 6. 흰돌차례가 되도록 변수 수정..
		}
		return 0;

	case WM_CREATE:
		{
		hPen = (HBITMAP)LoadImage(0, "Pan.bmp", IMAGE_BITMAP, 0, 0, 
										LR_LOADFROMFILE);
		hBlack = (HBITMAP)LoadImage(0, "black.bmp", IMAGE_BITMAP, 0, 0, 
										LR_LOADFROMFILE);
		hWhite = (HBITMAP)LoadImage(0, "white.bmp", IMAGE_BITMAP, 0, 0, 
										LR_LOADFROMFILE);
		//--------------------------------------------------------------
		RECT r = { 0, 0, 610, 610 };

		// 원하는 클라이언트의 크기로 설정...
		AdjustWindowRect(&r, 
					GetWindowLong(hwnd, GWL_STYLE), FALSE);

		int cx = r.right	- r.left	;
		int cy = r.bottom	- r.top		;
		MoveWindow(hwnd, 0, 0, cx, cy, TRUE);
		}
		//----------------------------------------------------
		return 0;

	case WM_PAINT:
		{
			PAINTSTRUCT ps;
			HDC hdc		= BeginPaint(hwnd, &ps);
			HDC memDC	= CreateCompatibleDC(hdc);
			HBITMAP old = (HBITMAP)SelectObject(memDC, hPen);

			BitBlt(hdc, 0, 0, 610, 610, memDC, 0, 0, SRCCOPY);

			SelectObject(memDC, old);
			DeleteDC(memDC);

			EndPaint(hwnd , &ps);
		}
		return 0;

	case WM_RBUTTONDOWN:
		return 0;
	case WM_DESTROY:
		//---------------------------------
		DeleteObject(hPen);
		DeleteObject(hBlack);
		//---------------------------------
		PostQuitMessage(0);
		return 0;
	}
	return DefWindowProc(hwnd, msg, wParam, lParam);
}