下载此文档

JAVA上机1参考代码.doc


文档分类:IT计算机 | 页数:约9页 举报非法文档有奖
1/9
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/9 下载此文档
文档列表 文档介绍
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转载请标明出处.

相关文档 更多>>
非法内容举报中心
文档信息
  • 页数9
  • 收藏数0 收藏
  • 顶次数0
  • 上传人小健
  • 文件大小70 KB
  • 时间2021-08-10