用C或者C++编写一个陆军棋游戏软件设计

2024-12-27 16:45:37
推荐回答(2个)
回答1:

////////////////////////////////////////////////////
//
// Luffar.H by Yuheng Zhao
//
////////////////////////////////////////////////////

#ifndef _LUFFAR_H_
#define _LUFFAR_H_
#include "shell.h"

// Visa upp informationen
class CMessagePad
{
private:
int x0,y0,x1,y1;
int m_nShadow;

// ruta d剅 texten ska visas
int mx0,my0,mx1,my1;
int m_nLineSpace, m_nLines, m_nCurrentLine;
public:
CMessagePad();
void ScrollMessages();
void Draw();
void Message(char* msg);
};

class CPlayer
{
private:
BOOL m_bComputer; // Om det 剅 dator som k拦.
int m_nPlayer; // Vilken spelare det 剅
public:
CPlayer(int p) {m_bComputer = FALSE; m_nPlayer=p;}
void ChangePlayer(BOOL com) {m_bComputer = com;}
int WhichPlayer() {return m_nPlayer;}
BOOL IsComputer() {return m_bComputer;}
};

class CBoard
{
private:
// V剅det 0 om platsen 剅 tom, 1 f拦 spelaren 1, 2, f拦 spelare 2
int m_nBoard[MAX_X][MAX_Y];

// Var schackbr刣e ligger p?sk剅men.
int x0,y0,x1,y1; // Positionen p?br刣et
int m_nMargin; // Hur stor Marginal det br刣et ska ha
int m_nShadow; // Hur l唍gt skuggan det ska vara
int m_nCellX; // Storleken p?en cell p?br刣et
int m_nCellY;
CPlayer* m_pPlayer1;
CPlayer* m_pPlayer2;
int m_nWhoBegins;
CPlayer* m_pCurrentPlayer;
BOOL m_bIsEmpty;

// Skapa bilder i minnet och anv刵da PutImage() sedan
void CreateImages();
void *m_pImage1, *m_pImage2;
CPoint m_lastPt;
CPoint m_nextlPt; // N剆t sista punkten

// Kalkylera ut hur m唍ga i rad det finns i ett visst h唋l
int Calculate(int x,int y,Direction d,int player=-1);
CPoint Analyse(int x, int y, int count,int param=0);

char msg[30];
CPoint RandomPoint();
CPoint Think();
CPoint GetEndPoint(int x, int y, Direction d, BOOL& closed); // Returnera punkten efter den sista punkten i en viss rad
CPoint FindDangerPt(int player);

BOOL m_bSearchAll;
CPoint SearchAll(int,int, int param=0);
public:
CBoard(CPlayer* p1,CPlayer* p2);
~CBoard();
void ResetBoard();

void Draw();
int Go(); // L唗 current player g拦a n剆ta drag, returnera vinnare om det finns
int GetWinner();
void ShowWinner(int x,int y,Direction start,int player=-1);
};
#endif

------------------------------------------------------------------------

////////////////////////////////////////////////////
//
// Mouse.h by Yuheng Zhao
//
////////////////////////////////////////////////////

#ifndef _MOUSE_H_
#define _MOUSE_H_

void InitMouse();
void ShowPoint();
void SetPoint(unsigned int x,unsigned int y);
void HidePoint();
void HidePointXY(unsigned int cordx,unsigned int cordy,unsigned int x,unsigned int y);
void ReleaseXY(int &xcordi,int &ycordi,unsigned int bbutt);
void PressXY(int &xcordi,int &ycordi,unsigned int bbutt);
void ReadMouse(int &x,int &y,int &b);
void Limits(unsigned int minx,unsigned maxX,unsigned miny,unsigned maxY);
int MouseSize();

#endif

--------------------------------------------------------------------------------

////////////////////////////////////////////////////
//
// Shell.H by Yuheng Zhao
//
////////////////////////////////////////////////////

#ifndef _SHELL_H_
#define _SHELL_H_
#include "luffar.h"

void InitGraphics();
void Cls();

void DrawBackground();
char ReadKey();
void Rectangle(int,int,int,int,int,BOOL shadow=FALSE,int deep=0);

void WaitDlg(int nMode=0, int nDelay=0);
int ShowWinDlg(CPlayer* winner);

void IntToChar(int, char*);
void Message(char*);
#endif

-----------------------------------------------------------

////////////////////////////////////////////////////
//
// Types.H by Yuheng Zhao
//
////////////////////////////////////////////////////

#ifndef _TYPES_H_
#define _TYPES_H_

#include
#include // c++ grafik,Inte sj刲v gjorda. ( ska 刵d?inte g拦a n唃ot grafisk avancerat sak )
#include
#include
#include
#include
#include

#define MAX_X 19
#define MAX_Y 19

#define SCR_MAX_X 639
#define SCR_MAX_Y 479

#define NOCOLOR -1
#define BLACK 0
#define BLUE 1
#define GREEN 2
#define CYAN 3
#define RED 4
#define MAGENTA 5
#define BROWN 6
#define LGRAY 7
#define DGRAY 8
#define LBLUE 9
#define LGREEN 10
#define LCYAN 11
#define LRED 12
#define LMAGENTA 13
#define YELLOW 14
#define WHITE 15

enum BOOL{TRUE=1, FALSE=0};
enum Direction {LEFT,UPLEFT,UP,UPRIGHT,RIGHT,DOWNRIGHT,DOWN,DOWNLEFT};

class CPoint
{
public:
int x,y;
CPoint() {x=-1;y=-1;}
CPoint(int xx,int yy) {x=xx; y=yy;}
CPoint(const CPoint* pt) {x=pt->x; y=pt->y;}

BOOL operator== (const CPoint& pt) const;
const CPoint& operator= (const CPoint& pt);
};

class CRect
{
public:
int x0,y0,x1,y1;
CRect(int xx0,int yy0,int xx1,int yy1) {x0=xx0; y0=yy0; x1=xx1; y1=yy1;}
CRect(const CRect* r) {x0=r->x0; y0=r->y0; x1=r->x1; y1=r->y1;}
const CRect& operator= (const CRect& pt);

BOOL PtInRect(const CPoint& pt);
void Draw(int,int lineColor=NOCOLOR,BOOL shadow=FALSE,int deep=0);
};

class CButton
{
public:
CRect m_Rect;
char* m_pchName;
BOOL m_bPressed;

CButton(const CRect& rect,char* ch);
~CButton() {delete m_pchName;}
void Draw();
// Kolla om n唃on har klickat p?knappen
BOOL Clicked(int,int,int);
void SetWindowText(char*);
};

#endif

回答2:

跟真棋一样