| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 590 人关注过本帖
标题:关于API的一些问题新手求教
只看楼主 加入收藏
poxsorry
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2012-5-9
结帖率:0
收藏
已结贴  问题点数:20 回复次数:4 
关于API的一些问题新手求教
下面是一个扫雷的程序    为什么会出现下面问题  WIN7系统VC++6.0开发的
#include <assert.h>
#include <windowsx.h>
#include "resource.h"
#include "WinMine.h"

// the only global variable
extern BOARD board;

void TranslateMouseMsg(UINT* puMsg, WPARAM wParam)
{
    if (*puMsg == WM_LBUTTONDOWN)
        SetCapture(board.hWnd);
    else if (*puMsg == WM_LBUTTONUP)
        ReleaseCapture();
    else if ((*puMsg == WM_MOUSEMOVE) && (wParam & MK_LBUTTON))
    {
        *puMsg = WM_LBUTTONDOWN;
    }
}

void ProcessMouseMsg(UINT uMsg, LPARAM lParam)
{
    POINT pt;
    int row, col;

    pt.x = GET_X_LPARAM(lParam);
    pt.y = GET_Y_LPARAM(lParam);

    if (PtInRect(&board.FaceRect, pt))
    {
        if (uMsg == WM_LBUTTONDOWN)
        {
            DisplayFace(FACE_DOWN);
        }
        else if (uMsg == WM_LBUTTONUP)
        {
            NewGame();
        }
        return;
    }

    if (board.GameState == GAMEWON)
    {
        DisplayFace(FACE_WIN);
        return;
    }
    else if (board.GameState == GAMELOST)
    {
        DisplayFace(FACE_LOSE);
        return;
    }

    Pt2RowCol(pt, &row, &col);

    if (uMsg == WM_LBUTTONDOWN)
    {
        DisplayFace(FACE_CAUTION);

        if (row != board.rowPressed || col != board.colPressed)
        {
            UnPressBox();
            PressBox(row, col);
        }
    }
    else
    {
        UnPressBox();
        if (row < 0)
        {
            // row<0 means we clicked outside the grid
            DisplayFace(FACE_HAPPY);
            return;
        }

        if (uMsg == WM_LBUTTONUP)
        {
            if (board.GameState == WAITING)
            {
                LayMines(row, col);
                board.GameState = PLAYING;
            }

            if (StepBox(row, col))
            {
                if (board.uSteps == board.uMaxSteps)
                    GameWon();
                else
                    DisplayFace(FACE_HAPPY);
            }
            else
                GameLost();
        }
        else if (uMsg == WM_RBUTTONUP && board.GameState != WAITING)
        {
            if (board.Box[row][col].State == BS_DICEY)
            {
                SetAndDispBoxState(row, col, BS_INITIAL);
            }
            else if (board.Box[row][col].State == BS_FLAG)
            {
                SetAndDispBoxState(row, col, board.bMark? BS_DICEY : BS_INITIAL);
                IncMinesLeft();
            }
            else if (board.Box[row][col].State == BS_INITIAL
                && (board.uMinesLeft != 0))
            {
                SetAndDispBoxState(row, col, BS_FLAG);
                DecMinesLeft();
            }
        }
    }
}


void Pt2RowCol(POINT pt, int *prow, int *pcol)
{
    if (PtInRect(&board.GridRect, pt))
    {
        *prow = (pt.y - board.GridRect.top) / BOX_HEIGHT;
        *pcol = (pt.x - board.GridRect.left) / BOX_WIDTH;
    }
    else
    {
        *prow = -1;
        *pcol = -1;
    }
}

void PressBox(int row, int col)
{
    if ( (row >= 0) &&
        (board.Box[row][col].State == BS_INITIAL ||
        board.Box[row][col].State == BS_DICEY))
    {
        assert(col >= 0);

        board.rowPressed = row;
        board.colPressed = col;
        
        SetAndDispBoxState(row, col,
            (board.Box[row][col].State == BS_INITIAL)? BS_DOWN: BS_DICEY_DOWN);
    }
}


void UnPressBox()
{
    if (board.rowPressed >= 0)
    {
        BOX_STATE state = board.Box[board.rowPressed][board.colPressed].State;
        assert(state == BS_DOWN || state == BS_DICEY_DOWN);

        SetAndDispBoxState(board.rowPressed, board.colPressed,
            (state == BS_DOWN)? BS_INITIAL : BS_DICEY);

        board.rowPressed = -1;
        board.colPressed = -1;
    }
}

void LayMines(int row, int col)
{
    UINT cMines = 0;
    UINT r, c;

    // temporarily mark this box as mine
    board.Box[row][col].fMine = TRUE;
    srand(GetTickCount());

    while (cMines < board.uMines)
    {
        r = ((UINT) rand()) % board.uRows;
        c = ((UINT) rand()) % board.uCols;

        if (!board.Box[r][c].fMine)
        {
            board.Box[r][c].fMine = TRUE;
            cMines++;
        }
    }

    // remove the mine attribute of the box
    board.Box[row][col].fMine = FALSE;
}

void GameWon()
{
    UINT r, c;

    board.GameState = GAMEWON;
    ZeroMinesLeft();
    DisplayFace(FACE_WIN);

    for (r = 0; r < board.uRows; r++)
        for (c = 0; c < board.uCols; c++)
        {
            if (board.Box[r][c].fMine && board.Box[r][c].State != BS_FLAG)
            {
                SetAndDispBoxState(r, c, BS_FLAG);
            }
        }
        
}

void GameLost()
{
    UINT r, c;

    board.GameState = GAMELOST;
    DisplayFace(FACE_LOSE);

    for (r = 0; r < board.uRows; r++)
        for (c = 0; c < board.uCols; c++)
        {
            if (board.Box[r][c].fMine && board.Box[r][c].State != BS_BLAST)
            {
                SetAndDispBoxState(r, c, BS_MINE);
            }
            else if (board.Box[r][c].State == BS_FLAG)
            {
                SetAndDispBoxState(r, c, BS_WRONG);
            }
        }
}


#define WITHIN_GRID(r, c) \
    ( (UINT) r < board.uRows && (UINT) c < board.uCols )

// Count the mines surrounding the box
UINT CountMines(int row, int col)
{
    UINT cMines = 0;
    int r, c;

    for (r = row-1; r <= row+1; r++)
        for (c = col-1; c <= col+1; c++)
        {
            if (WITHIN_GRID(r, c) && (r != row || c != col) &&
                board.Box[r][c].fMine)
            {
                cMines++;
            }
        }

    return cMines;
}

// steps on this box, return value indicates if it is safe
BOOL StepBox(int row, int col)
{
    UINT cMinesSurround;

    if (board.Box[row][col].State != BS_INITIAL &&
        board.Box[row][col].State != BS_DICEY)
    {
        // previously stepped, must be safe, and no need to step second time
        return TRUE;
    }

    if (board.Box[row][col].fMine)
    {
        // stepped on a mine!
        SetAndDispBoxState(row, col, BS_BLAST);
        return FALSE;
    }

    board.uSteps++;
    cMinesSurround = CountMines(row, col);
    SetAndDispBoxState(row, col, BS_DOWN - cMinesSurround);

    if (cMinesSurround == 0)
    {
        int r, c;

        for (r = row-1; r <= row+1; r++)
            for (c = col-1; c <= col+1; c++)
            {
                if (WITHIN_GRID(r, c) && (r != row || c != col))
                {
                    StepBox(r, c);
                }
            }
    }

    return TRUE;
}


该程序是没有语法问题的  但是在编译的时候会出现下面错误而无法连接

--------------------Configuration: MineGame - Win32 Debug--------------------
Linking...
MineGame.obj : error LNK2001: unresolved external symbol _board
MineGame.obj : error LNK2001: unresolved external symbol _DecMinesLeft
MineGame.obj : error LNK2001: unresolved external symbol _IncMinesLeft
MineGame.obj : error LNK2001: unresolved external symbol _SetAndDispBoxState
MineGame.obj : error LNK2001: unresolved external symbol _NewGame
MineGame.obj : error LNK2001: unresolved external symbol _DisplayFace
MineGame.obj : error LNK2001: unresolved external symbol _ZeroMinesLeft
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/MineGame.exe : fatal error LNK1120: 8 unresolved externals
Error executing link.exe.

MineGame.exe - 9 error(s), 0 warning(s)

}
搜索更多相关主题的帖子: only void include 开发 
2012-05-09 16:07
双刃
Rank: 2
等 级:论坛游民
帖 子:7
专家分:28
注 册:2012-5-9
收藏
得分:10 
board、DecMinesLeft、IncMinesLeft这些符号的定义在哪里呢?

编译器说的明白,你的代码里没有。。。。

要吗你有已经编译过的lib、dll库,要吗你要有源码呀,什么都没有,编译器不会知道那堆符号是什么意思的。。。
2012-05-10 00:31
双刃
Rank: 2
等 级:论坛游民
帖 子:7
专家分:28
注 册:2012-5-9
收藏
得分:0 
这不是API的问题,是缺少对象、函数的链接库。。。
2012-05-10 00:32
poxsorry
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2012-5-9
收藏
得分:0 
回复 楼主 poxsorry
懂了
2012-05-10 21:54
冰封之心
Rank: 2
等 级:论坛游民
帖 子:2
专家分:10
注 册:2012-5-12
收藏
得分:10 
好厉害的程序,我是新手,看不懂
2012-05-12 11:00
快速回复:关于API的一些问题新手求教
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.028134 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved