使用Java实现坦克大战

本文分享了一款使用Java编写的坦克大战游戏的代码,包括游戏规则、声音播放、记录保存等功能。游戏具备坦克移动、发射子弹、敌人自主移动、防止重叠、分关、暂停与继续、成绩记录及背景音乐等特性。
摘要由CSDN通过智能技术生成

`
本来打算在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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值