unity3D学习之纯GUI实现 黑白棋AI对战Word格式.docx

上传人:b****6 文档编号:18235173 上传时间:2022-12-14 格式:DOCX 页数:8 大小:15.55KB
下载 相关 举报
unity3D学习之纯GUI实现 黑白棋AI对战Word格式.docx_第1页
第1页 / 共8页
unity3D学习之纯GUI实现 黑白棋AI对战Word格式.docx_第2页
第2页 / 共8页
unity3D学习之纯GUI实现 黑白棋AI对战Word格式.docx_第3页
第3页 / 共8页
unity3D学习之纯GUI实现 黑白棋AI对战Word格式.docx_第4页
第4页 / 共8页
unity3D学习之纯GUI实现 黑白棋AI对战Word格式.docx_第5页
第5页 / 共8页
点击查看更多>>
下载资源
资源描述

unity3D学习之纯GUI实现 黑白棋AI对战Word格式.docx

《unity3D学习之纯GUI实现 黑白棋AI对战Word格式.docx》由会员分享,可在线阅读,更多相关《unity3D学习之纯GUI实现 黑白棋AI对战Word格式.docx(8页珍藏版)》请在冰豆网上搜索。

unity3D学习之纯GUI实现 黑白棋AI对战Word格式.docx

privateintleftEdge=10;

privateinttopEdge=100;

privateintsize=10;

privateintcellsep=5;

voidRestart()

lTable.Clear();

for(inti=0;

i<

colNum;

i++)

lTable.Add(newList<

ChessCell>

());

for(intj=0;

j<

rowNum;

j++)

lTable[i].Add(newChessCell());

if(i==rowNum/2-1&

&

j==colNum/2-1)

lTable[i][j].iPlayer=1;

if(i==rowNum/2&

lTable[i][j].iPlayer=2;

if(i==rowNum/2-1&

j==colNum/2)

size=((Screen.width>

Screen.height?

(Screen.height-topEdge):

Screen.width)-(2*leftEdge))/rowNum-cellsep;

lasti=-1;

lastj=-1;

curPlayer=1;

privateintcurPlayer=1;

privatevoidChangePlayer()

curPlayer=curPlayer==1?

2:

1;

privatestringcurPlayerName

get

returncurPlayer==1?

"

O"

:

X"

;

publicboolbPC=true;

privateintlasti=-1;

privateintlastj=-1;

List<

>

lTable=newList<

();

privateintplayer1count=2;

privateintplayer2count=2;

voidOnGUI()

GUI.Label(newRect(10,10,200,30),"

CurPlayer:

"

+curPlayerName);

if(GUI.Button(newRect(220,10,80,40),"

restart"

))

if(lasti>

=0)

GUI.Box(newRect(leftEdge+lasti*(size+cellsep),topEdge+lastj*(size+cellsep),size,size),"

);

intmost1=0;

for(intii=0;

ii<

colNum;

ii++)

for(intjj=0;

jj<

jj++)

if(lTable[ii][jj].iPlayer!

continue;

inticount=CheckValid(jj,ii,false);

if(most1<

icount)

most1=icount;

if(most1==0)

ShowResult();

i<

i++)

if(lTable[i][j].iPlayer==1)

GUI.Button(newRect(leftEdge+i*(size+cellsep),topEdge+j*(size+cellsep),size,size),"

elseif(lTable[i][j].iPlayer==2)

else

if(GUI.Button(newRect(leftEdge+i*(size+cellsep),topEdge+j*(size+cellsep),size,size),"

if(!

bPC||curPlayer==1)

CheckValid(j,i,true);

if(bPC&

curPlayer==2)

intmost=0;

intmii=0;

intmjj=0;

if(most<

most=icount;

mii=ii;

mjj=jj;

if(most>

0)

CheckValid(mjj,mii,true);

lasti=mii;

lastj=mjj;

player1count=0;

player2count=0;

if(lTable[ii][jj].iPlayer==1)

player1count++;

elseif(lTable[ii][jj].iPlayer==2)

player2count++;

GUI.Label(newRect(10,55,300,40),"

P1O:

+player1count+"

P2X:

+player2count);

voidShowResult()

GUI.Box(newRect(220,55,100,40),"

GUI.Button(newRect(220,55,100,40),player1count>

player2count?

P1WIN"

P2WIN"

intCheckValid(introw,intcol,boolbSet)

lSetCells=newList<

lPendingCells=newList<

//testleft

for(inti=col-1;

i>

=0;

i--)

if(lTable[i][row].iPlayer==0)

break;

if(lTable[i][row].iPlayer!

=curPlayer)

lPendingCells.Add(lTable[i][row]);

if(lTable[i][row].iPlayer==curPlayer)

lSetCells.AddRange(lPendingCells);

//testright

lPendingCells.Clear();

for(inti=col+1;

//testup

for(inti=row-1;

if(lTable[col][i].iPlayer==0)

if(lTable[col][i].iPlayer!

lPendingCells.Add(lTable[col][i]);

if(lTable[col][i].iPlayer==curPlayer)

//testdown

for(inti=row+1;

//testlefttop

for(inti=col-1,j=row-1;

=0&

j>

i--,j--)

if(lTable[i][j].iPlayer==0)

if(lTable[i][j].iPlayer!

lPendingCells.Add(lTable[i][j]);

if(lTable[i][j].iPlayer==curPlayer)

//testrighttop

for(inti=col+1,j=row-1;

colNum&

i++,j--)

//testleftbottom

for(inti=col-1,j=row+1;

i--,j++)

//testrightbottom

for(inti=col+1,j=row+1;

i++,j++)

if(lSetCells.Count>

if(bSet)

{

lTable[col][row].iPlayer=curPlayer;

foreach(ChessCellccinlSetCells)

cc.iPlayer=curPlayer;

ChangePlayer();

returnlSetCells.Count;

classChessCell

publicintiPlayer=0;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 艺术

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1