教程中国
PHOTOSHOP CS9.0中文版 MAYA 8.5 FOR WINDOWS Corel Painter v9.0 Flash MX2004 中文版 Illustrator cs2 中文版
VC++6.0含sp6 中英文版 VB6.0 +sp6 简体中文版 Borland Delphi 7汉化版 MSDN for vb6.0中文版 Visual Studio 2005简体
教程中国下属 文件存储共享专家BIBIDU.COM 提供大型软件,教材,源码,电影,音乐,图书等下载 更多精品请点此进入
  您目前所在位置: 教程中国 >> C >> 游戏编程 >> 个用C 编写的五子棋游戏(2) RSS订阅
个用C 编写的五子棋游戏(2)
个用C 编写的五子棋游戏(2)(1)
教程(视频,书籍)下载:  ASP.NET AutoCAD 数据库 C# ASP java photoshop 网页设计 delphi 3dmax Flash C++ VB 张孝祥 实例   更多请进入BIBIDU搜索
IT搜索引擎   

////////////////////////////////////////////////////
//
// 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
poly[7]=y1 deep;
poly[8]=x0; // Femte punkten
poly[9]=y1;
poly[10]=x1;
poly[11]=y1;


fillpoly(6,poly);
}
}

int ShowWinDlg(CPlayer* winner)
{
CRect rect(200,200,440,300);
CRect title(200,200,440,215);
CButton okButton(CRect(215,270,315,290),"OK");
CButton quitButton(CRect(325,270,425,290),"Cancel");
void *oldImage;
unsigned int size;
int newGame=-1;
int x,y,b;

/* calculate the size of the image */
size = imagesize(rect.x0,rect.y0,rect.x1 10,rect.y1 10);

/* allocate memory to hold the image */

来源:十度教育
作者:
关键字:用C,编写,五子棋游戏
发表日期:2006-6-13 17:05:04

网页显示有限 阅读全文请下载本文完整版WORD文档

上一篇:个用C 编写的五子棋游戏(1)   下一篇:一个用C 编写的五子棋游戏(3)


共4页 9 7 [1] [2] [3] [48 :>

2008-11-23 21:18:42
本文的相类似文章
  • VB简单计算函数的编写过程
  • VB编写键盘记录器
  • 用VB编写键盘拦截程序
  • VB下如何编写CRC校验程序
  • VB编写入侵监听程序
  • VB编写一个加密软件
  • COM程序编写入门(全文-1)
  • 怎样编写CSS?
  • 巧用COPY命令加密文本文件
  • 你学会正确地使用CD刻录机了吗
  • 在学习中进步 在进步中成长 教程中国相随您的成长之路
    华腾联合科技股份有限公司版权所有
    广告联系:Rosibo@163.com