`
本来打算在GitHub上分享代码,但是发现有的时候并不需要那么复杂的操作,所以讲自己的原创代码分享给大家,希望可以对同仁的学习得到帮助!
1. 构建坦克大战游戏规则类
“
package com.yifanjia;
import java.io.*;
import java.util.*;
import javax.sound.*;
import javax.sound.sampled.*;
//回复点
class Node {
int x;
int y;
int direct;
public Node(int x, int y, int z) {
this.x = x;
this.y = y;
this.direct = z;
}
}
//播放声音的类
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