五子棋源代码(VC++6.0)

作者:京东瀚览家居官方旗舰店

 

 

一、头文件

 

//TicTac.h
#define EX 1
#define OH 2

class com
...{
public:
    com(
int i=0int j=0):m(i),n(j)
    
...{
    }
;
    com
& operator=(const com & rv)
    
...{
        m
=rv.m;
        n
=rv.n;
        
return *this;
    }
;
    
int m;
    
int n;
}
//为了保存的棋子的坐标

class CMyApp : public CWinApp
...{
public:
    
virtual BOOL InitInstance ();
}
;

class CMainWindow : public CWnd
...{
protected:
     CRect m_rcSquares[
20][20];    // Grid coordinates
    int m_nGameGrid[20][20];            // Grid contents
    int m_nNextChar;            // Next character (EX or OH)

    com GetRectID (CPoint & point);
    
void DrawBoard (CDC* pDC);
    
void DrawX (CDC* pDC, com & nPos);
    
void DrawO (CDC* pDC, const com & nPos);
    
void ResetGame ();
    
void CheckForGameOver ();
    
int IsWinner ();
    BOOL IsDraw ();

public:
    CMainWindow ();

protected:
    
virtual void PostNcDestroy ();

    afx_msg 
void OnPaint ();
    afx_msg 
void OnLButtonDown (UINT nFlags, CPoint point);
    afx_msg 
void OnLButtonDblClk (UINT nFlags, CPoint point);
    afx_msg 
void OnRButtonDown (UINT nFlags, CPoint point);

    DECLARE_MESSAGE_MAP ()
}
;

二、CPP文件

 

#include <afxwin.h>
#include "TicTac.h"

CMyApp myApp;

/**//
// CMyApp member functions

BOOL CMyApp::InitInstance ()
...{
    m_pMainWnd 
= new CMainWindow;
    m_pMainWnd
->ShowWindow (m_nCmdShow);
    m_pMainWnd
->UpdateWindow ();
    
return TRUE;
}


/**//
// CMainWindow message map and member functions

BEGIN_MESSAGE_MAP (CMainWindow, CWnd)
    ON_WM_PAINT ()
    ON_WM_LBUTTONDOWN ()
    ON_WM_LBUTTONDBLCLK ()
    ON_WM_RBUTTONDOWN ()
END_MESSAGE_MAP ()



CMainWindow::CMainWindow ()
...{
    
//初始化棋子的位置
    for(int i=0;i<20;i++)
    
...{
        
for(int j=0;j<20;j++)
        
...{
            m_rcSquares[i][j]
=CRect( j*50 , i*50 , (j+1)*50 , (i+1)*50 ) ;
        }

    }

    m_nNextChar 
= EX;
    
for(int k=0;k<20;k

  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值