网站首页 > 文章中心 > 其它

java游戏音效源代码

作者:小编 更新时间:2023-08-22 18:21:09 浏览量:219人看过

求java小游戏源代码

表1. CheckerDrag.java

java游戏音效源代码-图1

急需基于eclipse的JAVA小游戏源代码!!!

单人版五子棋,不用导入,直接新建一个mywindow类就行,然后把一下代码粘贴就Ok了.或者,直接用dos就可以了..

---------------------

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

class mypanel extends Panel implements MouseListener

{

int chess[][] = new int[11][11];

boolean Is_Black_True;

mypanel()

Is_Black_True = true;

for(int i = 0;i 11;i++)

java游戏音效源代码-图2

for(int j = 0;j 11;j++)

chess[i][j] = 0;

}

addMouseListener(this);

setBackground(Color.BLUE);

setVisible(true);

public void mousePressed(MouseEvent e)

int x = e.getX();

int y = e.getY();

return;

if(Is_Black_True == true)

Is_Black_True = false;

repaint();

Justisewiner();

if(Is_Black_True == false)

void Drawline(Graphics g)

g.setColor(Color.WHITE);

void Drawchess(Graphics g)

if(chess[i][j] == 1)

g.setColor(Color.BLACK);

void Justisewiner()

int black_count = 0;

int white_count = 0;

int i = 0;

for(i = 0;i 11;i++)//横向判断

black_count++;

JOptionPane.showMessageDialog(this, "黑棋胜利");

Clear_Chess();

else

black_count = 0;

white_count++;

JOptionPane.showMessageDialog(this, "白棋胜利");

white_count = 0;

for(i = 0;i 11;i++)//竖向判断

if(chess[j][i] == 1)

if(chess[i + k][j + k] == 1)

if(chess[i - k][j + k] == 1)

void Clear_Chess()

for(int i=0;i11;i++)

for(int j=0;j11;j++)

chess[i][j]=0;

public void paint(Graphics g)

Drawline(g);

Drawchess(g);

public void mouseExited(MouseEvent e){}

public void mouseEntered(MouseEvent e){}

public void mouseReleased(MouseEvent e){}

public void mouseClicked(MouseEvent e){}

class myframe extends Frame implements WindowListener

mypanel panel;

myframe()

setLayout(null);

panel = new mypanel();

add(panel);

setTitle("单人版五子棋");

addWindowListener(this);

public void windowClosing(WindowEvent e)

System.exit(0);

public void windowDeactivated(WindowEvent e){}

public void windowActivated(WindowEvent e){}

public void windowOpened(WindowEvent e){}

public void windowClosed(WindowEvent e){}

public void windowIconified(WindowEvent e){}

public void windowDeiconified(WindowEvent e){}

public class mywindow

public static void main(String argc [])

myframe f = new myframe();

用java 如何在游戏中插入音乐

java好像只支持wav格式的音乐文件,你可以用 格式化工厂 转换一下..再用下面代码:

import java.applet.Applet;

import java.applet.AudioClip;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.io.File;

import java.net.URI;

import java.net.URL;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JPanel;

public class f extends JFrame implements ActionListener {

private static final String AudioClip = null;

private JButton Oj;

private JButton Oj1;

AudioClip clip =null;

java游戏音效源代码-图3

File musicFile;

URI uri;

URL url;

private void f() throws InterruptedException{

musicFile = new File("/zxc.wav");

uri = musicFile.toURI();

try {

url = uri.toURL();

} catch (Exception e) {

clip=Applet.newAudioClip(url);

//clip.play();

f() {

this.setResizable(false);

JPanel p = new JPanel();

this.setContentPane(p);

this.setVisible(true);

Oj = new JButton("开始");

Oj1 = new JButton("结束");

Oj.addActionListener(this);

Oj1.addActionListener(this);

this.add(Oj);

this.add(Oj1);

public static void main(String[] args) throws InterruptedException {

f ff=new f();

ff.f();

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

if (e.getSource() == Oj) {

play();

} else if (e.getSource() == Oj1) {

stop();

//System.exit(0);

public void play() {

if (clip != null)

( (java.applet.AudioClip) clip).play();

public void stop() {

( (java.applet.AudioClip) clip).stop();

以上就是土嘎嘎小编为大家整理的java游戏音效源代码相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!

版权声明:倡导尊重与保护知识产权。未经许可,任何人不得复制、转载、或以其他方式使用本站《原创》内容,违者将追究其法律责任。本站文章内容,部分图片来源于网络,如有侵权,请联系我们修改或者删除处理。

编辑推荐

热门文章