五子棋游戏代码(在win32项目)

这个博客展示了如何在Windows环境下实现一个五子棋游戏。通过解析提供的代码,可以看到游戏的主程序流程,包括窗口注册、初始化、消息处理等。在消息处理中,实现了鼠标点击下的棋子、游戏胜负判断等功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

// dsj.cpp : 定义应用程序的入口点。
//

#include "stdafx.h"
#include "dsj.h"
#include "stdio.h"
#include "music.h"
#define MAX_LOADSTRING 100
#pragma comment(lib,"gdi32.lib")
#pragma comment(lib,"msimg32.lib")
// 全局变量:
//CMusic gmusic;
CMusic *g_music;


static int width=400,size=10;
HINSTANCE hInst;        // 当前实例
TCHAR szTitle[MAX_LOADSTRING];     // 标题栏文本
TCHAR szWindowClass[MAX_LOADSTRING];
int mx ,my;
int HasChess[200][3];
int ChessNum = 0;
int painted[12][12];
bool RorG[12][12];
bool kind;
//int a=900,b=900;
// 此代码模块中包含的函数的前向声明:
ATOM    MyRegisterClass(HINSTANCE hInstance);
BOOL    InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
// 当用户下完一步棋后,判断是否胜出
bool IsWin(bool kind, int x, int y) {
 int min,max;
 min = x;max = x;
 while(min >= 0 && painted[min][y] == 1 && RorG[min][y] == kind) min--;
 while(max <= 11 && painted[max][y] == 1 && RorG[max][y] == kind) max++;
 if(max-min>5) return true;
 min = y,max = y;
 while(min >= 0 && painted[x][min] == 1 && RorG[x][min] == kind) min--;
 while(max <= 11 && painted[x][max] == 1 && RorG[x][max] == kind) max++;
 if(max-min>5) return true;
 min = x,max = x;
 int min1 = y,max1 = y;
 while(min >= 0 && min1 >= 0 && painted[min][min1] == 1 && RorG[min][min1] == kind) {min--;min1--;}
 while(max <= 11 && max1 <= 11 && painted[max][max1] == 1 && RorG[max][max1] == kind) {max++;max1++;}
 if(max-min>5) return true;
 min = x, max = x;
 min1 = y, max1 = y;
 while(min <= 11 && min1 >= 0 && painted[min][min1] == 1 && RorG[min][min1] == kind) {min++;min1--;}
 while(max >= 0 && max1 <= 11 && painted[max][max1] == 1 && RorG[max][max1] == kind) {max--;max1++;}
 if(max1-min1>5) return true;
 return false;
}
// 主窗口类名
int APIENTRY _tWinMain(HINSTANCE hInstance,
        HINSTANCE hPrevInstance,
        LPTSTR    lpCmdLine,
        int       nCmdShow)
{
 // TODO: 在此放置代码。
 MSG msg;
 HACCEL hAccel

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值