| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 6359 人关注过本帖
标题:All about windows programming
取消只看楼主 加入收藏
kai
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:52
帖 子:3450
专家分:59
注 册:2004-4-25
收藏
得分:0 
// wuziqi.h

#include <windows.h>

#include <string>

#include <vector>



#ifndef WUZIQI_H_

#define WUZIQI_H_



class Point

{

private:

    int x;

    int y;

    int state;

public:

    enum{NOCHESSMAN = -1, BLACK = 0, WHITE = 1};

    Point(int _x = 0, int _y = 0, int s = -1) : x(_x), y(_y), state(s){}

    void reset(){ state = NOCHESSMAN; }

    void setBlack(){ state = BLACK; }

    void setWhite(){ state = WHITE; }

    int getState(){ return state; }

    int getX(){ return x; }

    int getY(){ return y; }

};



class Mark

{

private:

    POINT point;

    COLORREF color;

public:

    Mark(){}

    Mark(const POINT & _point) : point(_point){ color = RGB(255, 0, 0);}

    Mark(int x, int y)

    {

        point.x = x;

        point.y = y;

        color = RGB(255, 0, 0);

    }

    bool operator!=(const Mark & anotherMark)

    {

        return (point.x != anotherMark.point.x || point.y != anotherMark.point.y);

    }

    void setColor(const COLORREF & col)

    {

        color = col;

    }

    void paintMark(HWND hwnd);

    void erase(HWND hwnd, const COLORREF & col);

};

/*

class QiZi

{

private:

    enum{ BLACK, WHITE, R = 16};

    POINT position;

    COLORREF color;

public:

    QiZi(){};

    QiZi(const POINT pos, const COLORREF col) : position(pos), color(col){}

    void paint(HWND hwnd);

};

*/

class Step

{

private:

    int step;

    int xIndex;

    int yIndex;

    int player;   // 0 for black, 1 for white

public:

    Step(){}

    Step(int s, int xI, int yI, int BorW)

    {

        step = s;

        xIndex = xI;

        yIndex = yI;

        player = BorW;

    }

    void getStepInfo(int & xI, int & yI, int & p)

    {

        xI = xIndex;

        yI = yIndex;

        p = player;

    }

};





class QiPan

{

private:

    enum{SIZE = 15, LENGTH = 504};

    std::string zeichen1;

    std::string zeichen2[15];

    Point points[SIZE][SIZE];

    Mark current_mark;

    Mark prev_mark;

    COLORREF bkgcol;

    bool gameover;

    std::string winner;

    std::vector<Step> vcSteps;

   

    bool findIndex(int x, int y, int & xIndex, int & yIndex);

public:

    QiPan();

    Point & getPoint(int xIndex, int yIndex);

    void paint(HWND hwnd);

    void drawChessman(HWND hwnd, Point point, int col);

    void eraseChessman(HWND hwnd, Point point);

    void drawAllChessman(HWND hwnd);

    void eraseAllChessman(HWND hwnd);

    void reset()

    {

        for(int i = 0; i<SIZE; i++)

        {

            for(int j = 0; j<SIZE; j++)

            {

                points[i][j].reset();

            }

        }

        gameover = false;

        vcSteps.clear();

    }

    void setCurrentMark(int x, int y);

    bool setStep(int x, int y, int round, Step & step);

    void setBkgColor(const COLORREF & col){ bkgcol = col; }

    COLORREF getBkgColor(){ return bkgcol; }

    Mark getCurrentMark(){ return current_mark; }

    Mark getPrevMark(){ return prev_mark; };

    void eraseMark(HWND hwnd, const COLORREF & col);

    void paintMark(HWND hwnd);

    void updateMark(){ prev_mark = current_mark;}

    bool isSetable(int x, int y);

    void addAStep(Step & step);

    void stepBack(){;}  // noch nicht fertig

    bool judger();

    std::string getWinner(){ return winner; }

};



class Player

{

private:

    enum{BLACK, WHITE, NOEFFECT};

    int sequence;

    bool current_player;

//    bool giveup;

    std::vector<Point> points;

public:

    Player(){sequence = NOEFFECT; current_player = false;};

    void setSequence(const int s = BLACK)

    {

        sequence = (s == BLACK || s == WHITE)? s : NOEFFECT;

    }

    void play(const Point & p);

    void stepback();

//    void giveup(){ giveup = true; }

};



class ComputerPlayer : public Player

{



};



class WuZiQi

{

private:

    int mode;

    static int step;

    Step a_step;

    int currentPlayer;

    QiPan chessboard;

    ComputerPlayer * pc;

    int gameState;

    int modeState;



    // for grafic user interface

    HWND hGroupMode, hGroupSequence;

    HWND hRadioBtnPP, hRadioBtnPC;

    HWND hRadioBtnBlack, hRadioBtnWhite;

    HWND hPushBtnStepback, hPushBtnBegin, hPushBtnGiveup;

    HWND hMessage;

    HINSTANCE hInst;

    COLORREF BKGCOL;

    std::string winner;

    void createWindow(HWND hwnd);

   

public:

    enum{ NULLSTATE, PLAYING, GAMEOVER}; //, NEWBEGIN};

    enum{ PVSP, PVSC, NOTHING};

    enum{ BLACK, WHITE, NOONE};

    enum{

        IDGROUP_MODE        = 101,

        IDGROUP_SEQUENCE    = 102,

        IDRADIOBTN_PP       = 103,

        IDRADIOBTN_PC       = 104,

        IDRADIOBTN_BLACK    = 105,

        IDRADIOBTN_WHITE    = 106,

        IDPUSHBTN_STEPBACK  = 107,

        IDPUSHBTN_BEGIN     = 108,

        IDPUSHBTN_GIVEUP    = 109 };

    WuZiQi(){BKGCOL = RGB(255, 240, 177);}

    COLORREF getBackgroudColor(){ return BKGCOL; }

    void setGameState(int gS = NULLSTATE){ gameState = gS; }

    int getGameState(){ return gameState; }

    LRESULT selectRadioBtn(HWND hRadioBtn)

    {

        return SendMessage(hRadioBtn, BM_SETCHECK, 1, 0);

    }

    LRESULT deselectRadioBtn(HWND hRadioBtn)

    {

        return SendMessage(hRadioBtn, BM_SETCHECK, 0, 0);

    }

    void setModeState(int mS = PVSC)

    {

        if(gameState == PLAYING)

        {

            modeState = mS;

            switch(modeState)

            {

            case PVSC:

                selectRadioBtn(hRadioBtnPC);

                deselectRadioBtn(hRadioBtnPP);

                break;

            case PVSP:

                selectRadioBtn(hRadioBtnPP);

                deselectRadioBtn(hRadioBtnPC);

                deselectRadioBtn(hRadioBtnBlack);

                deselectRadioBtn(hRadioBtnWhite);

                break;

            }

        }

    }

    void executeCommand(HWND hwnd, const int command);

    int getModeState(){ return modeState; }

    void setFocus(){ SetFocus(hGroupMode); }

    void init(HWND hwnd);

    void paintChessboard(HWND hwnd){ chessboard.paint(hwnd); }

    void paintMark(HWND hwnd, int x, int y);

    void paintAllChessman(HWND hwnd)

    {

        chessboard.drawAllChessman(hwnd);

    }

    void beginPlay(HWND hwnd)

    {

        if(gameState == NULLSTATE)

        {

            gameState = PLAYING;

            step = 0;

            currentPlayer = BLACK;

            chessboard.reset();

        }

   

        else if(gameState == GAMEOVER)

        {

            step = 0;

            currentPlayer = BLACK;

            chessboard.reset();

            chessboard.eraseAllChessman(hwnd);

            chessboard.paint(hwnd);

            gameState = PLAYING;

        }

        

    }

    void setChessman(HWND hwnd, int x, int y)

    {

        if(gameState == PLAYING)

        {

            // finde correct index;

            // create a step;

            if(chessboard.isSetable(x, y))

            {

              
 // step incremented, and so that change the player 0 for black, 1
for white

                stepCount();

                chessboard.setStep(x, y, step, a_step);

                // write step record;

                // update chessboard;



                chessboard.addAStep(a_step);

                chessboard.drawAllChessman(hwnd);

                if(chessboard.judger())

                {

                    gameOver();

              
     MessageBox(hMessage, chessboard.getWinner() ==
"Black"? "Black has won the game" : "White has won the game", "Winner",
MB_OK);

                }

            }

        }

    }

    void gameOver(){ gameState = GAMEOVER; }

    ComputerPlayer * getComputerPlayer(){ return pc; }

    int getCurrentPlayer(){ return currentPlayer; }

    int getMode(){ return modeState;}

    QiPan & getQiPan(){ return chessboard; }

    int getStepAmount(){ return step; }

    bool isPlaying(){ return gameState == PLAYING; }

    void setMode(const int m);

    void setSequence(const int sq);

    void stepCount(){ step++; currentPlayer = step&1; }

    ~WuZiQi(){ delete pc; }

};

#endif




自由,民主,平等,博爱,进步.
中华民国,我的祖国,中华民国万岁!中华民国加油!
本人自愿加入中国国民党,为人的自由性,独立性和平等性而奋斗!
2005-02-18 22:18
kai
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:52
帖 子:3450
专家分:59
注 册:2004-4-25
收藏
得分:0 
// wuziqi.cpp

#include "wuziqi.h"



void Mark::paintMark(HWND hwnd)

{

    HDC hdc = GetDC(hwnd);

    HPEN hpen = CreatePen(PS_SOLID, 1, color);

    SelectObject(hdc, hpen);

    MoveToEx(hdc, point.x, point.y, NULL);

    LineTo(hdc, point.x + 9, point.y);



    MoveToEx(hdc, point.x , point.y, NULL);

    LineTo(hdc, point.x, point.y + 9);



    MoveToEx(hdc, point.x + 36 , point.y, NULL);

    LineTo(hdc, point.x + 27, point.y);



    MoveToEx(hdc, point.x + 36 , point.y, NULL);

    LineTo(hdc, point.x + 36, point.y + 9);



    MoveToEx(hdc, point.x , point.y + 36, NULL);

    LineTo(hdc, point.x, point.y + 27);



    MoveToEx(hdc, point.x, point.y + 36, NULL);

    LineTo(hdc, point.x + 9, point.y + 36);



    MoveToEx(hdc, point.x + 36 , point.y + 36, NULL);

    LineTo(hdc, point.x + 27, point.y + 36);



    MoveToEx(hdc, point.x + 36 , point.y + 36, NULL);

    LineTo(hdc, point.x + 36, point.y + 27);

    DeleteObject(hpen);

    ReleaseDC(hwnd, hdc);

}



void Mark::erase(HWND hwnd, const COLORREF & col)

{

    setColor(col);

    paintMark(hwnd);

}



QiPan::QiPan()

{

    int a = LENGTH/(SIZE-1);

    int offset = 40;

    zeichen1 = "ABCDEFGHIJKLMNO";

    char temp[2];

    for(int i = 0; i<SIZE; i++)

    {

        sprintf(temp, "%d ", i+1);

        zeichen2[SIZE - i - 1] = temp;

        for(int j = 0; j<SIZE; j++)

        {

            points[i][j] = Point(offset + j * a, offset + i * a);

        }

    }

}



void QiPan::drawChessman(HWND hwnd, Point point, int col)

{

    HDC hdc;

    HPEN hpen;

    HBRUSH hbrush;

        

    hdc = GetDC(hwnd);

    if(col == 0) // black

    {

        hpen = CreatePen(PS_SOLID, 1, RGB(54,54,54));  // a little black

        hbrush = CreateSolidBrush(RGB(54,54,54));

    }

    else if(col == 1)  // white

    {

        hpen = CreatePen(PS_SOLID, 1, RGB(250,240,230));  // a little white

        hbrush = CreateSolidBrush(RGB(255,250,245));

    }

    else  // same color as background

    {

        hpen = CreatePen(PS_SOLID, 1, bkgcol);

        hbrush = CreateSolidBrush(bkgcol);

    }

    SelectObject(hdc, hpen);

    SelectObject(hdc, hbrush);



    Ellipse(hdc, point.getX() - 15, point.getY() - 15, point.getX() + 15, point.getY() + 15);

    DeleteObject(hpen);

    DeleteObject(hbrush);

    ReleaseDC(hwnd, hdc);

}



void QiPan::eraseChessman(HWND hwnd, Point point)

{

    this->drawChessman(hwnd, point, 2);  // draw it with background color

}



void QiPan::eraseAllChessman(HWND hwnd)

{

    for(int i = 0; i<SIZE; i++)

    {

       for(int j = 0; j<SIZE; j++)

       {

               drawChessman(hwnd, points[i][j], 2);

       }

    }

}

bool QiPan::findIndex(int x, int y, int & xIndex, int & yIndex)

{

    if(x<=562 && x>= 22 && y<=562 && y>=22)

    {

        if(x<=58)

            yIndex = 0;

        else if(x<=94)

            yIndex = 1;

        else if(x<=130)

            yIndex = 2;

        else if(x<=166)

            yIndex = 3;

        else if(x<=202)

            yIndex = 4;

        else if(x<=238)

            yIndex = 5;

        else if(x<=274)

            yIndex = 6;

        else if(x<=310)

            yIndex = 7;

        else if(x<=346)

            yIndex = 8;

        else if(x<=382)

            yIndex = 9;

        else if(x<=418)

            yIndex = 10;

        else if(x<=454)

            yIndex = 11;

        else if(x<=490)

            yIndex = 12;

        else if(x<=526)

            yIndex = 13;

        else if(x<=562)

            yIndex = 14;



        if(y<=58)

            xIndex = 0;

        else if(y<=94)

            xIndex = 1;

        else if(y<=130)

            xIndex = 2;

        else if(y<=166)

            xIndex = 3;

        else if(y<=202)

            xIndex = 4;

        else if(y<=238)

            xIndex = 5;

        else if(y<=274)

            xIndex = 6;

        else if(y<=310)

            xIndex = 7;

        else if(y<=346)

            xIndex = 8;

        else if(y<=382)

            xIndex = 9;

        else if(y<=418)

            xIndex = 10;

        else if(y<=454)

            xIndex = 11;

        else if(y<=490)

            xIndex = 12;

        else if(y<=526)

            xIndex = 13;

        else if(y<=562)

            xIndex = 14;

        return true;

    }

    else

        return false;

}



// wuziqi.cpp 下面部分请见下一个帖子




自由,民主,平等,博爱,进步.
中华民国,我的祖国,中华民国万岁!中华民国加油!
本人自愿加入中国国民党,为人的自由性,独立性和平等性而奋斗!
2005-02-18 22:25
kai
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:52
帖 子:3450
专家分:59
注 册:2004-4-25
收藏
得分:0 
// wuziqi.cpp 的第二部分代码

void QiPan::setCurrentMark(int x, int y)

{

    int xIndex, yIndex;

    if(findIndex(x, y, xIndex, yIndex))

        current_mark = Mark(points[xIndex][yIndex].getX()-18, points[xIndex][yIndex].getY()-18);

    else

        current_mark = Mark(-50, -50);

}



bool QiPan::setStep(int x, int y, int round, Step & step)

{

    int xIndex, yIndex;

    if(findIndex(x, y, xIndex, yIndex))

    {

        step = Step(round, xIndex, yIndex, (round-1)&1);

        return true;

    }

    else

        return false;

}

void QiPan::eraseMark(HWND hwnd, const COLORREF & col)

{

    prev_mark.erase(hwnd, col);

}



void QiPan::paintMark(HWND hwnd)

{

    current_mark.paintMark(hwnd);

}



bool QiPan::isSetable(int x, int y)

{

    int xI, yI;

    int state;

    findIndex(x, y, xI, yI);

    state = points[xI][yI].getState();

    if(state == -1)   // noChessman, so in this position is still setable

        return true;

    else

        return false;

}



void QiPan::addAStep(Step & step)

{

    int xI, yI, player;

    step.getStepInfo(xI, yI, player);

    if(player == 0)   // black

        points[xI][yI].setBlack();

    else              // otherwise white

        points[xI][yI].setWhite();

    vcSteps.push_back(step);

}



Point & QiPan::getPoint(int xIndex, int yIndex)

{

    return points[xIndex][yIndex];

}



void QiPan::paint(HWND hwnd)

{

    HDC hdc = GetDC(hwnd);

    HPEN hPen = CreatePen(PS_SOLID, 2, RGB(0, 0, 125));

    SelectObject(hdc, hPen);

   

   for(int i = 0; i<SIZE; i++)

   {

       MoveToEx(hdc, points[i][0].getX(), points[i][0].getY(), NULL);

       LineTo(hdc, points[i][14].getX(), points[i][14].getY());



       MoveToEx(hdc, points[0][i].getX(), points[0][i].getY(), NULL);

       LineTo(hdc, points[14][i].getX(), points[14][i].getY());



       SetBkMode(hdc, TRANSPARENT);

       TextOut(hdc, points[14][i].getX() - 5, points[14][i].getY() + 5, &(zeichen1[i]), 1);

       TextOut(hdc, points[i][0].getX() - 25, points[i][0].getY()-10, zeichen2[i].begin(), 2);

   }



   DeleteObject(hPen);

   ReleaseDC(hwnd, hdc);

}



void QiPan::drawAllChessman(HWND hwnd)

{

    HDC hdc = GetDC(hwnd);

    HPEN hPen = CreatePen(PS_SOLID, 2, RGB(0, 0, 125));

    SelectObject(hdc, hPen);

   

    for(int i = 0; i<SIZE; i++)

    {

       for(int j = 0; j<SIZE; j++)

       {

           if(points[i][j].getState() == Point::BLACK)

               drawChessman(hwnd, points[i][j], Point::BLACK);

           else if(points[i][j].getState() == Point::WHITE)

               drawChessman(hwnd, points[i][j], Point::WHITE);

       }

    }

   

    DeleteObject(hPen);

    ReleaseDC(hwnd, hdc);

}



bool QiPan::judger()   // if return true, game over

{

    int i, j, round = 0;

    bool over = false;

    // horizontal judgement

    for(i = 0; i<SIZE; i++)

    {

        for(j = 0; j<11; j++)

        {

           
if(points[i][j].getState() == points[i][j+1].getState() &&
points[i][j].getState()!=Point::NOCHESSMAN)

            {

           
    if(points[i][j+1].getState() ==
points[i][j+2].getState() &&
points[i][j+1].getState()!=Point::NOCHESSMAN)

                {

           
        if(points[i][j+2].getState() ==
points[i][j+3].getState() &&
points[i][j+2].getState()!=Point::NOCHESSMAN)

                    {

           
           
if(points[i][j+3].getState() == points[i][j+4].getState() &&
points[i][j+3].getState()!=Point::NOCHESSMAN)

                        {

           
           
    //found the winner, game over, send Message

           
           
    over = gameover = true;

           
           
    winner =
points[i][j].getState()==Point::BLACK?"Black":"White";

                        }

                    }

                }

            }

        }

    }

    // vertikale judgement

    for(i = 0; i<SIZE; i++)

    {

        for(j = 0; j<11; j++)

        {

           
if(points[j][i].getState() == points[j+1][i].getState() &&
points[j][i].getState()!=Point::NOCHESSMAN )

            {

           
    if(points[j+1][i].getState() ==
points[j+2][i].getState() &&
points[j+1][i].getState()!=Point::NOCHESSMAN)

                {

           
        if(points[j+2][i].getState() ==
points[j+3][i].getState()&&points[j+2][i].getState()!=Point::NOCHESSMAN)

                    {

           
           
if(points[j+3][i].getState() ==
points[j+4][i].getState()&&points[j+3][i].getState()!=Point::NOCHESSMAN)

                        {

           
           
    //found the winner, game over, send Message

           
           
    over = gameover = true;

           
           
    winner =
points[j][i].getState()==Point::BLACK?"Black":"White";

                        }

                    }

                }

            }

        }

    }

    // WS-NE

    for(j = 10; j>0; j--)

    {

        for(i = 0; i<j; i++)

        {

           
if(points[14-i][i+1+round].getState() ==
points[13-i][i+2+round].getState() &&
points[14-i][i+1+round].getState()!=Point::NOCHESSMAN)

            {

           
    if(points[13-i][i+2+round].getState() ==
points[12-i][i+3+round].getState() &&
points[13-i][i+2+round].getState()!=Point::NOCHESSMAN)

                {

           
      
if(points[12-i][i+3+round].getState() ==
points[11-i][i+4+round].getState() &&
points[12-i][i+3+round].getState()!=Point::NOCHESSMAN)

                    {

           
           
if(points[11-i][i+5+round].getState() ==
points[10-i][i+6+round].getState() &&
points[11-i][i+5+round].getState()!=Point::NOCHESSMAN)

                        {

           
           
    //found the winner, game over, send Message

           
           
    over = gameover = true;

           
           
    winner = points[14-i][i+1+round].getState() ==
Point::BLACK?"Black":"White";

                        }

                    }

                }

            }

            else
if(points[i+1+round][i].getState() == points[i+2+round][i+1].getState()
&& points[i+1+round][i].getState()!=Point::NOCHESSMAN)

            {

           
    if(points[i+2+round][i+1].getState() ==
points[i+3+round][i+2].getState() &&
points[i+2+round][i+1].getState()!=Point::NOCHESSMAN)

                {

           
      
if(points[i+3+round][i+2].getState() ==
points[i+4+round][i+3].getState() &&
points[i+3+round][i+2].getState()!=Point::NOCHESSMAN)

                    {

           
           
if(points[i+4+round][i+3].getState() ==
points[i+5+round][i+4].getState() &&
points[i+4+round][i+3].getState()!=Point::NOCHESSMAN)

                        {

           
           
    //found the winner, game over, send Message

           
           
    over = gameover = true;

           
           
    winner = points[i+1+round][i].getState() ==
Point::BLACK?"Black":"White";

                        }

                    }

                }

            }

            else
if(points[i][i+1+round].getState() == points[i+1][i+2+round].getState()
&& points[i][i+1+round].getState()!=Point::NOCHESSMAN)

            {

           
    if(points[i+1][i+2+round].getState() ==
points[i+2][i+3+round].getState() &&
points[i+1][i+2+round].getState()!=Point::NOCHESSMAN)

                {

           
      
if(points[i+2][i+3+round].getState() ==
points[i+3][i+4+round].getState() &&
points[i+2][i+3+round].getState()!=Point::NOCHESSMAN)

                    {

           
           
if(points[i+3][i+4+round].getState() ==
points[i+4][i+5+round].getState() &&
points[i+3][i+4+round].getState()!=Point::NOCHESSMAN)

                        {

           
           
    //found the winner, game over, send Message

           
           
    over = gameover = true;

           
           
    winner = points[i][i+1+round].getState() ==
Point::BLACK?"Black":"White";

                        }

                    }

                }

            }

            else
if(points[13-i-round][i].getState() ==
points[12-i-round][i+1].getState() &&
points[13-i-round][i].getState()!=Point::NOCHESSMAN)

            {

           
    if(points[12-i-round][i+1].getState() ==
points[11-i-round][i+2].getState() &&
points[12-i-round][i+1].getState()!=Point::NOCHESSMAN)

                {

           
      
if(points[11-i-round][i+2].getState() ==
points[10-i-round][i+3].getState() &&
points[11-i-round][i+2].getState()!=Point::NOCHESSMAN)

                    {

           
           
if(points[10-i-round][i+3].getState() ==
points[9-i-round][i+4].getState() &&
points[10-i-round][i+3].getState()!=Point::NOCHESSMAN)

                        {

           
           
    //found the winner, game over, send Message

           
           
    over = gameover = true;

           
           
    winner = points[13-i-round][i].getState() ==
Point::BLACK?"Black":"White";

                        }

                    }

                }

            }

        }

        round++;

    }

   

    for(i = 0; i<11; i++)

    {

        if(points[14-i][i].getState() ==
points[13-i][i+1].getState() &&
points[14-i][i].getState()!=Point::NOCHESSMAN)

        {

           
if(points[13-i][i+1].getState() == points[12-i][i+2].getState()
&& points[13-i][i+1].getState()!=Point::NOCHESSMAN)

            {

           
    if(points[12-i][i+2].getState() ==
points[11-i][i+3].getState() &&
points[12-i][i+2].getState()!=Point::NOCHESSMAN)

                {

           
        if(points[11-i][i+3].getState()
== points[10-i][i+4].getState() &&
points[11-i][i+3].getState()!=Point::NOCHESSMAN)

                    {

           
            //found the
winner, game over, send Message

           
            over =
gameover = true;

           
            winner =
points[14-i][i].getState() == Point::BLACK?"Black":"White";

                    }

                }

            }

        }

        else if(points[i][i].getState()
== points[i+1][i+1].getState() &&
points[i][i].getState()!=Point::NOCHESSMAN)

        {

           
if(points[i+1][i+1].getState() ==
points[i+2][i+2].getState()&&points[i+1][i+1].getState()!=Point::NOCHESSMAN)

            {

           
    if(points[i+2][i+2].getState() ==
points[i+3][i+3].getState()&&points[i+2][i+2].getState()!=Point::NOCHESSMAN)

                {

           
        if(points[i+3][i+3].getState() ==
points[i+4][i+4].getState()&&points[i+3][i+3].getState()!=Point::NOCHESSMAN)

                    {

           
            //found the
winner, game over, send Message

           
            over =
gameover = true;

           
            winner =
points[i][i].getState() == Point::BLACK?"Black":"White";

                    }

                }

            }

        }

    }

    return over;

}


自由,民主,平等,博爱,进步.
中华民国,我的祖国,中华民国万岁!中华民国加油!
本人自愿加入中国国民党,为人的自由性,独立性和平等性而奋斗!
2005-02-18 22:30
kai
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:52
帖 子:3450
专家分:59
注 册:2004-4-25
收藏
得分:0 
// wuziqi.cpp 的最后一部分代码

void WuZiQi::createWindow(HWND hwnd)

{

    hGroupMode = CreateWindow("BUTTON", "Mode", WS_CHILD|WS_VISIBLE|BS_GROUPBOX,

           
           50, 600,
192, 55, hwnd, (HMENU)IDGROUP_MODE, hInst, NULL);

    hRadioBtnPP = CreateWindow("BUTTON", "person vs person", WS_CHILD|WS_VISIBLE|BS_RADIOBUTTON,

           
           70, 620,
160, 15, hwnd, (HMENU)IDRADIOBTN_PP, hInst, NULL);

    hRadioBtnPC = CreateWindow("BUTTON", "person vs computer", WS_CHILD|WS_VISIBLE|BS_RADIOBUTTON,

           
           70, 635,
160, 15, hwnd, (HMENU)IDRADIOBTN_PC, hInst, NULL);

    hGroupSequence = CreateWindow("BUTTON", "Sequence", WS_CHILD|WS_VISIBLE|BS_GROUPBOX,

           
           350, 600,
192, 55, hwnd, (HMENU)IDGROUP_SEQUENCE, hInst, NULL);

    hRadioBtnBlack = CreateWindow("BUTTON", "black", WS_CHILD|WS_VISIBLE|BS_RADIOBUTTON,

           
           370, 620,
160, 15, hwnd, (HMENU)IDRADIOBTN_BLACK, hInst, NULL);

    hRadioBtnWhite = CreateWindow("BUTTON", "white", WS_CHILD|WS_VISIBLE|BS_RADIOBUTTON,

           
           370, 635,
160, 15, hwnd, (HMENU)IDRADIOBTN_WHITE, hInst, NULL);

    hPushBtnStepback = CreateWindow("BUTTON", "step back", WS_CHILD|WS_VISIBLE,

           
           76, 565,
120, 30, hwnd, (HMENU)IDPUSHBTN_STEPBACK, hInst, NULL);

    hPushBtnBegin = CreateWindow("BUTTON", "begin", WS_CHILD|WS_VISIBLE,

           
           232, 565,
120, 30, hwnd, (HMENU)IDPUSHBTN_BEGIN, hInst, NULL);

    hPushBtnGiveup = CreateWindow("BUTTON", "give up", WS_CHILD|WS_VISIBLE,

           
           388, 565,
120, 30, hwnd, (HMENU)IDPUSHBTN_GIVEUP, hInst, NULL);

}



void WuZiQi::init(HWND hwnd)

{

    chessboard.setBkgColor(BKGCOL);

    this->createWindow(hwnd);

    this->setGameState();

    this->setModeState();

}



void WuZiQi::paintMark(HWND hwnd, int x, int y)

{

    if(gameState == PLAYING)

    {

        chessboard.setCurrentMark(x, y);

        Mark current_mark = chessboard.getCurrentMark();

        Mark prev_mark = chessboard.getPrevMark();

        if(current_mark != prev_mark)

        {

            chessboard.eraseMark(hwnd, BKGCOL);

            chessboard.paintMark(hwnd);

            chessboard.updateMark();

        }

    }

}



void WuZiQi::executeCommand(HWND hwnd, const int command)

{

    switch(command)

    {

    case IDRADIOBTN_PP:

        setModeState(WuZiQi::PVSP);

            SendMessage(hRadioBtnPP, BM_SETCHECK, 1, 0);

            SendMessage(hRadioBtnPC, BM_SETCHECK, 0, 0);

            SendMessage(hRadioBtnBlack, BM_SETCHECK, 0, 0);

            SendMessage(hRadioBtnWhite, BM_SETCHECK, 0, 0);

            break;

        case IDRADIOBTN_PC:

            setMode(WuZiQi::PVSC);

            SendMessage(hRadioBtnPP, BM_SETCHECK, 0, 0);

            SendMessage(hRadioBtnPC, BM_SETCHECK, 1, 0);

            break;

        case IDRADIOBTN_BLACK:

            if(getMode() == WuZiQi::PVSC)

            {

                getComputerPlayer()->setSequence(WuZiQi::WHITE);

                SendMessage(hRadioBtnBlack, BM_SETCHECK, 1, 0);

                SendMessage(hRadioBtnWhite, BM_SETCHECK, 0, 0);

            }

            break;

        case IDRADIOBTN_WHITE:

            if(getMode() == WuZiQi::PVSC)

            {

                getComputerPlayer()->setSequence();

                SendMessage(hRadioBtnBlack, BM_SETCHECK, 0, 0);

                SendMessage(hRadioBtnWhite, BM_SETCHECK, 1, 0);

            }

            break;

        case IDPUSHBTN_STEPBACK:

            chessboard.stepBack();  

            break;

        case IDPUSHBTN_BEGIN:

            beginPlay(hwnd);

            break;

        case IDPUSHBTN_GIVEUP:

            gameOver();

           
MessageBox(hMessage, (getCurrentPlayer() == WuZiQi::BLACK)?"Black give
up":"White give up", "Give up", MB_OK);

            break;

        }

}

void WuZiQi::setMode(const int m)

{

    this->mode = m;

    if(mode == WuZiQi::PVSC)

        this->pc = new ComputerPlayer;

}




自由,民主,平等,博爱,进步.
中华民国,我的祖国,中华民国万岁!中华民国加油!
本人自愿加入中国国民党,为人的自由性,独立性和平等性而奋斗!
2005-02-18 22:32
kai
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:52
帖 子:3450
专家分:59
注 册:2004-4-25
收藏
得分:0 
// wuziqiplayer.cpp

// wuqiqiplayer.cpp

#include "wuziqi.h"



LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);



WuZiQi myWuZiQi;

int WuZiQi::step = 0;



int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,

                    LPSTR lpszCmdLine, int nCmdShow)

{

    HWND hwnd;

    MSG Msg;

    WNDCLASS wndclass;

    char lpszClassName[] = "window";

    char lpszTitle[] = "Îå×ÓÆå";



    wndclass.cbClsExtra = 0;

    wndclass.cbWndExtra = 0;

    wndclass.hbrBackground =
CreateSolidBrush(myWuZiQi.getBackgroudColor());
//(HBRUSH)GetStockObject(WHITE_BRUSH);

    wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);

    wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);

    wndclass.hInstance = hInstance;

    wndclass.lpfnWndProc = WndProc;

    wndclass.lpszClassName = lpszClassName;

    wndclass.lpszMenuName = NULL;

    wndclass.style = 0;



    if(! RegisterClass(&wndclass))

    {

        MessageBeep(0);

        return FALSE;

    }



    hwnd = CreateWindow(

        lpszClassName,

        lpszTitle,

        WS_BORDER | WS_VISIBLE | WS_MINIMIZEBOX | WS_SYSMENU,// |WS_THICKFRAME,

        0, 0, 592, 690, NULL, NULL, hInstance, NULL);

    ShowWindow(hwnd, nCmdShow);

    UpdateWindow(hwnd);

    while(GetMessage(&Msg, NULL, 0, 0))

    {

        TranslateMessage(&Msg);

        DispatchMessage(&Msg);

    }

    return Msg.wParam;

}



LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)

{

    PAINTSTRUCT ps;

    HDC hdc;

    static int x, y;

   

    switch(message)

    {

    case WM_CREATE:

        myWuZiQi.init(hwnd);

        break;

    case WM_SETFOCUS:

        myWuZiQi.setFocus();

        break;

    case WM_COMMAND:

        myWuZiQi.executeCommand(hwnd, LOWORD(wParam));

        break;

    case WM_MOUSEMOVE:

        x = LOWORD(lParam);

        y = HIWORD(lParam);

        myWuZiQi.paintMark(hwnd, x, y);

        break;

    case WM_LBUTTONDOWN:

        myWuZiQi.setChessman(hwnd, x, y);

        break;

    case WM_PAINT:

        hdc = BeginPaint(hwnd, &ps);

        myWuZiQi.paintChessboard(hwnd);

        myWuZiQi.paintAllChessman(hwnd);

        EndPaint(hwnd, &ps);

        break;

    case WM_DESTROY:

        PostQuitMessage(0);

    default:

        return DefWindowProc(hwnd, message, wParam, lParam);

    }

    return 0;

}






自由,民主,平等,博爱,进步.
中华民国,我的祖国,中华民国万岁!中华民国加油!
本人自愿加入中国国民党,为人的自由性,独立性和平等性而奋斗!
2005-02-18 22:33
kai
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:52
帖 子:3450
专家分:59
注 册:2004-4-25
收藏
得分:0 
程序有很多不足之处,如棋盘的闪烁现象。

所以这两天一直在修改程序。在添置新的功能之前,先完善代码是有必要的。

就在刚才又做了新的改动。

考虑到在这里粘贴代码不是很方便,又无法上传文件。所以对改动后的代码不再在这里粘贴了。如有朋友需要,可以向我索取代码。


自由,民主,平等,博爱,进步.
中华民国,我的祖国,中华民国万岁!中华民国加油!
本人自愿加入中国国民党,为人的自由性,独立性和平等性而奋斗!
2005-02-19 01:09
kai
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:52
帖 子:3450
专家分:59
注 册:2004-4-25
收藏
得分:0 
source code

IymlfVKZ.zip (11.55 KB)


[此贴子已经被作者于2005-8-4 15:15:55编辑过]



自由,民主,平等,博爱,进步.
中华民国,我的祖国,中华民国万岁!中华民国加油!
本人自愿加入中国国民党,为人的自由性,独立性和平等性而奋斗!
2005-07-31 09:24
kai
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:52
帖 子:3450
专家分:59
注 册:2004-4-25
收藏
得分:0 
yeshirow,

actually I havn't written windows program some long. I have seen your question in my blog. Can you give a program within that you have problem?

自由,民主,平等,博爱,进步.
中华民国,我的祖国,中华民国万岁!中华民国加油!
本人自愿加入中国国民党,为人的自由性,独立性和平等性而奋斗!
2006-08-07 04:58
kai
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:52
帖 子:3450
专家分:59
注 册:2004-4-25
收藏
得分:0 
Alt+F 不能引發第一個 BUTTON 被按下


这句话怎么理解?

我觉得你的问题是键盘相应的问题。

自由,民主,平等,博爱,进步.
中华民国,我的祖国,中华民国万岁!中华民国加油!
本人自愿加入中国国民党,为人的自由性,独立性和平等性而奋斗!
2006-08-07 06:29
kai
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:52
帖 子:3450
专家分:59
注 册:2004-4-25
收藏
得分:0 

那就与我对你的先前的表述刚好相反。 你是想 以Alt+F 来作为对 第一个Button 的 按动。 也就是说, 我可以用鼠标来点击 Button1, 我也可以用 Alt +F 来等同于点击 Button1. 那就要对 按键消息作出处理了。

下次给你一个按键的演示程序。


自由,民主,平等,博爱,进步.
中华民国,我的祖国,中华民国万岁!中华民国加油!
本人自愿加入中国国民党,为人的自由性,独立性和平等性而奋斗!
2006-08-07 06:49
快速回复:All about windows programming
数据加载中...
 
   



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

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