#include <windows.h>
#define MAX 20//绘制20X20的棋盘
#define TextWidth 200//棋盘右边的宽度
#define ERROR 0
#define NO 0
#define OK 1
#define DEFAULT 0
#define ICO_CUR 0x1000 //预定义光标的id
int leng=1;
HDC hdc,hdc1,hdc2;
int xw,yw;
int iGame[MAX][MAX];
POINT point;//鼠标点击位置
enum {Default,Player1,Player2}play;
enum {Stop,Play,Paush}plays;
void Init(HWND hwnd);
void paint(int play,int x,int y);
void chagePlayer();
int Look(int x,int y,int play);
void over(HWND hwnd,int play);
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
char szClassName[] = "超简单的五子棋";
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)//主函数
{
HWND hwnd;
MSG messages;
WNDCLASSEX wincl;
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hIcon = LoadIcon(hThisInstance,MAKEINTRESOURCE(ICO_CUR));
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
if (!RegisterClassEx (&wincl))
return 0;
hwnd = CreateWindowEx (1,
szClassName,
szClassName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
800,
600,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL
);
ShowWindow (hwnd, nFunsterStil);//该函数设置指定窗口的显示状态
troublemaker什么意思while (GetMessage (&messages, NULL, 0, 0))
{
TranslateMessage(&messages);partnering
DispatchMessage(&messages);
}
return messages.wParam;
}
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) //处理窗口事件
{
PAINTSTRUCT ps;
static HPEN hpen,hpen1,hpen2; //设备
static HBRUSH hbrush,hbrush1,hbrush2; //画刷的句柄
int x,y;
switch (message) //消息
2013考研英语二答案{
ca WM_KEYDOWN:
switch (wParam)
{
ca VK_F2: //F2重新开始游戏
酒店面试问题及回答Init(hwnd); //初始绘制游戏界面
Rectangle(hdc,0,0,xw,yw);
for(x=0;x<MAX;x++) //绘制棋盘
for(y=0;y<MAX;y++)
{
Rectangle(hdc,x*xw/MAX,y*yw/MAX,(x+1)*xw/MAX,(y+1)*yw/MAX) ;
iGame[x][y]=Default; the interview
}
leng=1;
plays=Play;
break;
ca VK_F1:
leng=1;
plays=Play;
break;
}
break;
ca WM_CREATE: //初始化窗体时调用
plays=Stop;
play=Player1;
break;
ca WM_SIZE:
xw=LOWORD(lParam); //获取窗体的宽度
yw=HIWORD(lParam); //获取窗体的高度
//TCHAR xx[20];
//wsprintf(xx,"%d",xw);
//MessageBox(hwnd,xx,xx,MB_OK);
xw-=TextWidth; //xw保存棋盘的宽度
InvalidateRect(hwnd,NULL,TRUE);//向窗体绘制一个矩形,支持重新绘制
break;
ca WM_LBUTTONDOWN: //响应用户鼠标左键
cosma//获取但前鼠标坐标
point.x=LOWORD(lParam);
point.y=HIWORD(lParam);
//初始化设备DC
Init(hwnd);
//鼠标坐标换为数组坐标
x=(point.x)/(xw/MAX); //定位到小狂格中去
y=(point.y)/(yw/MAX);
if(plays==Stop)
break;
if(x<MAX&&y<MAX) //未超出棋盘
{
if(iGame[x][y]==Default&&plays==Play)//判断但前位置是否有棋子覆盖 是否是下棋模式英语四级2021年报名时间
{
leng=1;
paint(play,x,y);
if(Look(x,y,play))
over(hwnd,play);
chagePlayer();
}
}
break;
ca WM_PAINT://开始绘制
{
hdc=BeginPaint(hwnd,&ps);
Init(hwnd);
Rectangle(hdc,0,0,xw,yw);
for(x=0;x<MAX;x++)
for(y=0;y<MAX;y++)
{
ccip Rectangle(hdc,x*xw/MAX,y*yw/MAX,(x+1)*xw/MAX,(y+1)*yw/MAX) ;
paint(iGame[x][y],x,y);
}
EndPaint(hwnd,&ps);
}
break;
ca WM_DESTROY: //当用户关闭游戏
PostQuitMessage (0); // 发送一个消息给message queue
break; universiade
default: //什么都不做
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
void Init(HWND hwnd) //初始化方法
{
hdc1=GetDC(hwnd);
hdc2=GetDC(hwnd);
//初始背景 (游戏的界面)
SelectObject(hdc,CreatePen(0,1,RGB(0,0,0))); //小矩形框的边框的颜色
SelectObject(hdc,CreateSolidBrush(RGB(255,218,185))); //填充的颜色
//初始玩家一图形
SelectObject(hdc1,CreatePen(0,1,RGB(255,255,255))); //玩家一的棋子颜色
SelectObject(hdc1,CreateSolidBrush(RGB(255,255,255))); //填充白色
//初始玩家二图形
SelectObject(hdc2,CreatePen(0,1,RGB(255,255,255))); //玩家二的棋子颜色
SelectObject(hdc2,CreateSolidBrush(RGB(0,0,0))); //填充黑色南瓜的英文
//该背景分为两层背景,一层为游戏界面(hdc),一层为玩家的棋子(hdc1,hdc2)
//SetBkMode(hdc,0);该方法好像没什么用
//绘制右边操作提示区域
Rectangle(hdc,xw,29,xw+200,30);//从xw开始绘制到xw+200结束(绘制长200宽为30-29的矩形)的线条
TextOut(hdc,xw+45,13,"超简单的五子棋",14); //从坐标(xw+45)(13)开始绘制“超简单的五子棋”宽为14
TextOut(hdc,xw+45,40,"F1 - 开始游戏",13);
TextOut(hdc,xw+45,60,"F2 -重新开始游戏",16);
Rectangle(hdc,xw,80,xw+200,81);
TextOut(hdc,xw+45,150,"白棋为第二玩家",14);
TextOut(hdc,xw+45,250,"黑棋为第二玩家",14);