////////////////////////////////////////////////////
//
// Main.Cpp by Yuheng Zhao
//
////////////////////////////////////////////////////
#include "types.h"
#include "mouse.h"
#include "shell.h"
#include "luffar.h"
int main(void)
{
InitMouse();
InitGraphics();
DrawBackground();
SetPoint(1,1); // L刧ger musen p?punkten 1,1.
ShowPoint();
BOOL bWantToExit = FALSE;
CPlayer player1(1);
CPlayer player2(2);
player2.ChangePlayer(TRUE);
CBoard board(&player1,&player2);
int winner=-1;
int nCode=-1;
int x,y,b=-1;
CButton player1Button(CRect(480,50,610,70),"Player 1");
CButton player2Button(CRect(480,75,610,95),"Computer");
CButton newButton(CRect(450,430,530,450),"New");
CButton quitButton(CRect(540,430,620,450),"Quit");
board.Draw();
newButton.Draw();
quitButton.Draw();
player1Button.Draw();
player2Button.Draw();
Message("Luffar Schack! 0.99");
Message("Written by");
Message("Yuheng Zhao 1997-5");
Message("------------------");
Message("New game ...");
while (!bWantToExit)
{
ReadMouse(x,y,b);
if (b==1)
{
if (quitButton.Clicked(x,y,b))
{
Message("Exit...");
player2.ChangePlayer(FALSE);
bWantToExit = TRUE;
delay(200);
}
if (newButton.Clicked(x,y,b))
{
board.ResetBoard();
}
if (player1Button.Clicked(x,y,b))
;
if (player2Button.Clicked(x,y,b))
{
if (player2.IsComputer())
{
player2.ChangePlayer(FALSE);
player2Button.SetWindowText("Player 2");
}else
{
player2.ChangePlayer(TRUE);
player2Button.SetWindowText("Computer");
};
delay(200);
}
b=-1;
}
winner=board.Go();
if (winner==1 || winner==2)
{
Message((winner==1)?"Player 1 wins.":
(player2.IsComputer())?"Computer wins":"Player 2 wins");
nCode=(winner==1)?ShowWinDlg(&player1):ShowWinDlg(&player2);
if (nCode==1)
board.ResetBoard();
}
}
HidePoint();
closegraph();
return 0;
}
-------------------------------------------------------------------
////////////////////////////////////////////////////
//
// Shell.Cpp by Yuheng Zhao
//
////////////////////////////////////////////////////
#include "types.h"
#include "mouse.h"
#include "shell.h"
CMessagePad mp;
// INITERAR C GRAFIK
// #################################################
void InitGraphics()
{
int gdriver = VGA, gmode=VGAHI, errorcode;
if (!(registerbgidriver(EGAVGA_driver)<0))
{
initgraph(&gdriver, &gmode, "");
errorcode = graphresult();
if (errorcode == grOk)
return;
}
cout << "Error detected when initialize graphics...\n";
cout << "No VGA compatible graphics card is found...\n";
ReadKey();
exit(1);
}
// RENSAR SK嶳MEN
// ################################################
void Cls()
{
int maxx, maxy;
maxx = getmaxx();
maxy = getmaxy();
setcolor(0);
for(int tmp=0;tmp<(maxy 1);tmp )
line(0,tmp,maxx,tmp);
}
// L嶴ER ETT TECKEN FR廙 TANGET BORDET
// ################################################
char ReadKey()
{
unsigned char tmp;
asm{
mov ax,0
mov ah,0
int 16h
mov tmp,al
}
return tmp;
}
void DrawBackground()
{
Cls();
// Bakgrunden
setfillstyle(LTBKSLASH_FILL,GREEN);
bar(0,0,SCR_MAX_X,SCR_MAX_Y);
// Titel
setfillstyle(SOLID_FILL,WHITE);
bar(0,0,SCR_MAX_X,15);
setcolor(BLACK);
outtextxy(5,4,"Luffar schack 0.99 (Beta release) by Yuheng Zhao");
line(0,15,SCR_MAX_X,15);
// About info
CRect rect(450,40,620,105);
rect.Draw(BROWN,NOCOLOR,TRUE,5);
mp.Draw();
}
void Rectangle(int x0,int y0,int x1,int y1,int color,BOOL shadow,int deep)
{
setfillstyle(SOLID_FILL,color);
bar(x0,y0,x1,y1);
if(shadow)
{
// Skuggan
setcolor(BLACK);
setfillstyle(INTERLEAVE_FILL,color);
int poly[12];
poly[0]=x1; // F攔sta punkten
poly[1]=y0;
poly[2]=x1 deep; // Andra punkten
poly[3]=y0 deep;
poly[4]=x1 deep; // Tredje punkten
poly[5]=y1 deep;
poly[6]=x0 deep; // Fj剅de punk
ten