*/
//清楚原來的方形
public void clearoldretangle(Graphics
{
if(hasclickbomb)
diamonds[r][c]
else
{
if(!diamonds[r][c]
diamonds[r][c]
else
diamonds[r][c]
}
}
/*
//清除原來的圓形
public void clearOval(Graphics
{
if(c<col && r<row)
{
for(int y=r
{
if(y<
for(int x=c
{
if(x>=
{
if(hasclickbomb)
diamonds[y][x]
else
{
if(!diamonds[y][x]
diamonds[y][x]
else
diamonds[y][x]
}
}
}
}
}
}
*/
//設置炸彈
public void buildBombInMap()
{
int x=
for(int i=
{
x=(int)(Math
y=(int)(Math
if(!diamonds[y][x]
{
diamonds[y][x]
i++;
}
}
countRoundBomb();//計算炸彈
}
//計算附近的炸彈
public void countRoundBomb()
{
for(int i=
{
for(int j=
{
if(diamonds[i][j]
continue;
else
{
//開始計算每個附近的炸彈
int count=
for(int k=i
{
if(k<
for(int l=j
{
if(l>=
{
if(diamonds[k][l]
count++;
}
}
}
if(count!=
diamonds[i][j]
}
}
}
}
//踩中地雷後全部顯示
public void showAllDiamonds(int ro
{
Graphics
gg
for(int r=
{
for(int c=
{
if(!diamonds[r][c]
diamonds[r][c]
else if(diamonds[r][c]
diamonds[r][c]
diamonds[r][c]
}
}
}
//重載paint
public void paint(Graphics g)
{
Graphics
gg
for(int y=
{
for(int x=
{
if(hasclickbomb)
diamonds[y][x]
else
{
if(!diamonds[y][x]
diamonds[y][x]
else
diamonds[y][x]
}
}
}
gg
}
}
Diamonds
import java
import java
import java
import java
import java
/**
* 單元方格類
* @author dragon
*
*/
public class Diamonds
{
private Color fillcolor=Color
private Color rimcolor=Color
private boolean bomb=false;
private String showbyte=
private int diamondWidth=
private boolean opened=false;
private boolean signbomb=false;
public Diamonds(Color c
{
this
this
}
public Diamonds(int width)
{
this
}
/**
* 設置是否被標記為炸彈
* dragon
*Sep
* @param b
*/
public void setSignBomb(boolean b)
{
this
}
public boolean isSignBomb()
{
return this
}
/**
* 設置方格的邊長
* dragon
*Sep
* @param width
*/
public void setDiamondWidth(int width)
{
this
}
/**
* 返回當前方格的字符串
* dragon
*Sep
* @return
*/
public String getShowByte()
{
return this
}
/**
* 設置方格的字符串
* dragon
*Sep
* @param b
*/
public void setShowByte(String b)
{
showbyte=b;
}
/**
* 復位
*/
public void reset()
{
fillcolor=Color
rimcolor=Color
this
bomb=false;
showbyte=
opened=false;
}
/**
* 判斷方格是否已經被打開
*/
public boolean isOpened()
{
return this
}
/**
* 打開該方格
*/
public void Opened()
{
this
}
/**
* 判斷是否是炸彈
*/
public boolean isbomb()
{
return bomb;
}
/**
* 設置為炸彈
*/
public void setbomb()
{
this
}
/**
* 點擊時的顯示函數
*/
public void clickshow(Graphics
{
gg
if(bomb)
{
if(opened)
this
gg
gg
gg
gg
gg
gg
}
else
{
gg
gg
gg
gg
gg
gg
}
}
/**
* 繪畫單元格
*/
public void draw(Graphics
{
gg
gg
gg
gg
gg
}
/**
* 設置邊框顏色
*/
public void setRimColor(Color c)
{
rimcolor=c;
}
/**
* 設置填充顏色
*/
public void setFillColor(Color c)
{
this
}
}
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26439.html