// 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
#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
![](/skin/img/sigline.gif)
自由,民主,平等,博爱,进步.
中华民国,我的祖国,中华民国万岁!中华民国加油!
本人自愿加入中国国民党,为人的自由性,独立性和平等性而奋斗!