Chinaunix

标题: 芯片设计语源写的游戏 [打印本页]

作者: wheel    时间: 2005-03-09 12:19
标题: 芯片设计语源写的游戏
http://www.linuxfans.org/nuke/modules.php?name=Site_Downloads&op=geninfo&did=3345
游戏由9X9=81个格子组成,程序中以数组 nValue 来定义。定义了一些不同着色的球,并随机产生,并随机摆放到81个格子上。程序主要有以下几个部分组成:

colorlineMainForm();用hiCreatebutton产生81个button,创造不同色彩的球。



fBallRandom();; 随机产生球并摆放,并设定值8为背景,小于8的值均理解为有球。还定义了两个list,lBallnoexist和lBallexist来存储当然有球的区域和没球的区域。



fListReduce(),fListReducebymatch(),fListReducebynmatch()这三个函数都是用来减少list中的值的,以平衡lBallnoexist与lBallexist的关系。



fBallRefresh();是用来改变球的图标。



fBallSelect();则是定义点取的球是起点球还是终点位置。



fBallDir();是运算球的行走方向,左右上下的顺序。



fBallMove();以fBallDir()反馈的值来移动球。



fNewGame();初始化值,开始新的游戏。



fBallDispear();消去要消失的球。



fBallInLine() ;计算球成一条线,并且有5个以上的同色球。



游戏下载请到



以下是计算球成一线的程序原代码:



/******************************/

;;define ball in line and disappear func

;;define ball array 0_redball 1_yellowball 2_blueball

;;3_greenball 4_brownball 5_cyanball 6_purple 7_azure 8_noball 9_background 10_selected_bgISblack

;;there are 6 and bigger 6 ball in a line then remove the ball line

;;and give the value to 6

/******************************/

procedure(fBallInLine(nballx nbally)

prog(()



nReturn=t;

nCenterNumber=nbally*9+nballx;

nRefValue=nValue[nCenterNumber];

lInFive=list(nCenterNumber);



nInFive=0;

for(i 0 8

nLineNumber=nbally*9+i;

nLineValue=nValue[nLineNumber];

if(nLineValue == nRefValue then

nInFive++

lInFive=fListReducebynmatch(lInFive nLineNumber);

lInFive=append1(lInFive nLineNumber);

else

fBallDispear(nInFive lInFive);

nInFive=0;

lInFive=list(nCenterNumber);

));if_for

fBallDispear(nInFive lInFive);



nInFive=0;

for(j 0 8

nLineNumber=j*9+nballx

nLineValue=nValue[nLineNumber];

if(nLineValue == nRefValue then

nInFive++

lInFive=fListReducebynmatch(lInFive nLineNumber);

lInFive=append1(lInFive nLineNumber);

else

fBallDispear(nInFive lInFive);
nInFive=0;

lInFive=list(nCenterNumber);

));if

fBallDispear(nInFive lInFive);



nInFive=0;

i=nballx-nbally

j=0

if(i<0 then

i=0

j=nbally-nballx

);if

while((max i j)<9

nLineNumber=j*9+i;

nLineValue=nValue[nLineNumber];

if(nLineValue == nRefValue then

nInFive++

lInFive=fListReducebynmatch(lInFive nLineNumber);

lInFive=append1(lInFive nLineNumber);

else

fBallDispear(nInFive lInFive);

nInFive=0;

lInFive=list(nCenterNumber);

);if

i++

j++

);while_i_j

fBallDispear(nInFive lInFive);



nInFive=0;

i=nballx+nbally

j=0

if(i>;8 then

i=8

j=nballx+nbally-8

);if

while((and i>;=0 j<9)

nLineNumber=j*9+i;

;printf("%d %d %d
" nballx nbally nLineNumber);

nLineValue=nValue[nLineNumber];

if(nLineValue == nRefValue then

nInFive++

lInFive=fListReducebynmatch(lInFive nLineNumber);

lInFive=append1(lInFive nLineNumber);

else

fBallDispear(nInFive lInFive);

nInFive=0;

lInFive=list(nCenterNumber);

);if

i--

j++

);while_i_j

fBallDispear(nInFive lInFive);



return(nReturn);

));fBallInLine




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2