写了个五子棋程序(是个智障)

// wzq.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "resource.h"
#include "stdio.h"

char map[22][22];
char map_[22][22];
void deal();

#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE hInst;								// current instance
TCHAR szTitle[MAX_LOADSTRING];								// The title bar text
TCHAR szWindowClass[MAX_LOADSTRING];								// The title bar text

// Foward declarations of functions included in this code module:
ATOM				MyRegisterClass(HINSTANCE hInstance);
BOOL				InitInstance(HINSTANCE, int);
LRESULT CALLBACK	WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK	About(HWND, UINT, WPARAM, LPARAM);

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
 	// TODO: Place code here.
	MSG msg;
	HACCEL hAccelTable;

	for(int i=0;i<22;i++)
	{
		for(int j=0;j<22;j++)
		{
			if((i==0)||(i==21)||(j==0)||(j==21))
			{
				map[i][j]=-1;
			}
			else
			{
				map[i][j]=0;
			}
			map_[i][j]=0;
		}
	}
	// Initialize global strings
	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
	LoadString(hInstance, IDC_WZQ, szWindowClass, MAX_LOADSTRING);
	MyRegisterClass(hInstance);

	// Perform application initialization:
	if (!InitInstance (hInstance, nCmdShow)) 
	{
		return FALSE;
	}

	hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_WZQ);

	// Main message loop:
	while (GetMessage(&msg, NULL, 0, 0)) 
	{
		if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

	return msg.wParam;
}



//
//  FUNCTION: MyRegisterClass()
//
//  PURPOSE: Registers the window class.
//
//  COMMENTS:
//
//    This function and its usage is only necessary if you want this code
//    to be compatible with Win32 systems prior to the 'RegisterClassEx'
//    function that was added to Windows 95. It is important to call this function
//    so that the application will get 'well formed' small icons associated
//    with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
	WNDCLASSEX wcex;

	wcex.cbSize = sizeof(WNDCLASSEX); 

	wcex.style			= CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc	= (WNDPROC)WndProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= 0;
	wcex.hInstance		= hInstance;
	wcex.hIcon			= LoadIcon(hInstance, (LPCTSTR)IDI_WZQ);
	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOW+1);
	wcex.lpszMenuName	= (LPCSTR)IDC_WZQ;
	wcex.lpszClassName	= szWindowClass;
	wcex.hIconSm		= LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);

	return RegisterClassEx(&wcex);
}

//
//   FUNCTION: InitInstance(HANDLE, int)
//
//   PURPOSE: Saves instance handle and creates main window
//
//   COMMENTS:
//
//        In this function, we save the instance handle in a global variable and
//        create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd;

   hInst = hInstance; // Store instance handle in our global variable

   hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

   if (!hWnd)
   {
      return FALSE;
   }

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   return TRUE;
}

//
//  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND	- process the application menu
//  WM_PAINT	- Paint the main window
//  WM_DESTROY	- post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	HDC hdc;
	TCHAR szHello[MAX_LOADSTRING];
	LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);

	switch (message) 
	{
		case WM_COMMAND:
			wmId    = LOWORD(wParam); 
			wmEvent = HIWORD(wParam); 
			// Parse the menu selections:
			switch (wmId)
			{
				case IDM_ABOUT:
				   DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
				   break;
				case IDM_EXIT:
				   DestroyWindow(hWnd);
				   break;
				default:
				   return DefWindowProc(hWnd, message, wParam, lParam);
			}
			break;
		case WM_LBUTTONDOWN:
			RECT myRect;
			int m_x,m_y;
			int r_x,r_y;
			POINT myPoint;
			GetCursorPos(&myPoint);
			GetWindowRect(hWnd,&myRect);
			m_x=myPoint.x-myRect.left-5;
			m_y=myPoint.y-myRect.top-23;
			hdc=GetDC(hWnd);
			r_x=(m_x-(m_x%25))/25;
			r_y=(m_y-(m_y%25))/25;
			if((0<=r_x)&&(r_x<=20)&&(0<=r_y)&&(r_y<=20))
			{
				if(map[r_x][r_y]!=0)
					break;
				else map[r_x][r_y]=2;
				deal();
				int max=0;
				for(int i=0;i<22;i++)
				{
					for(int j=0;j<22;j++)
					{
						if(map_[i][j]>max)
						{
							max=map_[i][j];
						}
					}
				}
				for(i=0;i<22;i++)
				{
					for(int j=0;j<22;j++)
					{
						if(map_[i][j]==max)
						{
							map[i][j]=1;
							goto goto_111; 
						}
					}
				}
goto_111:
				for(i=0;i<20;i++)
				{
					for(int j=0;j<20;j++)
					{
						if(map[i+1][j+1]==1)
						{
							//PALLETTE pal;
							//SelectPalette(hdc,pal,0);
							
							Ellipse(hdc,i*25+25,j*25+25,i*25+50, j*25+50);
							for(int aa=0;aa<10;aa++)
							{
								for(int bb=0;bb<10;bb++)
								{
									SetPixel(hdc,i*25+35+aa,j*25+35+bb,RGB(255,0,0));
								}
							}
							
						}
						if(map[i+1][j+1]==2)
						{
							Ellipse(hdc,i*25+25,j*25+25,i*25+50, j*25+50);
							for(int aa=0;aa<10;aa++)
							{
								for(int bb=0;bb<10;bb++)
								{
									SetPixel(hdc,i*25+35+aa,j*25+35+bb,RGB(0,0,255));
								}
							}
						}
					}
				}
			}
			//char str[50];
			//sprintf(str,"%d %d",r_x,r_y);
			//TextOut(hdc,0,0,str,10);
			//MessageBox(hWnd,str,"ss",0);
			ReleaseDC(hWnd,hdc);
			break;
		case WM_PAINT:
			int i,j;
			hdc = BeginPaint(hWnd, &ps);
			// TODO: Add any drawing code here...
			for(i=0;i<20;i++)
			{
				for(j=0;j<22;j++)
				{
					Ellipse(hdc,i*25+25,j*25+25,i*25+50, j*25+50);
				}
			}
			RECT rt;
			GetClientRect(hWnd, &rt);
			DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
			EndPaint(hWnd, &ps);
			break;
		case WM_DESTROY:
			PostQuitMessage(0);
			break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
   }
   return 0;
}

// Mesage handler for about box.
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
		case WM_INITDIALOG:
				return TRUE;

		case WM_COMMAND:
			if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) 
			{
				EndDialog(hDlg, LOWORD(wParam));
				return TRUE;
			}
			break;
	}
    return FALSE;
}

void deal()
{
	//char temp_[9];
	int sx=0,zy=0,xs=0,xx=0,danbuf1=0,danbuf2=0,danbuf3=0,danbuf4=0;
	for(int i=0;i<22;i++)
	{
		for(int j=0;j<22;j++)
		{
			sx=0,zy=0,xs=0,xx=0,danbuf1=0,danbuf2=0,danbuf3=0,danbuf4=0;
			if(map[i][j]==0)
			{
				for(int a=0;a<=5;a++)
				{
					if((map[i-a][j]==1))
					{
						sx=sx+(5-a);
					}
					if(map[i-a][j]==2)
					{
						sx=sx+4*(5-a);
						danbuf1++;
					}
					if(map[i-a][j]==-1)
					{
						break;
					}
				}
				for(a=0;a<=5;a++)
				{
					if((map[i+a][j]==1))
					{
						sx=sx+(5-a);
					}
					if(map[i+a][j]==2)
					{
						sx=sx+4*(5-a);
						danbuf1++;
					}
					if(map[i+a][j]==-1)
					{
						break;
					}
				}
				for(a=0;a<=5;a++)
				{
					if((map[i][j-a]==1))
					{
						zy=zy+(5-a);
					}
					if(map[i][j-a]==2)
					{
						zy=zy+4*(5-a);
						danbuf2++;
					}
					if((map[i][j-a]==-1))
					{
						break;
					}
				}
				for(a=0;a<=5;a++)
				{
					if((map[i][j+a]==1))
					{
						zy=zy+(5-a);
					}
					if(map[i][j+a]==2)
					{
						zy=zy+4*(5-a);
						danbuf2++;
					}
					if(map[i][j+a]==-1)
					{
						break;
					}
				}
				for(a=0;a<=5;a++)
				{
					if((map[i+a][j+a]==1))
					{
						xx=xx+(5-a);
					}
					if(map[i+a][j+a]==2) 
					{
						xx=xx+4*(5-a);
						danbuf3++;
					}
					if(map[i+a][j+a]==-1)
					{
						break;
					}
				}
				for(a=0;a<=5;a++)
				{
					if((map[i-a][j-a]==1))
					{
						xx=xx+(5-a);
					}
					if(map[i-a][j-a]==2)
					{
						xx=xx+4*(5-a);
						danbuf3++;
					}
					if(map[i-a][j-a]==-1)
					{
						break;
					}
				}
				for(a=0;a<=5;a++)
				{
					if((map[i+a][j-a]==1))
					{
						xs=xs+(5-a);
					}
					if(map[i+a][j-a]==2)
					{
						xs=xs+4*(5-a);
						danbuf4++;
					}
					if(map[i+a][j-a]==-1)
					{
						break;
					}
				}
				for(a=0;a<=5;a++)
				{
					if(map[i-a][j+a]==1)
					{
						xs=xs+(5-a);
					}
					if(map[i-a][j+a]==2)
					{
						xs=xs+4*(5-a);
						danbuf4++;
					}
					if(map[i-a][j+a]==-1)
					{
						break;
					}
				}
				int max=xs;
				if(sx>max)max=sx;
				if(zy>max)max=zy;
				if(xx>max)max=xx;
				if(max==sx)
				{
					map_[i][j]=3*sx+zy+xs+xx;
				}
				if(max==zy)
				{
					map_[i][j]=sx+3*zy+xs+xx;
				}
				if(max==xs)
				{
					map_[i][j]=sx+zy+3*xs+xx;
				}
				if(max==xx)
				{
					map_[i][j]=sx+zy+xs+3*xx;
				}
				if((danbuf1>3)||(danbuf2>3)||(danbuf3>3)||(danbuf4>3))map_[i][j]=100;
				if((danbuf1==3)||(danbuf2==3)||(danbuf3==3)||(danbuf4==3))map_[i][j]=50;
				if((danbuf1==5)||(danbuf2==5)||(danbuf3==5)||(danbuf4==5))
				{
					exit(0);
				}
			}
			else
			{
				map_[i][j]=0;
			}
		}
	}
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值