在TC 1.0~TC 3.0下编译
// LUFFAR.CPP
////////////////////////////////////////////////////
//
// Luffar.Cpp by Yuheng Zhao
//
////////////////////////////////////////////////////
#include "types.h"
#include "shell.h"
#include "luffar.h"
#include "mouse.h"
CBoard::CBoard(CPlayer* p1,CPlayer* p2)
{
m_bSearchAll = TRUE;
// Rensa arrayen
for (int temp=0;temp<MAX_X;temp )
{
for (int temp1=0;temp1<MAX_Y;temp1 )
{
m_nBoard[temp][temp1]=0;
}
}
m_bIsEmpty = TRUE;
m_pPlayer1 = p1;
m_pPlayer2 = p2;
m_pCurrentPlayer = p1;
m_nWhoBegins=1;
x0 = 25;
y0 = 45;
x1 = 435;
y1 = 455;
m_nMargin = 10;
m_nShadow = 5;
m_nCellX = (x1-x0)/MAX_X;
m_nCellY = (y1-y0)/MAX_Y;
// Justera storleken p?br刣et s?att det blir delbart
x1=x0 m_nCellX*MAX_X;
y1=y0 m_nCellY*MAX_Y;
msg[0]='\0';
CreateImages();
}
void CBoard::ResetBoard()
{
if (!m_bIsEmpty)
{
for (int temp=0;temp<MAX_X;temp )
{
for (int temp1=0;temp1<MAX_Y;temp1 )
{
m_nBoard[temp][temp1]=0;
}
}
m_lastPt = CPoint();
m_nextlPt = CPoint();
if (m_nWhoBegins==1)
{
m_pCurrentPlayer = m_pPlayer2;
m_nWhoBegins=2;
}else
{
m_pCurrentPlayer = m_pPlayer1;
m_nWhoBegins=1;
}
m_bIsEmpty = TRUE;
Draw();
Message("-----------------");
Message("New game ... ");
}
}
CBoard::~CBoard()
{
free(m_pImage1);
free(m_pImage2);
}
void CBoard::CreateImages()
{
int r = (m_nCellX>m_nCellY)?m_nCellY:m_nCellX;
r/=2;
r-=1;
int x = 465;
int y = 60;
unsigned int size;
/* calculate the size of the image */
size = imagesize(0,0,r*2,r*2);
/* allocate memory to hold the image */
m_pImage1 = malloc(size);
m_pImage2 = malloc(size);
file://F攔sta image
setcolor(BLACK);
setfillstyle(SOLID_FILL,BLACK);
fillellipse(x,y,r,r);
setfillstyle(SOLID_FILL,DGRAY);
fillellipse(x-3,y-3,r-4,r-4);
setcolor(LGRAY);
setfillstyle(SOLID_FILL,LGRAY);
fillellipse(x-3,y-3,r-7,r-7);
/* grab the image */
getimage(x-r,y-r,x r,y r, m_pImage1);
x = 465;
y = 85;
// Andra image
setcolor(DGRAY);
setfillstyle(SOLID_FILL,DGRAY);
fillellipse(x,y,r,r);
setfillstyle(SOLID_FILL,LGRAY);
fillellipse(x-1,y-2,r-2,r-2);
setcolor(WHITE);
setfillstyle(SOLID_FILL,WHITE);
fillellipse(x-3,y-3,r-7,r-7);
getimage(x-r,y-r,x r,y r, m_pImage2);
// putimage(x, y-ARROW_SIZE, arrow, XOR_PUT);
}
void CBoard::Draw()
{
HidePoint();
CRect rect(x0-m_nMargin,y0-m_nMargin,
x1 m_nMargin,y1 m_nMargin);
rect.Draw(BROWN,NOCOLOR,TRUE,m_nShadow);
setcolor(BLACK);
for (int temp=0;temp<MAX_Y 1;temp )
line(x0,y0 temp*m_nCellY,x1,y0 temp*m_nCellY);
for (temp=0;temp<MAX_X 1;temp )
line(x0 temp*m_nCellX,y0,x0 temp*m_nCellX,y1);
ShowPoint();
}
int CBoard::Go()
{
int scrx=-1,scry=-1,b;
CPoint newPt;
BOOL redraw=FALSE;
if (m_pCurrentPlayer->IsComputer())
{
newPt = Think();
m_nBoard[newPt.x][newPt.y]=m_pCurrentPlayer->WhichPlayer();
redraw = TRUE;
m_bIsEmpty = FALSE;
m_nextlPt = m_lastPt;
m_lastPt = newPt;
}else
{
ReadMouse(scrx,scry,b);
if (b==1)
{
if (CRect(x0,y0,x1,y1).PtInRect(CPoint(scrx,scry)))
{
newPt = CPoint((scrx-x0)/m_nCellX,(scry-y0)/m_nCellY);
if (newPt.x>=MAX_X) newPt.x=MAX_X-1;
if (newPt.y>=MAX_Y) newPt.y=MAX_Y-1;
if (m_nBoard[newPt.x][newPt.y]==0)
{
m_nBoard[newPt.x][newPt.y]=m_pCurrentPlayer->WhichPlayer();
redraw = TRUE;
m_bIsEmpty = FALSE;
m_nextlPt = m_lastPt;
m_lastPt = newPt;
}
}
}
}
if (newPt.x!=-1 && newPt.y!=-1 && redraw)
{
HidePoint();
if (m_pCurrentPlayer->WhichPlayer() == 1)
{
putimage(x0 newPt.x*m_nCellX 1,y0 newPt.y*m_nCellY 1,
m_pImage1,COPY_PUT);