import javax.sound.sampled.*
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//修改你的音乐文件路径就OK了
AePlayWave apw=new AePlayWave("./111.wav")
apw.start()
}
}
//在程序中实例化这个类,启动线程,实例化的时候参照Test修改路径就OK
//播放声音的类
class AePlayWave extends Thread {
private String filename
public AePlayWave(String wavfile) {
filename = wavfile
}
public void run() {
File soundFile = new File(filename)
AudioInputStream audioInputStream = null
try {
audioInputStream = AudioSystem.getAudioInputStream(soundFile)
} catch (Exception e1) {
e1.printStackTrace()
return
}
AudioFormat format = audioInputStream.getFormat()
SourceDataLine auline = null
DataLine.Info info = new DataLine.Info(SourceDataLine.class, format)
try {
auline = (SourceDataLine) AudioSystem.getLine(info)
auline.open(format)
} catch (Exception e) {
e.printStackTrace()
return
}
auline.start()
int nBytesRead = 0
byte[] abData = new byte[512]
try {
while (nBytesRead != -1) {
nBytesRead = audioInputStream.read(abData, 0, abData.length)
if (nBytesRead >= 0)
auline.write(abData, 0, nBytesRead)
}
} catch (IOException e) {
e.printStackTrace()
return
} finally {
auline.drain()
auline.close()
}
}
}
有不明白的地方再hi我
做法一:InputStream is =null
AudioStream as = null
is = getClass().getResourceAsStream("a.wav")
try {
as = new AudioStream(is)
} catch (IOException e) {}
AudioPlayer.player.start(as)
此方法将音乐文件放入流中在播放,仅限于Java Application,容易报错,空指针异常,或者是流异常,不推荐。
做法二:
String music = "a.wav"
AudioClip clip = Applet.newAudioClip(getClass().getResource(music))
次方法在Applet中运行没有问题,但是Application中getclass()会返回空指针,导致失败。
推荐做法:
private URL url
private AudioClip ac
File f1 = new File("C:/3.wav")
try {
url= f1.toURL()
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace()
}
ac= Applet.newAudioClip(cb1)
ac.play()
package huaroadimport java.util.*
import com.siemens.mp.io.*
import com.siemens.mp.game.*
import java.io.IOException
import javax.microedition.lcdui.*
// 游戏类
public class HRGame extends Canvas implements CommandListener, Backable
{
private static int BLOCKSIZE = 0// 每块大小
private static int IMGOFFSET = 0 // 名字图片对于边框的偏移量
// 布局定义 (4*5)块
// 0-空, 1~4-兵, 5-张飞, 6-赵云, 7-马超, 8-黄忠, 9-关羽, 10-曹 ***
private static final byte gamelayout[][][] = {
{ // 横刀立马
{ 5,10,10, 6 },
{ 5,10,10, 6 },
{ 7, 9, 9, 8 },
{ 7, 2, 3, 8 },
{ 1, 0, 0, 4 },
},
{ // 过五关
{ 1,10,10, 3 },
{ 2,10,10, 4 },
{ 5, 5, 6, 6 },
{ 7, 7, 8, 8 },
{ 0, 9, 9, 0 },
},
{ // 水泄不通
{ 1,10,10, 5 },
{ 2,10,10, 5 },
{ 6, 6, 7, 7 },
{ 8, 8, 9, 9 },
{ 3, 0, 0, 4 },
},
{ // 小燕出巢
{ 5,10,10, 6 },
{ 5,10,10, 6 },
{ 7, 7, 8, 8 },
{ 1, 9, 9, 3 },
{ 2, 0, 0, 4 },
},
{ // 进在咫尺
{ 1, 5, 6, 7 },
{ 2, 5, 6, 7 },
{ 8, 8, 3, 4 },
{ 9, 9,10,10 },
{ 0, 0,10,10 },
},
{ // 左右夹击
{ 1,10,10, 2 },
{ 5,10,10, 6 },
{ 5, 9, 9, 6 },
{ 7, 3, 4, 8 },
{ 7, 0, 0, 8 },
},
{ // 重兵挡道
{ 5,10,10, 6 },
{ 5,10,10, 6 },
{ 1, 2, 3, 4 },
{ 7, 9, 9, 8 },
{ 7, 0, 0, 8 },
}
}
private static final byte posSxy[][] = { // 各布局光标起始位置(x,y)
{ 1, 4 }, { 0, 4 }, { 1, 4 }, { 1, 4 }, { 0, 4 },
{ 1, 4 }, { 1, 4 }
}
private static final Command COMMANDS[] = { // 定义菜单
new Command("继续游戏", 4, 0),
new Command("新游戏", 1, 1),
new Command("退出", 6, 2),
new Command("按键设置", 1, 3),
new Command("帮助信息", 1, 4)
}
public byte ctrlkey[] = {// 按键定义(初始按键)
'4',// left - 4
'6',// right - 6
'2',// up - 2
'8',// down - 8
'5',// select - 5
}
private Command SndCmd, VibCmd
final private static String openSnd="开启声音", closeSnd="关闭声音", openVib="开启振动", closeVib="关闭振动"
public boolean Snd, Vib
private byte grid[][] = new byte[4][5] // 游戏布局矩阵
private int posx, posy // 当前光标位置
private int oldx, oldy // 上次光标位置
private int offx, offy // 棋子的大小偏移量(相对于当前块)。
// 比如当前块是曹 *** 的右上角,那么offx=-1,offy=1
// 表示x负方向还有一块,y的正方向有一块
private int steps, tmpstep// 已走步数
private Image nameImg[]// 名字图片(由于可写文字太大,所以用图片)
private SelNew gamelist
private Display display
private Quitable winQuit
private boolean selected, gameOver // 是否选中/是否游戏结束
private ExtendedImage ExScreenImg // 扩展图片作为绘图缓存(Siemens扩展)
private Graphics Exg// 缓存的Graphics对象
private MelodyComposer melody // midi播放(Siemens扩展)
public HRGame()
{
if (getHeight() >64) // 根据屏幕高度得到图形尺寸,以便针对不同机型
{
// 6688i使用
BLOCKSIZE = 15// 每块大小
IMGOFFSET = 3 // 名字图片对于边框的偏移量
}
else
{
// 3118使用
BLOCKSIZE = 12
IMGOFFSET = 1
}
nameImg = new Image[26] // 载入名字图片
try
{
nameImg[0] = Image.createImage("images/zhang.png") // 张
nameImg[1] = Image.createImage("images/zhang2.png")// 张(反色)
nameImg[2] = Image.createImage("images/fei.png") // 飞
nameImg[3] = Image.createImage("images/fei2.png") // 飞(反色)
nameImg[4] = Image.createImage("images/zhao.png") // 赵
nameImg[5] = Image.createImage("images/zhao2.png") // 赵(反色)
nameImg[6] = Image.createImage("images/yun.png") // 云
nameImg[7] = Image.createImage("images/yun2.png") // 云(反色)
nameImg[8] = Image.createImage("images/ma.png") // 马
nameImg[9] = Image.createImage("images/ma2.png") // 马(反色)
nameImg[10] = Image.createImage("images/chao.png") // 超
nameImg[11] = Image.createImage("images/chao2.png")// 超(反色)
nameImg[12] = Image.createImage("images/huang.png")// 黄
nameImg[13] = Image.createImage("images/huang2.png")// 黄(反色)
nameImg[14] = Image.createImage("images/zhong.png")// 忠
nameImg[15] = Image.createImage("images/zhong2.png")// 忠(反色)
nameImg[16] = Image.createImage("images/guan.png") // 关
nameImg[17] = Image.createImage("images/guan2.png")// 关(反色)
nameImg[18] = Image.createImage("images/yu.png") // 羽
nameImg[19] = Image.createImage("images/yu2.png") // 羽(反色)
nameImg[20] = Image.createImage("images/cao.png") // 曹
nameImg[21] = Image.createImage("images/cao2.png") // 曹(反色)
nameImg[22] = Image.createImage("images/c.png") // ***
nameImg[23] = Image.createImage("images/c2.png") // *** (反色)
nameImg[24] = Image.createImage("images/bing.png") // 兵
nameImg[25] = Image.createImage("images/bing2.png")// 兵(反色)
}
catch(IOException ioexception) { }
ExScreenImg = new ExtendedImage(Image.createImage(104, getHeight())) // 新建绘图缓存
Exg = ExScreenImg.getImage().getGraphics() // 缓存绘图的Graphics对象
melody = new MelodyComposer()// 新建midi
Snd = true // 音效开启
Vib = true // 震动开启
/////////////////////////////////////////////
// 读取按键设置 共7字节,依次表示:左按键、右按键、上按键、下按键、选中按键、音效、震动
try
{
byte bflag[] = new byte[2]
bflag[0] = bflag[1] = 1
File keyfile = new File()
int fid = keyfile.open("CtrlKey") // 打开文件(Siemens扩展)
if(keyfile.length(fid) >0) keyfile.read(fid, ctrlkey, 0, 5)// 读取按键参数到ctrlkey
if(keyfile.length(fid) >5) keyfile.read(fid, bflag, 0, 2) // 读取文件
Snd = (bflag[0] == 1)// 音效参数 (1-开启,其他-关闭)
Vib = (bflag[1] == 1)// 震动参数 (1-开启,其他-关闭)
keyfile.close(fid)
}
catch(IOException ioexception) { }
catch(NullPointerException npe){ }
//////////////////////////////////////////////
if (Snd) SndCmd = new Command(closeSnd, Command.OK, 5) // 根据参数设置菜单
else SndCmd = new Command(openSnd, Command.OK, 5)
if (Vib) VibCmd = new Command(closeVib, Command.OK, 6)
else VibCmd = new Command(openVib, Command.OK, 6)
for(int i = 0i <COMMANDS.lengthi++) // 添加菜单
addCommand(COMMANDS[i])
addCommand(SndCmd)
addCommand(VibCmd)
}
public void activate(Display disp, Quitable quitable) // 激活
{
winQuit = quitable
display = disp
show()
}
public void getkeys(byte ckeys[]) // 从自定义按键结果设置按键,并显示游戏界面
{
for (byte i=0i<5i++) ctrlkey[i] = ckeys[i]
show()
}
public void show() // 显示游戏画面
{
display.setCurrent(this)
setCommandListener(this)
}
public void newGame(SelNew gmlist)// 新游戏
{
gamelist = gmlist
int gnum = gamelist.getSelectedIndex() // 获取游戏布局编号
int i, j
for (i=0i<4i++) // 根据编号初始化游戏矩阵
for (j=0j<5j++)
grid[i][j] = gamelayout[gnum][j][i]
posx = posSxy[gnum][0] // 初始化当前光标位置
posy = posSxy[gnum][1]
offx = offy = 0
steps = 0 // 已走步数为0
gameOver = false
selected = false // 没有选中某一块
ExScreenImg.clear((byte)0) // 清空缓存
Exg.drawRect(4, 0, 2+BLOCKSIZE*4, 2+BLOCKSIZE*5)// 画边框
Exg.drawRect(4+BLOCKSIZE, 2+BLOCKSIZE*5, 2+BLOCKSIZE*2, 2)
// 画布局名称
String gname,gname2
switch(gamelist.getSelectedIndex())
{
case 0:
gname = "横刀"gname2 = "立马"break
case 1:
gname = "过"gname2 = "五关"break
case 2:
gname = "水泄"gname2 = "不通"break
case 3:
gname = "小燕"gname2 = "出巢"break
case 4:
gname = "进在"gname2 = "咫尺"break
case 5:
gname = "左右"gname2 = "夹击"break
default:
gname = "重兵"gname2 = "挡道"break
}
Exg.drawString(gname, 70, 0, Graphics.TOP|Graphics.LEFT)
Exg.drawString(gname2, 70, 13, Graphics.TOP|Graphics.LEFT)
// 画步数
Exg.drawString("步数", 70, 34, Graphics.TOP|Graphics.LEFT)
Exg.setColor(0xffffff)
Exg.fillRect(68, 55, 33, 13)
Exg.setColor(0)
Exg.drawString(Integer.toString(steps), 100, 47, Graphics.TOP|Graphics.RIGHT)
// 画棋子
byte layout[] = {0,0,0,0,0, 0,0,0,0,0} // 分别表示 10个棋子是否已经处理过,依次为:
// 1~4-兵, 5-张飞, 6-赵云, 7-马超, 8-黄忠, 9-关羽, 10-曹 ***
for(i=0i<4i++)
for(j=0j<5j++)
{
if (grid[i][j] != 0)
if (layout[grid[i][j]-1] == 0) // 如果这个棋子没有画过
{
moveSelbox(i, j, false)// 画一个棋子
layout[grid[i][j]-1] = 1// 已经画过了,标志置1
}
}
drawSelbox() // 画选择框
SoundPlay(0) // 播放游戏开始音效
}
protected void paint(Graphics parag)
{
redraw()
}
// 画选择框
private void drawSelbox()
{
if (selected) // 选中状态
{
drawBox(posx, posy, offx, offy, 0xffffff, false, 1, 0)
for (int i=0i<4i++)
for (int j=0j<5j++)
{
if (grid[i][j] == 0) drawBox(i, j, 0, 0, 0xffffff, true, 1, 0)
}
drawBox(posx, posy, offx, offy, 0, true, 0, 2)
}
else// 候选状态
{
if (grid[posx][posy] != 0) // 当前块不是空的
{
drawBox(posx, posy, offx, offy, 0xffffff, true, 0, 1)
drawBox(posx, posy, offx, offy, 0, false, 0, 0)
}
drawBox(posx, posy, offx, offy, 0, false, 2, 0) //画外框
}
}
// 移动选择框
// i,j当前块的(x,y)坐标, moving:true-移动到该棋子,false-重画该棋子
private void moveSelbox(int i, int j, boolean moving)
{
int ox = 0
int oy = 0
if (grid[i][j] != 0) // 该块不是空的
{
if (i >0) // 左侧
if (grid[i][j] == grid[i-1][j]) ox = -1// 左侧属于同一个棋子
if (i <3) // 右侧
if (grid[i][j] == grid[i+1][j]) ox = 1// 右侧属于同一个棋子
if (j >0) // 上面
if (grid[i][j] == grid[i][j-1]) oy = -1// 上面属于同一个棋子
if (j <4) // 下面
if (grid[i][j] == grid[i][j+1]) oy = 1// 下面属于同一个棋子
}
if (moving)
{
offx = ox
offy = oy
drawSelbox()// 移动选择框
}
else
drawBox(i, j, ox, oy, 0, false, 0, 1)// 画棋子
}
// 向缓存画棋子或外框:(px,py)焦点格坐标,(ox,oy)整块相对焦点的偏移量,
//color颜色, fill是否填充黑色,bigbox是否大块(分3级),img是否画人名:0-不画、1-正常、2-反色
private void drawBox(int px, int py, int ox, int oy, int color, boolean fill, int bigbox, int img)
{
int gx[] = new int[2]
int gy[] = new int[2]
boolean dir = (ox==0)
if (bigbox != 0)
{
gx[0] = gx[1] = 5
gy[0] = gy[1] = 1
}
else
{
gx[0] = 6
gx[1] = 4
gy[0] = 2
gy[1] = 0
}
if (ox <0)
{
gx[0] += (px+ox)*BLOCKSIZE
gx[1] += (px+1)*BLOCKSIZE
}
else
{
gx[0] += px*BLOCKSIZE
gx[1] += (px+ox+1)*BLOCKSIZE
}
if (oy <0)
{
gy[0] += (py+oy)*BLOCKSIZE
gy[1] += (py+1)*BLOCKSIZE
}
else
{
gy[0] += py*BLOCKSIZE
gy[1] += (py+oy+1)*BLOCKSIZE
}
Exg.setColor(color)
if (fill)
Exg.fillRect(gx[0], gy[0], gx[1]-gx[0]+1, gy[1]-gy[0]+1)
else
Exg.drawRect(gx[0], gy[0], gx[1]-gx[0], gy[1]-gy[0])
if (bigbox == 2)
{
Exg.drawLine(gx[0]+1, gy[0]-1, gx[1]-1, gy[0]-1)
Exg.drawLine(gx[0]+1, gy[1]+1, gx[1]-1, gy[1]+1)
Exg.drawLine(gx[0]-1, gy[0]+1, gx[0]-1, gy[1]-1)
Exg.drawLine(gx[1]+1, gy[0]+1, gx[1]+1, gy[1]-1)
}
else if (bigbox == 3)
{
if (ox != 0)
{
if (py >0 &&grid[px][py-1]!=grid[px+ox][py-1])
Exg.drawLine((gx[0]+gx[1])/2, gy[0]-1, (gx[0]+gx[1])/2, gy[0]-1)
if (py <4 &&grid[px][py+1]!=grid[px+ox][py+1])
Exg.drawLine((gx[0]+gx[1])/2, gy[1]+1, (gx[0]+gx[1])/2, gy[1]+1)
}
if (oy != 0)
{
if (px >0 &&grid[px-1][py]!=grid[px-1][py+oy])
Exg.drawLine(gx[0]-1, (gy[0]+gy[1])/2, gx[0]-1, (gy[0]+gy[1])/2)
if (px <3 &&grid[px+1][py]!=grid[px+1][py+oy])
Exg.drawLine(gx[1]+1, (gy[0]+gy[1])/2, gx[1]+1, (gy[0]+gy[1])/2)
}
}
Exg.setColor(0)
if (img>0)
{
if (grid[px][py] == 10)
{
Exg.drawImage(nameImg[20+img-1], gx[0]+BLOCKSIZE/2+IMGOFFSET, gy[0]+1+IMGOFFSET, 20)
Exg.drawImage(nameImg[22+img-1], gx[0]+BLOCKSIZE/2+IMGOFFSET, gy[0]+BLOCKSIZE, 20)
}
else if (grid[px][py] <5)
Exg.drawImage(nameImg[24+img-1], gx[0]+IMGOFFSET, gy[0]+IMGOFFSET, 20)
else if(dir)
{
Exg.drawImage(nameImg[(grid[px][py]-5)*4+img-1], gx[0]+IMGOFFSET, gy[0]+1+IMGOFFSET, 20)
Exg.drawImage(nameImg[(grid[px][py]-5)*4+img-1+2], gx[0]+IMGOFFSET, gy[0]+BLOCKSIZE, 20)
}
else
{
Exg.drawImage(nameImg[(grid[px][py]-5)*4+img-1], gx[0]+1+IMGOFFSET, gy[0]+IMGOFFSET, 20)
Exg.drawImage(nameImg[(grid[px][py]-5)*4+img-1+2], gx[0]+BLOCKSIZE, gy[0]+IMGOFFSET, 20)
}
}
}
protected void keyPressed(int kcode) // 按键响应
{
if (gameOver) return // 游戏结束了,不响应
if (selected) // 处于选中状态
{
if (kcode == ctrlkey[4]) // 选择
{
selected = false // 不选中
drawSelbox()
}
else
{
int tmpx, tmpy
tmpx = posx
tmpy = posy
if (kcode == ctrlkey[0])// 左移
{
if (offx <0) tmpx += offx
tmpx --
if (tmpx <0) tmpx = posx // 靠边,移不动
else if (grid[tmpx][posy] == 0 &&grid[tmpx][posy+offy] == 0)
tmpx = posx-1
else tmpx = posx
}
else if (kcode == ctrlkey[1]) // 右移
{
if (offx >0) tmpx += offx
tmpx ++
if (tmpx >3) tmpx = posx // 靠边,移不动
else if (grid[tmpx][posy] == 0 &&grid[tmpx][posy+offy] == 0)
tmpx = posx+1
else tmpx = posx
}
else if (kcode == ctrlkey[2]) // move up
{
if (offy <0) tmpy += offy
tmpy --
if (tmpy <0) tmpy = posy // 靠顶,移不动
else if (grid[posx][tmpy] == 0 &&grid[posx+offx][tmpy] == 0)
tmpy = posy-1
else tmpy = posy
}
else if (kcode == ctrlkey[3]) // move down
{
if (offy >0) tmpy += offy
tmpy ++
if (tmpy >4) tmpy = posy // 靠底,移不动
else if (grid[posx][tmpy] == 0 &&grid[posx+offx][tmpy] == 0)
tmpy = posy+1
else tmpy = posy
}
// 重画焦点块
if ( tmpx != posx || tmpy != posy)
{
byte oldbnum = grid[posx][posy]
grid[posx][posy] = grid[posx+offx][posy] = 0
grid[posx][posy+offy] = grid[posx+offx][posy+offy] = 0
drawBox(posx, posy, offx, offy, 0xffffff, true, 1, 0)
posx = tmpx
posy = tmpy
grid[posx][posy] = grid[posx+offx][posy] = oldbnum
grid[posx][posy+offy] = grid[posx+offx][posy+offy] = oldbnum
drawSelbox()
}
// 计算、画 步数
if (posx == oldx &&posy == oldy) // 如果等于上一步的位置,表示回退了一步
steps = tmpstep// 步数返回上一次的步数
else if (steps == tmpstep)
steps ++ // 步数增加
Exg.setColor(0xffffff)
Exg.fillRect(68, 55, 33, 13)
Exg.setColor(0)
Exg.drawString(Integer.toString(steps), 100, 45, Graphics.TOP| Graphics.RIGHT)
// 判断曹 *** (10)的位置
if (grid[1][4] == 10 &&grid[2][4] == 10) // 胜利
{
gameOver = true
SoundPlay(1)
if (Vib) Vibrator.triggerVibrator(100) // 震动100ms(Siemens扩展)
Exg.setColor(0xffffff)
Exg.fillRect(11, 28, 47, 18)
Exg.setColor(0)
Exg.drawRect(11, 28, 47, 18)
Exg.drawString("胜利了!", 14, 32, 20)
}
}
}
else
{
if (kcode == ctrlkey[4]) // select
{
if (grid[posx][posy] != 0)
{
selected = true// 选中
tmpstep = steps
oldx = posx
oldy = posy
drawSelbox()
}
}
else
{
int tmpx, tmpy
tmpx = posx
tmpy = posy
if (kcode == ctrlkey[0])// move left
{
tmpx --
if (tmpx <0) tmpx = 0
else if (grid[tmpx][posy]==grid[posx][posy] &&grid[posx][posy]!=0)
{
tmpx --
if (tmpx <0) tmpx = posx
}
}
else if (kcode == ctrlkey[1]) // move right
{
tmpx ++
if (tmpx >3) tmpx = 3
else if (grid[tmpx][posy]==grid[posx][posy] &&grid[posx][posy]!=0)
{
tmpx ++
if (tmpx >3) tmpx = posx
}
}
else if (kcode == ctrlkey[2]) // move up
{
tmpy --
if (tmpy <0) tmpy = 0
else if (grid[posx][tmpy]==grid[posx][posy] &&grid[posx][posy]!=0)
{
tmpy --
if (tmpy <0) tmpy = posy
}
}
else if (kcode == ctrlkey[3]) // move down
{
tmpy ++
if (tmpy >4) tmpy = 4
else if (grid[posx][tmpy]==grid[posx][posy] &&grid[posx][posy]!=0)
{
tmpy ++
if (tmpy >4) tmpy = posy
}
}
if ( tmpx != posx || tmpy != posy)
{
drawBox(posx, posy, offx, offy, 0xffffff, false, 3, 0)
for (int i=0i<4i++)
for (int j=0j<5j++)
{
if (grid[i][j] == 0) drawBox(i, j, 0, 0, 0xffffff, true, 1, 0)
}
posx = tmpx
posy = tmpy
moveSelbox(posx, posy, true)
}
}
}
redraw()
}
public void commandAction(Command command, Displayable displayable) // 菜单响应
{
boolean savepara = false
if(command == COMMANDS[1]) // new game
{
gamelist.activate(display, winQuit)
}
else if(command == COMMANDS[2]) // exit
winQuit.quit()
else if(command == COMMANDS[3]) // 按键设置
{
SetKeys fskey = new SetKeys(ctrlkey)
fskey.activate(display, this)
}
else if(command == COMMANDS[4]) // about
{
HRAbout hrabout = new HRAbout()
hrabout.activate(display, this)
}
else if (command == SndCmd)
{
Snd = !Snd
removeCommand(SndCmd)
if (Snd) SndCmd = new Command(closeSnd, Command.OK, 5)
else SndCmd = new Command(openSnd, Command.OK, 5)
addCommand(SndCmd)
savepara = true
}
else if (command == VibCmd)
{
Vib = !Vib
removeCommand(VibCmd)
if (Vib) VibCmd = new Command(closeVib,Command.OK, 6)
else VibCmd = new Command(openVib,Command.OK, 6)
addCommand(VibCmd)
savepara = true
}
if (savepara)
{
/////////////////////////////////////////////
// 写入参数
try
{
byte bflag[] = new byte[2]
File keyfile = new File()
int fid = keyfile.open("CtrlKey")
keyfile.write(fid, ctrlkey, 0, 5) // 写入按键数据(Siemens扩展)
bflag[0] = (byte)(Snd ? 1 : 0)
bflag[1] = (byte)(Vib ? 1 : 0)
keyfile.write(fid, bflag, 0, 2)
keyfile.close(fid)
}
catch(IOException ioexception) { }
catch(NullPointerException npe){}
//////////////////////////////////////////////*/
}
}
private void redraw()
{
ExScreenImg.blitToScreen(0, 0) // 缓存内数据直接输出到屏幕上
}
//音乐
private void SoundPlay(int n)// 播放音效
{
if (!Snd) return // 音效关闭,则返回
// Siemens扩展
melody.resetMelody()
try
{
if (n == 0) // new game
{
melody.setBPM(100)
melody.appendNote(MelodyComposer.TONE_G3, MelodyComposer.TONELENGTH_1_16)
melody.appendNote(MelodyComposer.TONE_G3, MelodyComposer.TONELENGTH_1_16)
melody.appendNote(MelodyComposer.TONE_H3, MelodyComposer.TONELENGTH_1_16)
melody.appendNote(MelodyComposer.TONE_G3, MelodyComposer.TONELENGTH_1_8)
}
else if (n == 1)// win
{
melody.setBPM(110)
melody.appendNote(MelodyComposer.TONE_C2, MelodyComposer.TONELENGTH_1_16)
melody.appendNote(MelodyComposer.TONE_E2, MelodyComposer.TONELENGTH_1_16)
melody.appendNote(MelodyComposer.TONE_G2, MelodyComposer.TONELENGTH_1_16)
melody.appendNote(MelodyComposer.TONE_E2, MelodyComposer.TONELENGTH_1_16)
melody.appendNote(MelodyComposer.TONE_G2, MelodyComposer.TONELENGTH_1_16)
以上为核心代码 由于代码太多无法一次传上来
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)