JAVA上机1参考代码.doc上机实践1数据结构
实验1
扫雷小游戏
:
【代码1】:
new LinkedList ();
【代码2】:
list, add (block [i] [ j]);
【代码3】:
list. size();
【代码4】:
(Block)1 ist. get(randomindex)
【代码5】:
list. remove(randomlndex);
publie class Block
{ String name;
int number;
boolean boo二false;
public void setName(String name)
{ this. name二name;
}
public void setNumber(int n)
{ number=n;
}
public int getNumber()
{ return number;
}
public String getName ()
{ return name:
}
boolean isMineO
{ return boo;
}
public void setlsMine(boolean boo)
{ this. boo二boo;
}
}
import java, uti1. LinkedList;
publie class LayMines
public void layMinesForBlock(Block block[][], int mineCount)
{ int row二block, length;
int column=block[0]. length;
LinkedList list二【代码1】//创建空链表list
for (int i=0;i〈row;i++)
{ for (int j=0;j〈column;j++)
{【代码2】// list添加节点,其中的数据为block[i][j]
}
}
while(mineCou nt〉0)
{ int size二 【代码3】// list返回节点的个数
int randomlndex^ (int) (Math. random () *size);
Block b=【代码4】// list返回索引为randomindex的节点中的数据
b. setName ("雷”);
b. setlsMine (true);
【代码5】 //list删除索引值为randomindex的节点
mineCount--;
}
for(int i=0;i〈row;i++)
{ for (int j=0;j〈column;j++)
{ if (block[i] [j]. isMineO) {}
else
{ int mineNumbe—O;
for (int k=Math. max (i~l, 0) ;k<=Math. min(i+l, row~l) ;k++) { for (int t=Math. max (j~l, 0); t<=Math. min( j+1, column-1); t++) { if (block[k] [t].
JAVA上机1参考代码 来自淘豆网m.daumloan.com转载请标明出处.