//hi./srxboys/item/8ce4743da1adc991c2cf29c4
Tank——坦克大战(简洁版)源代码-------(此文档是自己在韩顺平教程总结而来)
*功能:1.防止敌人的坦克重叠运动
*(决定把判断是否碰撞的函数写到EnemyTank类)
*2.可以分关
*2.1(做一个开始的Panel,它是一个空的)
*2.2开始字体闪烁
*3.可以在玩游戏的时候,暂停和继续
*3.1当用户点击暂停时,子弹的速度和坦克速度设为0,并让坦克的方向
*不要发生变化。
*4.可以记录玩家的成绩
*4.1用文件流的方式(小游戏)[大游戏是用的数据库<cs,bs>结构,三国]
*4.2单写一个记录类,完成对玩家的记录
*4.3先完成保存共击毁了多少辆敌人坦克的功能
*4.4存盘退出游戏,可以记录当时的敌人的坦克坐标,并可以恢复
*5.java如何操作声音文件
*/
② JAVA课程设计,求个能用eclipse实现小游戏或小程序的源代码。感激不尽
你自己来去下自载吧,这里面都有 //oschina/project/java
③ 用JAVA编写一个小游戏
前天写的猜数字游戏,yongi控制猜测次数,有详细解析,用黑窗口可以直接运行,
我试验过了,没问题
import javax.swing.Icon
import javax.swing.JOptionPane
public class CaiShuZi4JOptionPane {
/**
* @param args
*/
public static void main(String[] args) {
Icon icon = null
boolean bl = false
int put = 0
int c = (int) (((Math.random())*100)+1)//获取一个1-100的随机数
System.out.println("你获取的随机数是:"+c)//打印你的随机数字
String str1 = (String) JOptionPane.showInputDialog(null,"请输入你的猜测数字(1-100): ","猜数字游戏",JOptionPane.PLAIN_MESSAGE,icon,null,"在这输入")//第一次输入你的猜测数字
if(str1==null){
JOptionPane.showMessageDialog(null, "你已经取消了本次游戏")//如果你点取消那么本次游戏结束
}else{
bl = num(str1)//判断是输入的是不是数字或者是整数
if(true==bl){ //如果是数字的话进入与随机数比较的程序
System.out.println("你输入的数字是:"+str1)//打印你输入的数字
put = Integer.valueOf(str1)
for(int i = 4i >0i--){ //i是你可以猜测的次数
if(put==c){
JOptionPane.showMessageDialog(null, "恭喜你猜对了,正确答案是:"+c+"。")//如果你猜对了就直接结束循环
break
}else if(put>c){ //如果输大了就让你再次从新输入
str1 = (String) JOptionPane.showInputDialog(null,"你的输入过大。你还有"+i+"次机会,请重新输入: ","猜数字游戏",JOptionPane.PLAIN_MESSAGE,icon,null,"在这输入")
if(str1==null){
JOptionPane.showMessageDialog(null, "你已经取消了本次输入")
break
}else{
bl =num(str1)
if(true==bl){
put = Integer.valueOf(str1)
}else{
JOptionPane.showMessageDialog(null, "你的输入不正确,请重新输入")
}
}
}else if(put<c){ //如果你输小了也让你从新输入
str1 = (String) JOptionPane.showInputDialog(null,"你的输入过小。你还有"+i+"次机会,请重新输入: ","猜数字游戏",JOptionPane.PLAIN_MESSAGE,icon,null,"在这输入")
if(str1==null){
JOptionPane.showMessageDialog(null, "你已经取消了本次输入")
break
}else{
bl =num(str1)
if(true==bl){
put = Integer.valueOf(str1)
}else{
JOptionPane.showMessageDialog(null, "你的输入不正确,请重新输入")
}
}
}
}
}else if(bl==false){ //这个 是你第一次如果填写的不是数字的话也会结束本次游戏
JOptionPane.showMessageDialog(null, "请您下次按要求填写。本次游戏结束")
}
if(true==bl &&c!=put){ //如果你i次都没猜对,那么就直接告诉你这个数十什么
JOptionPane.showMessageDialog(null, "很遗憾你没能猜对,这个数字是:"+c+".")
}
}
}
public static boolean num(String value){ //一个静态方法,判断你输入的是不是数字
try {
Integer.parseInt(value)
return true
} catch (Exception e) {
return false
}
}
}
④ 用java制作一个小游戏 教学
static Scanner in =new Scanner(System.in)
public static int aaa(){
int c = 0
while(true){
try {
if(c>999&&c<10000){
break
}else{
// System.out.println("请输入4位整数")
c= in.nextInt()
if(c>999&&c<10000){
break
}else{
System.out.println("输入有误,请重新输入4位整数")
}
}
} catch (Exception e) {
System.out.println("请输入整数")
c= in.nextInt()
}
}
//in.close()
return c
}
public static void cai(){
//Scanner sa =new Scanner(System.in)
int haoma=(int)(Math.random()*10000)
if(haoma<999)
{
haoma = Integer.parseInt(String.valueOf(haoma)+"0")
}
System.out.println(haoma)
System.out.println("请输入一位4位整数")
int aa = 0
while(true){
aa= aaa()
String pd=String.valueOf(aa)
if(pd.length()!=4){
aa = aaa()
}else{
break
}
}
while(true){
if(aa==haoma){
System.out.println("你猜对了,可以去买彩票了")
}else{
System.out.println("抱歉 , 你猜错了")
}
System.out.println("是否继续1继续 其他结束")
try {
int ss = in.nextInt()
if(ss==1){
cai()
}else{
break
}
} catch (Exception e) {
in.close()
break
}
}
}
public static void main(String[] args) {
System.out.println("欢迎来到猜号小游戏")
cai()
System.out.println("over")
}
⑤ 想做一个java小游戏 谁能给几个创意啊 注意 是创意!!!!! 不是已有的有创意的小游戏
比如有东西扔过来,选择吃掉或者躲开,考反应吧。
⑥ 急求java课程设计,内容可以是小游戏的,如(迷宫,计算器,停车场之恋的),要能运行,谢谢
俄罗斯方块,贪吃蛇。推箱子。
⑦ 求JAVA期末课程设计,要那种开发的小项目软件。可以是像记事本那种,也可以是小游戏那种。
网上搜不到的一般是不可共享的资源,建议去图书馆找本专门针对课程设计的书,里面的资料很丰富,你可以照着做一下,并作功能上适当的增减,这样网上就很难找到了
Newload(){
jf1=new JFrame("猜数游戏")
jf2=new JFrame("猜数游戏")
jf3=new JFrame("猜数游戏")
jf1_title=new JLabel("猜数游戏-欢迎进入")
jf1_title.setFont(new Font("仿宋体",Font.BOLD,40))//设置字体大小,及文字字体
jf1_title.setHorizontalAlignment(JLabel.CENTER)
JLabel jf2title=new JLabel("猜数游戏")
jf2title.setFont(new Font("仿宋体",Font.BOLD,40))//设置字体大小,及文字字体
jf2title.setHorizontalAlignment(JLabel.CENTER)
jf1_username=new JLabel("用户名")
jf1_userpass=new JLabel("密码")
jf2_question=new JLabel("There is question which needs you to guess!")
jf2_question.setFont(new Font("仿宋体",Font.BOLD,20))//设置字体大小,及文字字体
jf2_question.setHorizontalAlignment(JLabel.CENTER)
jf2_rightface=new JLabel(iron1)
jf2_wrongface=new JLabel(iron2)
jf2_rightface.setVisible(false)
jf2_wrongface.setVisible(false)
jf2_reelresult=new JLabel()
jf3_pinyu=new JLabel("your result is")
jf1_usernameT=new JTextField(6)
jf2_anwser=new JTextField(6)
jf2_anwser.addActionListener(this)
jf1_password=new JPasswordField(6)
jf1_password.addActionListener(this)
jf1_ok=new JButton("确定")
jf1_ok.addActionListener(this)
jf1_quit=new JButton("退出")
jf1_quit.addActionListener(this)
jf2_newgame=new JButton("新游戏(k)")
jf2_newgame.setMnemonic(KeyEvent.VK_K)
jf2_newgame.addActionListener(this)
jf2_ok=new JButton("确定")
jf2_ok.addActionListener(this)
jf1.setLayout(new BorderLayout())
jf2.setLayout(new BorderLayout())
JPanel jf1p1=new JPanel(),jf2p1=new JPanel(),jf2p2=new JPanel(),jf2p3=new JPanel()
jf2p1.setLayout(new BorderLayout())
jf1p1.setLayout(new FlowLayout())
jf2p2.setLayout(new FlowLayout())
jf2p3.setLayout(new FlowLayout())
jf1.add(jf1_title,"Center")
jf1p1.add(jf1_username)jf1p1.add(jf1_usernameT)
jf1p1.add(jf1_userpass)jf1p1.add(jf1_password)
jf1p1.add(jf1_ok)jf1p1.add(jf1_quit)
jf1.add(jf1p1,"South")
jf2p2.add(jf2_rightface)
jf2p2.add(jf2_wrongface)
jf2p2.add(jf2_reelresult)
jf2p1.add(jf2p2,"South")
jf2p1.add(jf2_question)
jf2.add(jf2title,"North")
jf2.add(jf2p1,"Center")
jf2p3.add(jf2_ans)jf2p3.add(jf2_anwser)jf2p3.add(jf2_ok)jf2p3.add(jf2_newgame)
jf2.add(jf2p3,"South")
jf3.add(jf3_pinyu)
jf1.setSize(700,400)
jf2.setSize(700,400)
jf3.setSize(700,400)
jf1.setLocation(300,150)
jf2.setLocation(300,150)
jf3.setLocation(300,150)
jf1.setVisible(true)
jf2.setVisible(false)
jf3.setVisible(false)
jf1.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0)
}
})
jf2.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0)
}
})
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==jf1_ok||e.getSource()==jf1_password)
{char[] a=jf1_password.getPassword()String paas=""
for(int i=0i<a.lengthi++)//JPasswordField是一种特殊的类只能得到char数组,将其转成String
paas=paas+a[i]
if(jf1_usernameT.getText().equals("user")&&paas.equals("pass"))
{jf2.setVisible(true)jf1.setVisible(false)
number=returnquestion()
jf2_anwser.requestFocus()
}
else
JOptionPane.showMessageDialog(null,"用户名不正确或密码错误!")
}
if(e.getSource()==jf1_quit)
{
System.exit(0)
}
if(e.getSource()==jf2_ok||e.getSource()==jf2_anwser)
{
if(times<=5){
if(Integer.parseInt(jf2_anwser.getText())==number)
{
jf2_rightface.setVisible(true)
jf2_wrongface.setVisible(false)
jf2_reelresult.setText("you are right! and your have used "+times+" times!"
+((times<=3)?"very good!":"pleas do more work for it"))
}
else
if(Integer.parseInt(jf2_anwser.getText())>number)
{times++
jf2_wrongface.setVisible(true)
jf2_rightface.setVisible(false)
jf2_reelresult.setText("your answer is bigger than the one produced by computer!"
+"and your have used "+times+" times!")
}
else
if(Integer.parseInt(jf2_anwser.getText())<number)
{times++
jf2_wrongface.setVisible(true)
jf2_rightface.setVisible(false)
jf2_reelresult.setText("your answer is smaller than the one produced by computer!"
+"and your have used "+times+" times!")
}
}
else
{JOptionPane.showMessageDialog(null,"你已经超过六次了,请重新开始吧!")}
jf2_anwser.requestFocus()
jf2_anwser.setText("")
}
if(e.getSource()==jf2_newgame)
{
number=returnquestion()
times=0
jf2_rightface.setVisible(false)
jf2_wrongface.setVisible(false)
jf2_anwser.setText("")
jf2_reelresult.setText("")
jf2_anwser.requestFocus()
}
}
public static void main(String args[])
{
new Newload()
}
int returnquestion()
{
double db=Math.random()*100
return (int)db
}
}
呵呵,代码自己测试:import java.awt.*
import java.awt.event.*
import java.applet.Applet
import java.awt.Color
public class enzit extends Applet implements ActionListener,MouseListener,MouseMotionListener,ItemListener
{
int color_Qizi=0//旗子的颜色标识 0:白子 1:黑子
int intGame_Start=0//游戏开始标志 0未开始 1游戏中
int intGame_Body[][]=new int[16][16]//设置棋盘棋子状态 0 无子 1 白子 2 黑子
Button b1=new Button("游戏开始")
Button b2=new Button("重置游戏")
Label lblWin=new Label(" ")
Checkbox ckbHB[]=new Checkbox[2]
CheckboxGroup ckgHB=new CheckboxGroup()
public void init()
{
setLayout(null)
addMouseListener(this)
add(b1)
b1.setBounds(330,50,80,30)
b1.addActionListener(this)
add(b2)
b2.setBounds(330,90,80,30)
b2.addActionListener(this)
ckbHB[0]=new Checkbox("白子先",ckgHB,false)
ckbHB[0].setBounds(320,20,60,30)
ckbHB[1]=new Checkbox("黑子先",ckgHB,false)
ckbHB[1].setBounds(380,20,60,30)
add(ckbHB[0])
add(ckbHB[1])
ckbHB[0].addItemListener(this)
ckbHB[1].addItemListener(this)
add(lblWin)
lblWin.setBounds(330,130,80,30)
Game_start_csh()
}
public void itemStateChanged(ItemEvent e)
{
if (ckbHB[0].getState()) //选择黑子先还是白子先
{
color_Qizi=0
}
else
{
color_Qizi=1
}
}
public void actionPerformed(ActionEvent e)
{
Graphics g=getGraphics()
if (e.getSource()==b1)
{
Game_start()
}
else
{
Game_re()
}
}
public void mousePressed(MouseEvent e){}
public void mouseClicked(MouseEvent e)
{
Graphics g=getGraphics()
int x1,y1
x1=e.getX()
y1=e.getY()
if (e.getX()<20 || e.getX()>300 || e.getY()<20 || e.getY()>300)
{
return
}
if (x1%20>10)
{
x1+=20
}
if(y1%20>10)
{
y1+=20
}
x1=x1/20*20
y1=y1/20*20
set_Qizi(x1,y1)
}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mouseReleased(MouseEvent e){}
public void mouseDragged(MouseEvent e){}
public void mouseMoved(MouseEvent e){}
public void paint(Graphics g)
{
draw_qipan(g)
}
public void set_Qizi(int x,int y) //落子
{
if (intGame_Start==0) //判断游戏未开始
{
return
}
if (intGame_Body[x/20][y/20]!=0)
{
return
}
Graphics g=getGraphics()
if (color_Qizi==1)//判断黑子还是白子
{
g.setColor(Color.black)
color_Qizi=0
}
else
{
g.setColor(Color.white)
color_Qizi=1
}
g.fillOval(x-10,y-10,20,20)
intGame_Body[x/20][y/20]=color_Qizi+1
if (Game_win_1(x/20,y/20)) //判断输赢
{
lblWin.setText(Get_qizi_color(color_Qizi)+"赢了!")
intGame_Start=0
}
if (Game_win_2(x/20,y/20)) //判断输赢
{
lblWin.setText(Get_qizi_color(color_Qizi)+"赢了!")
intGame_Start=0
}
if (Game_win_3(x/20,y/20)) //判断输赢
{
lblWin.setText(Get_qizi_color(color_Qizi)+"赢了!")
intGame_Start=0
}
if (Game_win_4(x/20,y/20)) //判断输赢
{
lblWin.setText(Get_qizi_color(color_Qizi)+"赢了!")
intGame_Start=0
}
}
public String Get_qizi_color(int x)
{
if (x==0)
{
return "黑子"
}
else
{
return "白子"
}
}
public void draw_qipan(Graphics G) //画棋盘 15*15
{
G.setColor(Color.lightGray)
G.fill3DRect(10,10,300,300,true)
G.setColor(Color.black)
for(int i=1i<16i++)
{
G.drawLine(20,20*i,300,20*i)
G.drawLine(20*i,20,20*i,300)
}
}
public void Game_start() //游戏开始
{
intGame_Start=1
Game_btn_enable(false)
b2.setEnabled(true)
}
public void Game_start_csh() //游戏开始初始化
{
intGame_Start=0
Game_btn_enable(true)
b2.setEnabled(false)
ckbHB[0].setState(true)
for (int i=0i<16 i++ )
{
for (int j=0j<16 j++ )
{
intGame_Body[i][j]=0
}
}
lblWin.setText("")
}
public void Game_re() //游戏重新开始
{
repaint()
Game_start_csh()
}
public void Game_btn_enable(boolean e) //设置组件状态
{
b1.setEnabled(e)
b2.setEnabled(e)
ckbHB[0].setEnabled(e)
ckbHB[1].setEnabled(e)
}
public boolean Game_win_1(int x,int y) //判断输赢 横
{
int x1,y1,t=1
x1=x
y1=y
for (int i=1i<5 i++ )
{
if (x1>15)
{
break
}
if (intGame_Body[x1+i][y1]==intGame_Body[x][y])
{
t+=1
}
else
{
break
}
}
for (int i=1i<5 i++ )
{
if (x1<1)
{
break
}
if(intGame_Body[x1-i][y1]==intGame_Body[x][y])
{
t+=1
}
else
{
break
}
}
if (t>4)
{
return true
}
else
{
return false
}
}
public boolean Game_win_2(int x,int y) //判断输赢 竖
{
int x1,y1,t=1
x1=x
y1=y
for (int i=1i<5 i++ )
{
if (x1>15)
{
break
}
if (intGame_Body[x1][y1+i]==intGame_Body[x][y])
{
t+=1
}
else
{
break
}
}
for (int i=1i<5 i++ )
{
if (x1<1)
{
break
}
if(intGame_Body[x1][y1-i]==intGame_Body[x][y])
{
t+=1
}
else
{
break
}
}
if (t>4)
{
return true
}
else
{
return false
}
}
public boolean Game_win_3(int x,int y) //判断输赢 左斜
{
int x1,y1,t=1
x1=x
y1=y
for (int i=1i<5 i++ )
{
if (x1>15)
{
break
}
if (intGame_Body[x1+i][y1-i]==intGame_Body[x][y])
{
t+=1
}
else
{
break
}
}
for (int i=1i<5 i++ )
{
if (x1<1)
{
break
}
if(intGame_Body[x1-i][y1+i]==intGame_Body[x][y])
{
t+=1
}
else
{
break
}
}
if (t>4)
{
return true
}
else
{
return false
}
}
public boolean Game_win_4(int x,int y) //判断输赢 左斜
{
int x1,y1,t=1
x1=x
y1=y
for (int i=1i<5 i++ )
{
if (x1>15)
{
break
}
if (intGame_Body[x1+i][y1+i]==intGame_Body[x][y])
{
t+=1
}
else
{
break
}
}
for (int i=1i<5 i++ )
{
if (x1<1)
{
break
}
if(intGame_Body[x1-i][y1-i]==intGame_Body[x][y])
{
t+=1
}
else
{
break
}
}
if (t>4)
{
return true
}
else
{
return false
}
}
}